forked from substrait-io/substrait-java
-
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.
feat: support parsing of SQL queries with APPLY
This change adds support for parsing of SQL queries with APPLY (join with correlated subquery), and to build OuterReferences map of correlated variables present in the query's join predicates. The OuterRefs will be used while constructing Substrait plans to bind correlated variables. The change also adds few example queries which depend on APPLY / LATERAL operators. This change still does not map calcite-correlated-join to Substrait, as the spec for APPLY is still not approved. As such, while the parsing of calcite query plans will succeed after this change, the unit tests and run time conversion will continue to fail in the final step of building the Substrait plan. Additional changes are needed to support APPLY. Refs #substrait-io/substrait/issues/357
- Loading branch information
Showing
5 changed files
with
116 additions
and
3 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
69 changes: 69 additions & 0 deletions
69
isthmus/src/test/java/io/substrait/isthmus/ApplyJoinPlanTest.java
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,69 @@ | ||
package io.substrait.isthmus; | ||
|
||
import org.apache.calcite.adapter.tpcds.TpcdsSchema; | ||
import org.apache.calcite.sql.parser.SqlParseException; | ||
import org.apache.calcite.sql.validate.SqlConformanceEnum; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ApplyJoinPlanTest { | ||
|
||
@Test | ||
public void lateralJoinQuery() { | ||
TpcdsSchema schema = new TpcdsSchema(1.0); | ||
String sql; | ||
sql = | ||
""" | ||
SELECT ss_sold_date_sk, ss_item_sk, ss_customer_sk | ||
FROM store_sales CROSS JOIN LATERAL | ||
(select i_item_sk from item where item.i_item_sk = store_sales.ss_item_sk)"""; | ||
|
||
SqlToSubstrait s = new SqlToSubstrait(); | ||
Assertions.assertThrows( | ||
UnsupportedOperationException.class, | ||
() -> s.execute(sql, "tpcds", schema), | ||
"Lateral join is not supported"); | ||
} | ||
|
||
@Test | ||
public void outerApplyQuery() throws SqlParseException { | ||
TpcdsSchema schema = new TpcdsSchema(1.0); | ||
String sql; | ||
sql = | ||
""" | ||
SELECT ss_sold_date_sk, ss_item_sk, ss_customer_sk | ||
FROM store_sales OUTER APPLY | ||
(select i_item_sk from item where item.i_item_sk = store_sales.ss_item_sk)"""; | ||
|
||
FeatureBoard featureBoard = | ||
ImmutableFeatureBoard.builder() | ||
.sqlConformanceMode(SqlConformanceEnum.SQL_SERVER_2008) | ||
.build(); | ||
SqlToSubstrait s = new SqlToSubstrait(featureBoard); | ||
Assertions.assertThrows( | ||
UnsupportedOperationException.class, | ||
() -> s.execute(sql, "tpcds", schema), | ||
"APPLY is not supported"); | ||
} | ||
|
||
@Test | ||
public void crossApplyQuery() throws SqlParseException { | ||
TpcdsSchema schema = new TpcdsSchema(1.0); | ||
String sql; | ||
sql = | ||
""" | ||
SELECT ss_sold_date_sk, ss_item_sk, ss_customer_sk | ||
FROM store_sales CROSS APPLY | ||
(select i_item_sk from item where item.i_item_sk = store_sales.ss_item_sk)"""; | ||
|
||
FeatureBoard featureBoard = | ||
ImmutableFeatureBoard.builder() | ||
.sqlConformanceMode(SqlConformanceEnum.SQL_SERVER_2008) | ||
.build(); | ||
SqlToSubstrait s = new SqlToSubstrait(featureBoard); | ||
Assertions.assertThrows( | ||
UnsupportedOperationException.class, | ||
() -> s.execute(sql, "tpcds", schema), | ||
"APPLY is not supported"); | ||
} | ||
} |