From 0b329bb0c96b4c409a0702445a7497e4d8ade5e2 Mon Sep 17 00:00:00 2001 From: Anshul Data Date: Mon, 12 Aug 2024 14:04:15 +0530 Subject: [PATCH] Fix pre-commit errors and rename test case --- expr/interval_compound_literal.go | 6 ++---- expr/interval_compound_literal_test.go | 9 +++++---- expr/interval_year_to_month_test.go | 3 ++- types/interval_compound_type.go | 1 + types/interval_compound_type_test.go | 3 ++- types/interval_year_month_type.go | 1 + types/interval_year_month_type_test.go | 3 ++- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/expr/interval_compound_literal.go b/expr/interval_compound_literal.go index 802a464..dbb8f62 100644 --- a/expr/interval_compound_literal.go +++ b/expr/interval_compound_literal.go @@ -2,6 +2,7 @@ package expr import ( "errors" + "github.com/substrait-io/substrait-go/proto" "github.com/substrait-io/substrait-go/types" ) @@ -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) @@ -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, diff --git a/expr/interval_compound_literal_test.go b/expr/interval_compound_literal_test.go index 89885bb..ff6304f 100644 --- a/expr/interval_compound_literal_test.go +++ b/expr/interval_compound_literal_test.go @@ -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 ( @@ -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 @@ -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", @@ -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) } diff --git a/expr/interval_year_to_month_test.go b/expr/interval_year_to_month_test.go index 48ea7d4..27708c9 100644 --- a/expr/interval_year_to_month_test.go +++ b/expr/interval_year_to_month_test.go @@ -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) { diff --git a/types/interval_compound_type.go b/types/interval_compound_type.go index 1bd0382..5d5d171 100644 --- a/types/interval_compound_type.go +++ b/types/interval_compound_type.go @@ -2,6 +2,7 @@ package types import ( "fmt" + "github.com/substrait-io/substrait-go/proto" ) diff --git a/types/interval_compound_type_test.go b/types/interval_compound_type_test.go index f73c6b2..65c0197 100644 --- a/types/interval_compound_type_test.go +++ b/types/interval_compound_type_test.go @@ -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) { diff --git a/types/interval_year_month_type.go b/types/interval_year_month_type.go index 981b4b6..d0ce546 100644 --- a/types/interval_year_month_type.go +++ b/types/interval_year_month_type.go @@ -2,6 +2,7 @@ package types import ( "fmt" + "github.com/substrait-io/substrait-go/proto" ) diff --git a/types/interval_year_month_type_test.go b/types/interval_year_month_type_test.go index 438cabd..bd49666 100644 --- a/types/interval_year_month_type_test.go +++ b/types/interval_year_month_type_test.go @@ -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) {