-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb119f4
commit ad153da
Showing
8 changed files
with
140 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestNewPrecisionTimestampType(t *testing.T) { | ||
allPossibleTimePrecision := []TimePrecision{Seconds, DeciSeconds, CentiSeconds, MilliSeconds, | ||
EMinus4Seconds, EMinus5Seconds, MicroSeconds, EMinus7Seconds, EMinus8Seconds, NanoSeconds} | ||
allPossibleNullability := []Nullability{NullabilityUnspecified, NullabilityNullable, NullabilityRequired} | ||
|
||
for _, precision := range allPossibleTimePrecision { | ||
for _, nullability := range allPossibleNullability { | ||
expectedPrecisionTimeStampType := PrecisionTimeStampType{precision: precision, nullability: nullability} | ||
expectedPrecisionTimeStampTzType := PrecisionTimeStampTzType{PrecisionTimeStampType: expectedPrecisionTimeStampType} | ||
assert.Equal(t, expectedPrecisionTimeStampType, NewPrecisionTimestampType(precision).WithNullability(nullability)) | ||
assert.Equal(t, expectedPrecisionTimeStampTzType, NewPrecisionTimestampTzType(precision).WithNullability(nullability)) | ||
} | ||
} | ||
} |