-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(type): add support for type PrecisionTimestamp and PrecisionTimestampTz #41
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package expr | ||
|
||
import ( | ||
"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 TestToProtoLiteral(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
constructedLiteral *ProtoLiteral | ||
expectedExpressionLiteral *proto.Expression_Literal | ||
}{ | ||
{"TimeStampType", | ||
&ProtoLiteral{Value: uint64(12345678), Type: types.NewPrecisionTimestampType(types.EMinus4Seconds).WithNullability(types.NullabilityNullable)}, | ||
&proto.Expression_Literal{LiteralType: &proto.Expression_Literal_PrecisionTimestamp_{PrecisionTimestamp: &proto.Expression_Literal_PrecisionTimestamp{Precision: 4, Value: 12345678}}, Nullable: true}, | ||
}, | ||
{"TimeStampTzType", | ||
&ProtoLiteral{Value: uint64(12345678), Type: types.NewPrecisionTimestampTzType(types.NanoSeconds).WithNullability(types.NullabilityNullable)}, | ||
&proto.Expression_Literal{LiteralType: &proto.Expression_Literal_PrecisionTimestampTz{PrecisionTimestampTz: &proto.Expression_Literal_PrecisionTimestamp{Precision: 9, Value: 12345678}}, Nullable: true}, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
toProto := tc.constructedLiteral.ToProtoLiteral() | ||
if diff := cmp.Diff(toProto, tc.expectedExpressionLiteral, protocmp.Transform()); diff != "" { | ||
t.Errorf("proto didn't match, diff:\n%v", diff) | ||
} | ||
}) | ||
|
||
} | ||
} | ||
|
||
func TestLiteralFromProto(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
constructedProto *proto.Expression_Literal | ||
expectedLiteral interface{} | ||
}{ | ||
{"TimeStampType", | ||
&proto.Expression_Literal{LiteralType: &proto.Expression_Literal_PrecisionTimestamp_{PrecisionTimestamp: &proto.Expression_Literal_PrecisionTimestamp{Precision: 4, Value: 12345678}}, Nullable: true}, | ||
&ProtoLiteral{Value: uint64(12345678), Type: types.NewPrecisionTimestampType(types.EMinus4Seconds).WithNullability(types.NullabilityNullable)}, | ||
}, | ||
{"TimeStampTzType", | ||
&proto.Expression_Literal{LiteralType: &proto.Expression_Literal_PrecisionTimestampTz{PrecisionTimestampTz: &proto.Expression_Literal_PrecisionTimestamp{Precision: 9, Value: 12345678}}, Nullable: true}, | ||
&ProtoLiteral{Value: uint64(12345678), Type: types.NewPrecisionTimestampTzType(types.NanoSeconds).WithNullability(types.NullabilityNullable)}, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
literal := LiteralFromProto(tc.constructedProto) | ||
assert.Equal(t, tc.expectedLiteral, literal) | ||
}) | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,23 +6,30 @@ go 1.20 | |
|
||
require ( | ||
github.com/alecthomas/participle/v2 v2.0.0 | ||
github.com/cockroachdb/errors v1.11.3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think it makes sense to source the cockroachdb errors package for a test. Let's revert the go.mod/go.sum changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a utility library which has useful function to construct meaningful error. So good to keep it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is it different than just using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I felt instead of using some methods from fmt and some from standard "errors". It is good to use one library. This cockroach library has much richer APIs (e.g. adding Hint to errors) too. Hence I used it so that we can use a single lib for errors and augment errors to be more informative |
||
github.com/goccy/go-yaml v1.9.8 | ||
github.com/stretchr/testify v1.8.1 | ||
github.com/google/go-cmp v0.5.9 | ||
github.com/stretchr/testify v1.8.2 | ||
golang.org/x/exp v0.0.0-20230206171751-46f607a40771 | ||
google.golang.org/protobuf v1.28.1 | ||
google.golang.org/protobuf v1.33.0 | ||
gopkg.in/yaml.v3 v3.0.1 | ||
) | ||
|
||
require ( | ||
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect | ||
github.com/cockroachdb/redact v1.1.5 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/fatih/color v1.13.0 // indirect | ||
github.com/google/go-cmp v0.5.9 // indirect | ||
github.com/getsentry/sentry-go v0.27.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/kr/pretty v0.3.1 // indirect | ||
github.com/kr/text v0.2.0 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.17 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
golang.org/x/crypto v0.1.0 // indirect | ||
golang.org/x/sys v0.5.0 // indirect | ||
github.com/rogpeppe/go-internal v1.9.0 // indirect | ||
golang.org/x/sys v0.18.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect | ||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did this import move? Can we please put it back in the import list with the rest of the imports that are not stdlib imports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as elsewhere, -1 on review comments around import order. If we want a specific order, add as precommit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it should be fixed by pre-commit. I will add a pre-commit action to detect imports in future PR