forked from substrait-io/substrait-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix code to use Expressions fields in VirtualTable instead of Literal
- Loading branch information
1 parent
bdb436b
commit 60578ef
Showing
9 changed files
with
167 additions
and
34 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
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,52 @@ | ||
package plan | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/stretchr/testify/require" | ||
"github.com/substrait-io/substrait-go/expr" | ||
"github.com/substrait-io/substrait-go/extensions" | ||
"github.com/substrait-io/substrait-go/proto" | ||
"google.golang.org/protobuf/testing/protocmp" | ||
) | ||
|
||
func TestRelFromProto(t *testing.T) { | ||
|
||
registry := expr.NewEmptyExtensionRegistry(&extensions.DefaultCollection) | ||
literal5 := &proto.Expression_Literal{LiteralType: &proto.Expression_Literal_I64{I64: 5}} | ||
exprLiteral5 := &proto.Expression{RexType: &proto.Expression_Literal_{Literal: literal5}} | ||
|
||
nestedStructExpr1 := &proto.Expression_Nested_Struct{Fields: []*proto.Expression{exprLiteral5}} | ||
virtualTableWithExpression := &proto.ReadRel_VirtualTable_{VirtualTable: &proto.ReadRel_VirtualTable{Expressions: []*proto.Expression_Nested_Struct{nestedStructExpr1}}} | ||
readRelWithExpression := &proto.ReadRel{ReadType: virtualTableWithExpression} | ||
|
||
literalStruct := &proto.Expression_Literal_Struct{Fields: []*proto.Expression_Literal{literal5}} | ||
virtualTableWithLiteral := &proto.ReadRel_VirtualTable_{VirtualTable: &proto.ReadRel_VirtualTable{Values: []*proto.Expression_Literal_Struct{literalStruct}}} | ||
readRelWithLiteral := &proto.ReadRel{ReadType: virtualTableWithLiteral} | ||
|
||
for _, td := range []struct { | ||
name string | ||
readType *proto.ReadRel | ||
}{ | ||
{"virtual table with expression", readRelWithExpression}, | ||
{"virtual table with deprecated literal", readRelWithLiteral}, | ||
} { | ||
t.Run(td.name, func(t *testing.T) { | ||
rel := &proto.Rel{RelType: &proto.Rel_Read{Read: td.readType}} | ||
|
||
outRel, err := RelFromProto(rel, registry) | ||
require.NoError(t, err) | ||
gotRel := outRel.ToProto() | ||
gotReadRel, ok := gotRel.RelType.(*proto.Rel_Read) | ||
require.True(t, ok) | ||
gotVirtualTableReadRel, ok := gotReadRel.Read.ReadType.(*proto.ReadRel_VirtualTable_) | ||
require.True(t, ok) | ||
// in case of both deprecated or new expression, the output should be the same as the new expression | ||
if diff := cmp.Diff(gotVirtualTableReadRel, virtualTableWithExpression, protocmp.Transform()); diff != "" { | ||
t.Errorf("expression proto didn't match, diff:\n%v", diff) | ||
} | ||
}) | ||
} | ||
|
||
} |
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