Skip to content

Commit 2ce3501

Browse files
authored
feat(isthmus): parse SQL using SqlConformanceEnum.LENIENT (#368)
BREAKING CHANGE: removed SqlConformance from FeatureBoard
1 parent 7705243 commit 2ce3501

File tree

6 files changed

+12
-73
lines changed

6 files changed

+12
-73
lines changed

isthmus-cli/README.md

+6-13
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,24 @@ isthmus 0.1
2727
```
2828
$ ./isthmus-cli/build/graal/isthmus --help
2929
30-
Usage: isthmus [-hmV] [--crossjoinpolicy=<crossJoinPolicy>]
31-
[--outputformat=<outputFormat>]
32-
[--sqlconformancemode=<sqlConformanceMode>]
33-
[-c=<createStatements>]... [-e=<sqlExpressions>...]... [<sql>]
30+
Usage: isthmus [-hmV] [--outputformat=<outputFormat>]
31+
[--unquotedcasing=<unquotedCasing>] [-c=<createStatements>]...
32+
[-e=<sqlExpressions>...]... [<sql>]
3433
Convert SQL Queries and SQL Expressions to Substrait
3534
[<sql>] A SQL query
3635
-c, --create=<createStatements>
3736
One or multiple create table statements e.g. CREATE
3837
TABLE T1(foo int, bar bigint)
39-
--crossjoinpolicy=<crossJoinPolicy>
40-
One of built-in Calcite SQL compatibility modes:
41-
KEEP_AS_CROSS_JOIN, CONVERT_TO_INNER_JOIN
4238
-e, --expression=<sqlExpressions>...
4339
One or more SQL expressions e.g. col + 1
4440
-h, --help Show this help message and exit.
4541
-m, --multistatement Allow multiple statements terminated with a semicolon
4642
--outputformat=<outputFormat>
4743
Set the output format for the generated plan:
4844
PROTOJSON, PROTOTEXT, BINARY
49-
--sqlconformancemode=<sqlConformanceMode>
50-
One of built-in Calcite SQL compatibility modes:
51-
DEFAULT, LENIENT, BABEL, STRICT_92, STRICT_99,
52-
PRAGMATIC_99, BIG_QUERY, MYSQL_5, ORACLE_10,
53-
ORACLE_12, STRICT_2003, PRAGMATIC_2003, PRESTO,
54-
SQL_SERVER_2008
45+
--unquotedcasing=<unquotedCasing>
46+
Calcite's casing policy for unquoted identifiers:
47+
UNCHANGED, TO_UPPER, TO_LOWER
5548
-V, --version Print version information and exit.
5649
```
5750

isthmus-cli/src/main/java/io/substrait/isthmus/cli/IsthmusEntryPoint.java

-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.List;
2020
import java.util.concurrent.Callable;
2121
import org.apache.calcite.avatica.util.Casing;
22-
import org.apache.calcite.sql.validate.SqlConformanceEnum;
2322
import picocli.CommandLine;
2423

2524
@Command(
@@ -60,11 +59,6 @@ enum OutputFormat {
6059
BINARY, // protobuf BINARY format
6160
}
6261

63-
@Option(
64-
names = {"--sqlconformancemode"},
65-
description = "One of built-in Calcite SQL compatibility modes: ${COMPLETION-CANDIDATES}")
66-
private SqlConformanceEnum sqlConformanceMode = SqlConformanceEnum.DEFAULT;
67-
6862
@Option(
6963
names = {"--unquotedcasing"},
7064
description = "Calcite's casing policy for unquoted identifiers: ${COMPLETION-CANDIDATES}")
@@ -120,7 +114,6 @@ private void printMessage(Message message) throws IOException {
120114
FeatureBoard buildFeatureBoard() {
121115
return ImmutableFeatureBoard.builder()
122116
.allowsSqlBatch(allowMultiStatement)
123-
.sqlConformanceMode(sqlConformanceMode)
124117
.unquotedCasing(unquotedCasing)
125118
.build();
126119
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package io.substrait.isthmus.cli;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
43
import static org.junit.jupiter.api.Assertions.assertFalse;
5-
import static org.junit.jupiter.api.Assertions.assertThrows;
64
import static org.junit.jupiter.api.Assertions.assertTrue;
75

86
import io.substrait.isthmus.FeatureBoard;
9-
import org.apache.calcite.sql.validate.SqlConformance;
10-
import org.apache.calcite.sql.validate.SqlConformanceEnum;
117
import org.junit.jupiter.api.Test;
128
import picocli.CommandLine;
13-
import picocli.CommandLine.ParameterException;
149

1510
class IsthmusEntryPointTest {
1611

@@ -21,33 +16,14 @@ void defaultFeatureBoard() {
2116
new CommandLine(isthmusEntryPoint);
2217
FeatureBoard features = isthmusEntryPoint.buildFeatureBoard();
2318
assertFalse(features.allowsSqlBatch());
24-
assertEquals(SqlConformanceEnum.DEFAULT, features.sqlConformanceMode());
2519
}
2620

2721
/** Test that the command line options are correctly parsed into the {@link FeatureBoard}. */
2822
@Test
2923
void customFeatureBoard() {
3024
IsthmusEntryPoint isthmusEntryPoint = new IsthmusEntryPoint();
31-
new CommandLine(isthmusEntryPoint)
32-
.parseArgs("--multistatement", "--sqlconformancemode=SQL_SERVER_2008", "SELECT * FROM foo");
25+
new CommandLine(isthmusEntryPoint).parseArgs("--multistatement", "SELECT * FROM foo");
3326
FeatureBoard features = isthmusEntryPoint.buildFeatureBoard();
3427
assertTrue(features.allowsSqlBatch());
35-
assertEquals(
36-
(SqlConformance) SqlConformanceEnum.SQL_SERVER_2008, features.sqlConformanceMode());
37-
}
38-
39-
/**
40-
* Test that the command line parser throws an exception when an invalid join policy is specified.
41-
*/
42-
@Test
43-
void invalidCmdOptions() {
44-
IsthmusEntryPoint isthmusEntryPoint = new IsthmusEntryPoint();
45-
assertThrows(
46-
ParameterException.class,
47-
() ->
48-
new CommandLine(isthmusEntryPoint)
49-
.parseArgs(
50-
"--sqlconformancemode=SQL_SERVER_2008",
51-
"--crossjoinpolicy=REWRITE_TO_INNER_JOIN"));
5228
}
5329
}

isthmus/src/main/java/io/substrait/isthmus/FeatureBoard.java

-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.substrait.isthmus;
22

33
import org.apache.calcite.avatica.util.Casing;
4-
import org.apache.calcite.sql.validate.SqlConformance;
5-
import org.apache.calcite.sql.validate.SqlConformanceEnum;
64
import org.immutables.value.Value;
75

86
/**
@@ -20,18 +18,6 @@ public boolean allowsSqlBatch() {
2018
return false;
2119
}
2220

23-
/**
24-
* Returns Calcite's SQL conformance mode used for the current request. For e.g. APPLY is only
25-
* supported in SQL Server mode. Calcite's parser will throw an exception if the selected mode is
26-
* not SQL Server and the SQL statement contains APPLY.
27-
*
28-
* @return the selected built-in Calcite SQL compatibility mode.
29-
*/
30-
@Value.Default
31-
public SqlConformance sqlConformanceMode() {
32-
return SqlConformanceEnum.DEFAULT;
33-
}
34-
3521
/**
3622
* @return Calcite's identifier casing policy for unquoted identifiers.
3723
*/

isthmus/src/main/java/io/substrait/isthmus/SqlConverterBase.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.calcite.sql.parser.SqlParser;
3232
import org.apache.calcite.sql.parser.SqlParserPos;
3333
import org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl;
34+
import org.apache.calcite.sql.validate.SqlConformanceEnum;
3435
import org.apache.calcite.sql.validate.SqlValidator;
3536
import org.apache.calcite.sql.validate.SqlValidatorCatalogReader;
3637
import org.apache.calcite.sql.validate.SqlValidatorImpl;
@@ -65,7 +66,7 @@ protected SqlConverterBase(FeatureBoard features) {
6566
SqlParser.Config.DEFAULT
6667
.withUnquotedCasing(featureBoard.unquotedCasing())
6768
.withParserFactory(SqlDdlParserImpl.FACTORY)
68-
.withConformance(featureBoard.sqlConformanceMode());
69+
.withConformance(SqlConformanceEnum.LENIENT);
6970
}
7071

7172
protected static final SimpleExtension.ExtensionCollection EXTENSION_COLLECTION =

isthmus/src/test/java/io/substrait/isthmus/ApplyJoinPlanTest.java

+3-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.apache.calcite.rex.RexFieldAccess;
88
import org.apache.calcite.sql.parser.SqlParseException;
99
import org.apache.calcite.sql.parser.SqlParser;
10-
import org.apache.calcite.sql.validate.SqlConformanceEnum;
1110
import org.apache.calcite.sql.validate.SqlValidator;
1211
import org.apache.calcite.sql2rel.SqlToRelConverter;
1312
import org.junit.jupiter.api.Assertions;
@@ -88,10 +87,7 @@ public void outerApplyQuery() throws SqlParseException {
8887
FROM store_sales OUTER APPLY
8988
(select i_item_sk from item where item.i_item_sk = store_sales.ss_item_sk)""";
9089

91-
FeatureBoard featureBoard =
92-
ImmutableFeatureBoard.builder()
93-
.sqlConformanceMode(SqlConformanceEnum.SQL_SERVER_2008)
94-
.build();
90+
FeatureBoard featureBoard = ImmutableFeatureBoard.builder().build();
9591
SqlToSubstrait s = new SqlToSubstrait(featureBoard);
9692
RelRoot root = getCalcitePlan(s, schema, sql);
9793

@@ -133,10 +129,7 @@ public void nestedApplyJoinQuery() throws SqlParseException {
133129
LogicalFilter(condition=[AND(=($4, $cor0.I_ITEM_SK), =($4, $cor2.SS_ITEM_SK))])
134130
LogicalTableScan(table=[[tpcds, PROMOTION]])
135131
*/
136-
FeatureBoard featureBoard =
137-
ImmutableFeatureBoard.builder()
138-
.sqlConformanceMode(SqlConformanceEnum.SQL_SERVER_2008)
139-
.build();
132+
FeatureBoard featureBoard = ImmutableFeatureBoard.builder().build();
140133
SqlToSubstrait s = new SqlToSubstrait(featureBoard);
141134
RelRoot root = getCalcitePlan(s, schema, sql);
142135

@@ -163,10 +156,7 @@ public void crossApplyQuery() throws SqlParseException {
163156
FROM store_sales CROSS APPLY
164157
(select i_item_sk from item where item.i_item_sk = store_sales.ss_item_sk)""";
165158

166-
FeatureBoard featureBoard =
167-
ImmutableFeatureBoard.builder()
168-
.sqlConformanceMode(SqlConformanceEnum.SQL_SERVER_2008)
169-
.build();
159+
FeatureBoard featureBoard = ImmutableFeatureBoard.builder().build();
170160
SqlToSubstrait s = new SqlToSubstrait(featureBoard);
171161

172162
// TODO validate end to end conversion

0 commit comments

Comments
 (0)