-
Notifications
You must be signed in to change notification settings - Fork 95
feat(isthmus): add dynamic function conversion for Substrait<->Calcite #457
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
Changes from 1 commit
9d60dc7
556847b
857fe2c
eeb97cd
f30b556
6d9cc2a
1a1bf47
834ab5e
8340cc5
6ba115f
e739184
838a0a7
32ae275
e4f656d
8d2b4ed
9b0c027
a9e7c60
2f6cd28
71fcdfc
ca3d967
142d372
74fd2e7
ec45173
6eedacd
b002d9b
fcf24bb
fc2d576
26c15dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ToSqlOperator
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |||||
| import org.apache.calcite.rel.rules.CoreRules; | ||||||
| import org.apache.calcite.rex.RexBuilder; | ||||||
| import org.apache.calcite.sql.SqlNode; | ||||||
| import org.apache.calcite.sql.SqlOperatorTable; | ||||||
| import org.apache.calcite.sql.parser.SqlParseException; | ||||||
| import org.apache.calcite.sql.validate.SqlValidator; | ||||||
| import org.apache.calcite.sql2rel.SqlToRelConverter; | ||||||
|
|
@@ -41,6 +42,23 @@ public static RelRoot convertQuery(String sqlStatement, Prepare.CatalogReader ca | |||||
| return convertQuery(sqlStatement, catalogReader, validator, createDefaultRelOptCluster()); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Converts a SQL statement to a Calcite {@link RelRoot}. | ||||||
| * | ||||||
| * @param sqlStatement a SQL statement string | ||||||
| * @param catalogReader the {@link Prepare.CatalogReader} for finding tables/views referenced in | ||||||
| * the SQL statement | ||||||
| * @param operatorTable the {@link SqlOperatorTable} for dynamic operators | ||||||
| * @return a {@link RelRoot} corresponding to the given SQL statement | ||||||
| * @throws SqlParseException if there is an error while parsing the SQL statement | ||||||
| */ | ||||||
| public static RelRoot convertQuery( | ||||||
| String sqlStatement, Prepare.CatalogReader catalogReader, SqlOperatorTable operatorTable) | ||||||
| throws SqlParseException { | ||||||
| SqlValidator validator = new SubstraitSqlValidator(catalogReader, operatorTable); | ||||||
| return convertQuery(sqlStatement, catalogReader, validator, createDefaultRelOptCluster()); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Converts a SQL statement to a Calcite {@link RelRoot}. | ||||||
| * | ||||||
|
|
@@ -72,6 +90,24 @@ public static RelRoot convertQuery( | |||||
| return relRoots.get(0); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Converts one or more SQL statements to a List of {@link RelRoot}, with one {@link RelRoot} per | ||||||
| * statement. | ||||||
| * | ||||||
| * @param sqlStatements a string containing one or more SQL statements | ||||||
| * @param catalogReader the {@link Prepare.CatalogReader} for finding tables/views referenced in | ||||||
| * the SQL statements | ||||||
| * @param operatorTable the {@link SqlOperatorTable} for dynamic operators | ||||||
|
||||||
| * @param operatorTable the {@link SqlOperatorTable} for dynamic operators | |
| * @param operatorTable the {@link SqlOperatorTable} for controlling valid operators |
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.
fixed
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,12 +167,10 @@ protected RelRoot assertSqlSubstraitRelRoundTripWorkaroundOptimizer( | |
| SqlToSubstrait s = new SqlToSubstrait(extensions, null); | ||
|
|
||
| // 1. SQL -> Calcite RelRoot | ||
| List<RelRoot> relRoots = s.sqlToRelNode(query, catalogReader); | ||
| assertEquals(1, relRoots.size()); | ||
| RelRoot relRoot1 = relRoots.get(0); | ||
| Plan plan1 = s.convert(query, catalogReader); | ||
|
Member
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. A number of the comments in this test utility don't line up with what it's actually doing. For example, this is a Substrait Plan, not a Calcite RelRoot.
Contributor
Author
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. fixed |
||
|
|
||
| // 2. Calcite RelRoot -> Substrait Rel | ||
| Plan.Root pojo1 = SubstraitRelVisitor.convert(relRoot1, extensions); | ||
| Plan.Root pojo1 = plan1.getRoots().get(0); | ||
|
|
||
| // 3. Substrait Rel -> Calcite RelNode | ||
| RelRoot relRoot2 = substraitToCalcite.convert(pojo1); | ||
|
|
||
This file was deleted.
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.
Strictly speaking, you can inject a SqlOperatorTable here that incorporates dynamic operators, but you can also inject a SqlOperatorTable that doesn't. What this allows you to do is have more fine-grained control over valid operators by allowing you to control what SqlOperatorTable you use, instead of just being forced to use the default SubstraitOperatorTable that we provide.
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.
fixed