Skip to content

Commit

Permalink
Fix pre-commit errors and rename test case
Browse files Browse the repository at this point in the history
  • Loading branch information
anshuldata committed Aug 12, 2024
1 parent bff9e20 commit 0b329bb
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
6 changes: 2 additions & 4 deletions expr/interval_compound_literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package expr

import (
"errors"

"github.com/substrait-io/substrait-go/proto"
"github.com/substrait-io/substrait-go/types"
)
Expand Down Expand Up @@ -49,6 +50,7 @@ func WithIntervalCompoundSubSeconds(subSeconds int64) func(*intervalDateParts) {
// NewIntervalLiteralUptoSubSecondPrecision creates an interval literal which allows upto subsecond precision
// arguments: precision and nullable property (n)
// datePartsOptions is options to set value parts (month, year, day, seconds, subseconds).
// datePartsOptions can be set using WithIntervalCompound(Years|Months|Days|Seconds|SubSeconds) functions
// If multiple options of same types (e.g. multiple second options) are provided only value of last part is considered
func NewIntervalLiteralUptoSubSecondPrecision(precision types.TimePrecision, n types.Nullability, datePartsOptions ...intervalDatePartsOptions) Literal {
intervalCompoundType := types.NewIntervalCompoundType(precision).WithNullability(n)
Expand Down Expand Up @@ -77,10 +79,6 @@ func intervalPartsValToProto(idp *intervalDateParts, ict *types.IntervalCompound
}
intrCompPB.IntervalYearToMonth = yearToMonthProto
}
if idp.days == 0 && idp.seconds == 0 && idp.subSeconds == 0 {
// all parts are >= month granularity so no need to set daytosecond component
return intrCompPB
}

dayToSecondProto := &proto.Expression_Literal_IntervalDayToSecond{
Days: idp.days,
Expand Down
9 changes: 5 additions & 4 deletions expr/interval_compound_literal_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package expr

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/substrait-io/substrait-go/proto"
"github.com/substrait-io/substrait-go/types"
"google.golang.org/protobuf/testing/protocmp"
"testing"
)

const (
Expand All @@ -17,7 +18,7 @@ const (
subSecondsVal int64 = 10000
)

func TestIntervalCompoundProtoExpressionLiteral(t *testing.T) {
func TestIntervalCompoundToProto(t *testing.T) {
// precision and nullability belong to type. In type unit tests they are already tested
// for different values so no need to test for multiple values
precisonVal := types.PrecisionNanoSeconds
Expand All @@ -39,6 +40,7 @@ func TestIntervalCompoundProtoExpressionLiteral(t *testing.T) {
[]intervalDatePartsOptions{yearOption, monthOption},
&proto.Expression_Literal_IntervalCompound_{IntervalCompound: &proto.Expression_Literal_IntervalCompound{
IntervalYearToMonth: &proto.Expression_Literal_IntervalYearToMonth{Years: yearVal, Months: monthVal},
IntervalDayToSecond: &proto.Expression_Literal_IntervalDayToSecond{PrecisionMode: nanoSecPrecision},
}},
},
{"WithOnlyDayToSecond",
Expand Down Expand Up @@ -67,8 +69,7 @@ func TestIntervalCompoundProtoExpressionLiteral(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
expectedProtoExpression := &proto.Expression_Literal{LiteralType: tc.expectedExpressionLiteral, Nullable: nullable}
var intervalCompoundLiteral Literal
intervalCompoundLiteral = NewIntervalLiteralUptoSubSecondPrecision(precisonVal, nullability, tc.options...)
intervalCompoundLiteral := NewIntervalLiteralUptoSubSecondPrecision(precisonVal, nullability, tc.options...)
if diff := cmp.Diff(intervalCompoundLiteral.ToProtoLiteral(), expectedProtoExpression, protocmp.Transform()); diff != "" {
t.Errorf("proto didn't match, diff:\n%v", diff)
}
Expand Down
3 changes: 2 additions & 1 deletion expr/interval_year_to_month_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package expr

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/substrait-io/substrait-go/proto"
"github.com/substrait-io/substrait-go/types"
"google.golang.org/protobuf/testing/protocmp"
"testing"
)

func TestIntervalYearToMonthToProto(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions types/interval_compound_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"fmt"

"github.com/substrait-io/substrait-go/proto"
)

Expand Down
3 changes: 2 additions & 1 deletion types/interval_compound_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package types

import (
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/substrait-io/substrait-go/proto"
"google.golang.org/protobuf/testing/protocmp"
"testing"
)

func TestNewIntervalCompoundType(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions types/interval_year_month_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"fmt"

"github.com/substrait-io/substrait-go/proto"
)

Expand Down
3 changes: 2 additions & 1 deletion types/interval_year_month_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package types

import (
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/substrait-io/substrait-go/proto"
"google.golang.org/protobuf/testing/protocmp"
"testing"
)

func TestNewIntervalYearToMonthType(t *testing.T) {
Expand Down

0 comments on commit 0b329bb

Please sign in to comment.