-
Notifications
You must be signed in to change notification settings - Fork 93
feat: support Nested Lists #627
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
Open
gord02
wants to merge
15
commits into
substrait-io:main
Choose a base branch
from
gord02:gordon.hamilton/expressionNestedTypes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+473
−28
Open
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
95c27c9
feat: support Nested List Expressions
gord02 4b42b10
feat: adding substrait to calcite conversion
gord02 9e99091
feat: making junit 5 tests package private
gord02 5b277c9
feat: fixing code based on PR review
gord02 3ae2b62
feat: fixing empty list check
gord02 0e4c6fd
feat: formatting
gord02 5ad5fa1
feat: fixing more tests and comments
gord02 925c9ef
fix: updating the return type in new sqlFunction
gord02 b0a787d
fix: resolving issues with nestedlist converter
gord02 041a625
feat: adding new test and addressing comments
gord02 9f2ed4d
fix: perserving nullability and adding tests
gord02 e000913
fix: unifiying the callconverters for listLiterals and NestedLists
gord02 f6a7459
fix: removing unnecessary files
gord02 2c61543
fix: movivng mapLiteral construction to its own file
gord02 b489367
fix: fixing junit test
gord02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
52 changes: 52 additions & 0 deletions
52
core/src/test/java/io/substrait/type/proto/NestedListExpressionTest.java
gord02 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 io.substrait.type.proto; | ||
|
|
||
| import io.substrait.TestBase; | ||
| import io.substrait.expression.Expression; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class NestedListExpressionTest extends TestBase { | ||
| io.substrait.expression.Expression literalExpression = | ||
| Expression.BoolLiteral.builder().value(true).build(); | ||
| Expression.ScalarFunctionInvocation nonLiteralExpression = b.add(b.i32(7), b.i32(42)); | ||
|
|
||
| @Test | ||
| void literalNestedListTest() { | ||
| List<Expression> expressionList = new ArrayList<>(); | ||
| Expression.NestedList literalNestedList = | ||
| Expression.NestedList.builder() | ||
| .addValues(literalExpression) | ||
| .addValues(literalExpression) | ||
| .build(); | ||
| expressionList.add(literalNestedList); | ||
|
|
||
| io.substrait.relation.Project project = | ||
| io.substrait.relation.Project.builder() | ||
| .expressions(expressionList) | ||
| .input(b.emptyScan()) | ||
| .build(); | ||
gord02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| verifyRoundTrip(project); | ||
gord02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Test | ||
| void nonLiteralNestedListTest() { | ||
| List<Expression> expressionList = new ArrayList<>(); | ||
|
|
||
| Expression.NestedList nonLiteralNestedList = | ||
| Expression.NestedList.builder() | ||
| .addValues(nonLiteralExpression) | ||
| .addValues(nonLiteralExpression) | ||
| .build(); | ||
| expressionList.add(nonLiteralNestedList); | ||
|
|
||
| io.substrait.relation.Project project = | ||
| io.substrait.relation.Project.builder() | ||
| .expressions(expressionList) | ||
| .input(b.emptyScan()) | ||
| .build(); | ||
gord02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| verifyRoundTrip(project); | ||
| } | ||
| } | ||
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
isthmus/src/main/java/io/substrait/isthmus/NestedFunctions.java
This file contains hidden or 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,19 @@ | ||
| package io.substrait.isthmus; | ||
|
|
||
| import org.apache.calcite.sql.SqlFunction; | ||
| import org.apache.calcite.sql.SqlFunctionCategory; | ||
| import org.apache.calcite.sql.SqlKind; | ||
| import org.apache.calcite.sql.type.ReturnTypes; | ||
|
|
||
| /** Substrait-specific extension function for the Expression Nested List type */ | ||
| public class NestedFunctions { | ||
|
|
||
| public static final SqlFunction NESTED_LIST = | ||
| new SqlFunction( | ||
| "nested_list", | ||
| SqlKind.OTHER_FUNCTION, | ||
| ReturnTypes.BOOLEAN, | ||
gord02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| null, | ||
| null, | ||
| SqlFunctionCategory.USER_DEFINED_FUNCTION); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
isthmus/src/main/java/io/substrait/isthmus/expression/NestedExpressionConverter.java
This file contains hidden or 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,33 @@ | ||
| package io.substrait.isthmus.expression; | ||
|
|
||
| import io.substrait.expression.Expression; | ||
| import io.substrait.isthmus.CallConverter; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
| import org.apache.calcite.rex.RexCall; | ||
| import org.apache.calcite.rex.RexNode; | ||
|
|
||
| public class NestedExpressionConverter implements CallConverter { | ||
vbarua marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public NestedExpressionConverter() {} | ||
|
|
||
| @Override | ||
| public Optional<Expression> convert( | ||
| RexCall call, Function<RexNode, Expression> topLevelConverter) { | ||
|
|
||
| if (!call.getOperator().getName().equals("nested_list")) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| List<Expression> values = | ||
| call.operands.stream().map(topLevelConverter).collect(Collectors.toList()); | ||
|
|
||
| return Optional.of( | ||
| Expression.NestedList.builder() | ||
| .nullable(call.getType().isNullable()) | ||
| .values(values) | ||
| .build()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.