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.
Merge branch 'main' into anshul/VirtualTableMigrateToNewField
- Loading branch information
Showing
7 changed files
with
446 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package plan_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/substrait-io/substrait-go/literal" | ||
"github.com/substrait-io/substrait-go/plan" | ||
"github.com/substrait-io/substrait-go/types" | ||
) | ||
|
||
// getFilterForTest1 returns filter rel for "name LIKE 'Alice'" | ||
func getFilterForTest1(t *testing.T, b plan.Builder) plan.Rel { | ||
namedTableReadRel := b.NamedScan([]string{"employee_salaries"}, employeeSalariesSchema) | ||
|
||
// column 0 from the output of namedTableReadRel is name | ||
// Build the filter with condition `name LIKE 'Alice'` | ||
l, err := literal.NewString("Alice") | ||
require.NoError(t, err) | ||
nameLikeAlice := makeConditionExprForLike(t, b, namedTableReadRel, 0, l) | ||
return makeFilterRel(t, b, namedTableReadRel, nameLikeAlice) | ||
} | ||
|
||
// TestNamedTableInsertRoundTrip verifies that generated plans match the expected JSON. | ||
func TestNamedTableInsertRoundTrip(t *testing.T) { | ||
for _, td := range []struct { | ||
name string | ||
tableName []string | ||
tableSchema types.NamedStruct | ||
getInputRel func(t *testing.T, b plan.Builder) plan.Rel | ||
}{ | ||
{"insert_from_select", []string{"main", "employee_salaries"}, employeeSalariesSchema, getProjectionForTest1}, | ||
} { | ||
t.Run(td.name, func(t *testing.T) { | ||
// Load the expected JSON. This will be our baseline for comparison. | ||
expectedJson, err := testdata.ReadFile(fmt.Sprintf("testdata/%s.json", td.name)) | ||
require.NoError(t, err) | ||
|
||
// build plan for Insert | ||
b := plan.NewBuilderDefault() | ||
namedInsertRel, err := b.NamedInsert(td.getInputRel(t, b), td.tableName, td.tableSchema) | ||
require.NoError(t, err) | ||
namedInsertPlan, err := b.Plan(namedInsertRel, nil) | ||
require.NoError(t, err) | ||
|
||
// Check that the generated plan matches the expected JSON. | ||
checkRoundTrip(t, string(expectedJson), namedInsertPlan) | ||
}) | ||
} | ||
} | ||
|
||
// TestNamedTableDeleteRoundTrip verifies that generated plans match the expected JSON. | ||
func TestNamedTableDeleteRoundTrip(t *testing.T) { | ||
for _, td := range []struct { | ||
name string | ||
tableName []string | ||
tableSchema types.NamedStruct | ||
getInputRel func(t *testing.T, b plan.Builder) plan.Rel | ||
}{ | ||
{"delete_with_filter", []string{"main", "employee_salaries"}, employeeSalariesSchema, getFilterForTest1}, | ||
} { | ||
t.Run(td.name, func(t *testing.T) { | ||
// Load the expected JSON. This will be our baseline for comparison. | ||
expectedJson, err := testdata.ReadFile(fmt.Sprintf("testdata/%s.json", td.name)) | ||
require.NoError(t, err) | ||
|
||
// build plan for Delete | ||
b := plan.NewBuilderDefault() | ||
namedDeleteRel, err := b.NamedDelete(td.getInputRel(t, b), td.tableName, td.tableSchema) | ||
require.NoError(t, err) | ||
namedDeletePlan, err := b.Plan(namedDeleteRel, nil) | ||
require.NoError(t, err) | ||
|
||
// Check that the generated plan matches the expected JSON. | ||
checkRoundTrip(t, string(expectedJson), namedDeletePlan) | ||
}) | ||
} | ||
} |
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,145 @@ | ||
{ | ||
"extensionUris":[ | ||
{ | ||
"extensionUriAnchor":1, | ||
"uri":"https://github.com/substrait-io/substrait/blob/main/extensions/functions_string.yaml" | ||
} | ||
], | ||
"extensions":[ | ||
{ | ||
"extensionFunction":{ | ||
"extensionUriReference":1, | ||
"functionAnchor":1, | ||
"name":"contains:str_str" | ||
} | ||
} | ||
], | ||
"relations":[ | ||
{ | ||
"root":{ | ||
"input":{ | ||
"write":{ | ||
"common":{ | ||
"direct":{ | ||
|
||
} | ||
}, | ||
"namedTable":{ | ||
"names":[ | ||
"main", | ||
"employee_salaries" | ||
] | ||
}, | ||
"tableSchema":{ | ||
"names":[ | ||
"name", | ||
"salary" | ||
], | ||
"struct":{ | ||
"types":[ | ||
{ | ||
"string":{ | ||
"nullability":"NULLABILITY_NULLABLE" | ||
} | ||
}, | ||
{ | ||
"decimal":{ | ||
"scale":2, | ||
"precision":10, | ||
"nullability":"NULLABILITY_NULLABLE" | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"op":"WRITE_OP_DELETE", | ||
"input":{ | ||
"filter":{ | ||
"common":{ | ||
"direct":{ | ||
|
||
} | ||
}, | ||
"input":{ | ||
"read":{ | ||
"baseSchema":{ | ||
"names":[ | ||
"name", | ||
"salary" | ||
], | ||
"struct":{ | ||
"types":[ | ||
{ | ||
"string":{ | ||
"nullability":"NULLABILITY_NULLABLE" | ||
} | ||
}, | ||
{ | ||
"decimal":{ | ||
"scale":2, | ||
"precision":10, | ||
"nullability":"NULLABILITY_NULLABLE" | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"common":{ | ||
"direct":{ | ||
|
||
} | ||
}, | ||
"namedTable":{ | ||
"names":[ | ||
"employee_salaries" | ||
] | ||
} | ||
} | ||
}, | ||
"condition":{ | ||
"scalarFunction":{ | ||
"functionReference":1, | ||
"outputType":{ | ||
"bool":{ | ||
"nullability":"NULLABILITY_NULLABLE" | ||
} | ||
}, | ||
"arguments":[ | ||
{ | ||
"value":{ | ||
"selection":{ | ||
"directReference":{ | ||
"structField":{ | ||
"field":0 | ||
} | ||
}, | ||
"rootReference":{ | ||
|
||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"value":{ | ||
"literal":{ | ||
"string":"Alice" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"version":{ | ||
"majorNumber":0, | ||
"minorNumber":29, | ||
"patchNumber":0, | ||
"producer":"substrait-go" | ||
} | ||
} |
Oops, something went wrong.