Skip to content

Commit 2d17d58

Browse files
authored
feat(isthmus): always allow batch queries (#372)
BREAKING CHANGE: removed AllowsSqlBatch from FeatureBoard
1 parent 791f7ce commit 2d17d58

File tree

6 files changed

+18
-60
lines changed

6 files changed

+18
-60
lines changed

isthmus-cli/README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,24 @@ isthmus 0.1
2727
```
2828
$ ./isthmus-cli/build/graal/isthmus --help
2929
30-
Usage: isthmus [-hmV] [--outputformat=<outputFormat>]
30+
Usage: isthmus [-hV] [--outputformat=<outputFormat>]
3131
[--unquotedcasing=<unquotedCasing>] [-c=<createStatements>]...
3232
[-e=<sqlExpressions>...]... [<sql>]
3333
Convert SQL Queries and SQL Expressions to Substrait
34-
[<sql>] A SQL query
34+
[<sql>] A SQL query
3535
-c, --create=<createStatements>
36-
One or multiple create table statements e.g. CREATE
37-
TABLE T1(foo int, bar bigint)
36+
One or multiple create table statements e.g. CREATE
37+
TABLE T1(foo int, bar bigint)
3838
-e, --expression=<sqlExpressions>...
39-
One or more SQL expressions e.g. col + 1
40-
-h, --help Show this help message and exit.
41-
-m, --multistatement Allow multiple statements terminated with a semicolon
39+
One or more SQL expressions e.g. col + 1
40+
-h, --help Show this help message and exit.
4241
--outputformat=<outputFormat>
43-
Set the output format for the generated plan:
44-
PROTOJSON, PROTOTEXT, BINARY
42+
Set the output format for the generated plan:
43+
PROTOJSON, PROTOTEXT, BINARY
4544
--unquotedcasing=<unquotedCasing>
46-
Calcite's casing policy for unquoted identifiers:
47-
UNCHANGED, TO_UPPER, TO_LOWER
48-
-V, --version Print version information and exit.
45+
Calcite's casing policy for unquoted identifiers:
46+
UNCHANGED, TO_UPPER, TO_LOWER
47+
-V, --version Print version information and exit.
4948
```
5049

5150
## Example

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public class IsthmusEntryPoint implements Callable<Integer> {
4242
"One or multiple create table statements e.g. CREATE TABLE T1(foo int, bar bigint)")
4343
private List<String> createStatements;
4444

45-
@Option(
46-
names = {"-m", "--multistatement"},
47-
description = "Allow multiple statements terminated with a semicolon")
48-
private boolean allowMultiStatement;
49-
5045
@Option(
5146
names = {"--outputformat"},
5247
defaultValue = "PROTOJSON",
@@ -112,9 +107,6 @@ private void printMessage(Message message) throws IOException {
112107

113108
@VisibleForTesting
114109
FeatureBoard buildFeatureBoard() {
115-
return ImmutableFeatureBoard.builder()
116-
.allowsSqlBatch(allowMultiStatement)
117-
.unquotedCasing(unquotedCasing)
118-
.build();
110+
return ImmutableFeatureBoard.builder().unquotedCasing(unquotedCasing).build();
119111
}
120112
}
Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
package io.substrait.isthmus.cli;
22

3-
import static org.junit.jupiter.api.Assertions.assertFalse;
4-
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
54

6-
import io.substrait.isthmus.FeatureBoard;
75
import org.junit.jupiter.api.Test;
86
import picocli.CommandLine;
97

108
class IsthmusEntryPointTest {
119

12-
/** Test that the default values are set correctly into the {@link FeatureBoard}. */
1310
@Test
14-
void defaultFeatureBoard() {
11+
void canProcessQuery() {
1512
IsthmusEntryPoint isthmusEntryPoint = new IsthmusEntryPoint();
16-
new CommandLine(isthmusEntryPoint);
17-
FeatureBoard features = isthmusEntryPoint.buildFeatureBoard();
18-
assertFalse(features.allowsSqlBatch());
19-
}
20-
21-
/** Test that the command line options are correctly parsed into the {@link FeatureBoard}. */
22-
@Test
23-
void customFeatureBoard() {
24-
IsthmusEntryPoint isthmusEntryPoint = new IsthmusEntryPoint();
25-
new CommandLine(isthmusEntryPoint).parseArgs("--multistatement", "SELECT * FROM foo");
26-
FeatureBoard features = isthmusEntryPoint.buildFeatureBoard();
27-
assertTrue(features.allowsSqlBatch());
13+
CommandLine cli = new CommandLine(isthmusEntryPoint);
14+
int statusCode = cli.execute("SELECT 1;");
15+
assertEquals(0, statusCode);
2816
}
2917
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
@Value.Immutable
1111
public abstract class FeatureBoard {
1212

13-
/**
14-
* @return true if parsing sql batch (multiple input sql statements) is enabled
15-
*/
16-
@Value.Default
17-
public boolean allowsSqlBatch() {
18-
return false;
19-
}
20-
2113
/**
2214
* @return Calcite's identifier casing policy for unquoted identifiers.
2315
*/

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ private List<RelRoot> sqlToRelNode(
8585
throws SqlParseException {
8686
SqlParser parser = SqlParser.create(sql, parserConfig);
8787
var parsedList = parser.parseStmtList();
88-
if (!featureBoard.allowsSqlBatch() && parsedList.size() > 1) {
89-
throw new UnsupportedOperationException("SQL must contain only a single statement: " + sql);
90-
}
9188
SqlToRelConverter converter = createSqlToRelConverter(validator, catalogReader);
9289
List<RelRoot> roots =
9390
parsedList.stream()

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.substrait.isthmus;
22

3-
import static org.junit.jupiter.api.Assertions.assertThrows;
4-
53
import java.io.IOException;
64
import org.apache.calcite.sql.parser.SqlParseException;
75
import org.junit.jupiter.api.Test;
@@ -52,17 +50,9 @@ public void isNull() throws IOException, SqlParseException {
5250

5351
@Test
5452
public void multiStatement() throws IOException, SqlParseException {
55-
assertThrows(
56-
UnsupportedOperationException.class,
57-
() -> {
58-
assertProtoPlanRoundrip(
59-
"select l_orderkey from lineitem; select l_partkey from lineitem WHERE L_ORDERKEY > 20;");
60-
},
61-
"SQL must contain only a single statement");
62-
var features = ImmutableFeatureBoard.builder().allowsSqlBatch(true).build();
6353
assertProtoPlanRoundrip(
6454
"select l_orderkey from lineitem; select l_partkey from lineitem WHERE L_ORDERKEY > 20;",
65-
new SqlToSubstrait(features));
55+
new SqlToSubstrait());
6656
}
6757

6858
@Test

0 commit comments

Comments
 (0)