Skip to content

Commit f71cf7e

Browse files
committed
use SqlCall; remove @nullable
1 parent 0e816b0 commit f71cf7e

File tree

9 files changed

+34
-43
lines changed

9 files changed

+34
-43
lines changed

sdks/java/extensions/sql/iceberg/src/main/java/org/apache/beam/sdk/extensions/sql/meta/provider/iceberg/IcebergCatalog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public boolean createDatabase(String database) {
7474
}
7575

7676
@Override
77-
public @Nullable Collection<String> databases() {
77+
public Collection<String> databases() {
7878
return catalogConfig.listNamespaces();
7979
}
8080

sdks/java/extensions/sql/src/main/codegen/config.fmpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,10 @@ data: {
428428
# Return type of method implementation should be 'SqlNode'.
429429
# Example: SqlShowDatabases(), SqlShowTables().
430430
statementParserMethods: [
431-
"SqlShowTables(Span.of(), null)"
432-
"SqlShowDatabases(Span.of(), null)"
433-
"SqlShowCatalogs(Span.of(), null)"
434-
"SqlShowCurrent(Span.of(), null)"
431+
"SqlShowTables(Span.of())"
432+
"SqlShowDatabases(Span.of())"
433+
"SqlShowCatalogs(Span.of())"
434+
"SqlShowCurrent(Span.of())"
435435
"SqlUseCatalog(Span.of(), null)"
436436
"SqlUseDatabase(Span.of(), null)"
437437
"SqlSetOptionBeam(Span.of(), null)"

sdks/java/extensions/sql/src/main/codegen/includes/parserImpls.ftl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,15 @@ SqlDrop SqlDropCatalog(Span s, boolean replace) :
267267
/**
268268
* SHOW CATALOGS [ LIKE regex_pattern ]
269269
*/
270-
SqlCall SqlShowCatalogs(Span s, String scope) :
270+
SqlCall SqlShowCatalogs(Span s) :
271271
{
272272
SqlNode regex = null;
273273
}
274274
{
275275
<SHOW> <CATALOGS> { s.add(this); }
276276
[ <LIKE> regex = StringLiteral() ]
277277
{
278-
return new SqlShowCatalogs(s.end(this), scope, false, regex);
278+
return new SqlShowCatalogs(s.end(this), false, regex);
279279
}
280280
}
281281

@@ -350,7 +350,7 @@ SqlDrop SqlDropDatabase(Span s, boolean replace) :
350350
/**
351351
* SHOW DATABASES [ ( FROM | IN )? catalog_name ] [LIKE regex_pattern ]
352352
*/
353-
SqlCall SqlShowDatabases(Span s, String scope) :
353+
SqlCall SqlShowDatabases(Span s) :
354354
{
355355
SqlIdentifier catalogName = null;
356356
SqlNode regex = null;
@@ -360,22 +360,22 @@ SqlCall SqlShowDatabases(Span s, String scope) :
360360
[ ( <FROM> | <IN> ) catalogName = SimpleIdentifier() ]
361361
[ <LIKE> regex = StringLiteral() ]
362362
{
363-
return new SqlShowDatabases(s.end(this), scope, false, catalogName, regex);
363+
return new SqlShowDatabases(s.end(this), false, catalogName, regex);
364364
}
365365
}
366366

367-
SqlCall SqlShowCurrent(Span s, String scope) :
367+
SqlCall SqlShowCurrent(Span s) :
368368
{
369369
}
370370
{
371371
<SHOW> <CURRENT> { s.add(this); }
372372
(
373373
<CATALOG> {
374-
return new SqlShowCatalogs(s.end(this), scope, true, null);
374+
return new SqlShowCatalogs(s.end(this), true, null);
375375
}
376376
|
377377
<DATABASE> {
378-
return new SqlShowDatabases(s.end(this), scope, true, null, null);
378+
return new SqlShowDatabases(s.end(this), true, null, null);
379379
}
380380
)
381381
}
@@ -508,7 +508,7 @@ SqlDrop SqlDropTable(Span s, boolean replace) :
508508
/**
509509
* SHOW TABLES [ ( FROM | IN )? [ catalog_name '.' ] database_name ] [ LIKE regex_pattern ]
510510
*/
511-
SqlCall SqlShowTables(Span s, String scope) :
511+
SqlCall SqlShowTables(Span s) :
512512
{
513513
SqlIdentifier database = null;
514514
SqlNode regex = null;
@@ -518,7 +518,7 @@ SqlCall SqlShowTables(Span s, String scope) :
518518
[ (<FROM> | <IN>) database = CompoundIdentifier() ]
519519
[ <LIKE> regex = StringLiteral() ]
520520
{
521-
return new SqlShowTables(s.end(this), scope, database, regex);
521+
return new SqlShowTables(s.end(this), database, regex);
522522
}
523523
}
524524

sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/CatalogSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Catalog getCatalog() {
7272
return getSubSchema(catalog.currentDatabase());
7373
}
7474

75-
public @Nullable Collection<String> databases() {
75+
public Collection<String> databases() {
7676
return catalog.databases();
7777
}
7878

sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlShowCatalogs.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,24 @@
2929
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.jdbc.CalcitePrepare;
3030
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.runtime.SqlFunctions;
3131
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.schema.Schema;
32-
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlIdentifier;
32+
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlCall;
3333
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlKind;
3434
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlNode;
3535
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlOperator;
36-
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlSetOption;
3736
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlSpecialOperator;
3837
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlUtil;
3938
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.parser.SqlParserPos;
4039
import org.checkerframework.checker.nullness.qual.Nullable;
4140

42-
public class SqlShowCatalogs extends SqlSetOption implements BeamSqlParser.ExecutableStatement {
41+
public class SqlShowCatalogs extends SqlCall implements BeamSqlParser.ExecutableStatement {
4342
private static final SqlOperator OPERATOR =
44-
new SqlSpecialOperator("SHOW CATALOGS", SqlKind.OTHER);
43+
new SqlSpecialOperator("SHOW CATALOGS", SqlKind.OTHER_DDL);
4544

4645
private final boolean showCurrentOnly;
4746
private final @Nullable SqlNode regex;
4847

49-
public SqlShowCatalogs(
50-
SqlParserPos pos, String scope, boolean showCurrentOnly, @Nullable SqlNode regex) {
51-
super(pos, scope, new SqlIdentifier("", pos), null);
48+
public SqlShowCatalogs(SqlParserPos pos, boolean showCurrentOnly, @Nullable SqlNode regex) {
49+
super(pos);
5250
this.showCurrentOnly = showCurrentOnly;
5351
this.regex = regex;
5452
}

sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlShowDatabases.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,30 @@
2929
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.jdbc.CalcitePrepare;
3030
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.runtime.SqlFunctions;
3131
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.schema.Schema;
32+
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlCall;
3233
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlIdentifier;
3334
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlKind;
3435
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlNode;
3536
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlOperator;
36-
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlSetOption;
3737
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlSpecialOperator;
3838
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlUtil;
3939
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.parser.SqlParserPos;
4040
import org.checkerframework.checker.nullness.qual.Nullable;
4141

42-
public class SqlShowDatabases extends SqlSetOption implements BeamSqlParser.ExecutableStatement {
42+
public class SqlShowDatabases extends SqlCall implements BeamSqlParser.ExecutableStatement {
4343
private static final SqlOperator OPERATOR =
44-
new SqlSpecialOperator("SHOW DATABASES", SqlKind.OTHER);
44+
new SqlSpecialOperator("SHOW DATABASES", SqlKind.OTHER_DDL);
4545

4646
private final boolean showCurrentOnly;
4747
private final @Nullable SqlIdentifier catalogName;
4848
private final @Nullable SqlNode regex;
4949

5050
public SqlShowDatabases(
5151
SqlParserPos pos,
52-
String scope,
5352
boolean showCurrentOnly,
5453
@Nullable SqlIdentifier catalogName,
5554
@Nullable SqlNode regex) {
56-
super(pos, scope, new SqlIdentifier("", pos), null);
55+
super(pos);
5756
this.showCurrentOnly = showCurrentOnly;
5857
this.catalogName = catalogName;
5958
this.regex = regex;
@@ -100,19 +99,16 @@ public void execute(CalcitePrepare.Context context) {
10099
print(databases, catalogSchema.getCatalog().name(), SqlDdlNodes.getString(regex));
101100
}
102101

103-
private static void print(
104-
@Nullable Collection<String> databases, String path, @Nullable String pattern) {
102+
private static void print(Collection<String> databases, String path, @Nullable String pattern) {
105103
SqlFunctions.LikeFunction calciteLike = new SqlFunctions.LikeFunction();
106104

107105
final String headerName = "Databases in " + path;
108106
final String separatorChar = "-";
109107

110108
int nameWidth = headerName.length();
111109

112-
if (databases != null) {
113-
for (String dbName : databases) {
114-
nameWidth = Math.max(nameWidth, dbName.length());
115-
}
110+
for (String dbName : databases) {
111+
nameWidth = Math.max(nameWidth, dbName.length());
116112
}
117113

118114
nameWidth += 2;

sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlShowTables.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,27 @@
3232
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.jdbc.CalcitePrepare;
3333
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.runtime.SqlFunctions;
3434
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.schema.Schema;
35+
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlCall;
3536
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlIdentifier;
3637
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlKind;
3738
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlNode;
3839
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlOperator;
39-
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlSetOption;
4040
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlSpecialOperator;
4141
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlUtil;
4242
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.parser.SqlParserPos;
4343
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Splitter;
4444
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Lists;
4545
import org.checkerframework.checker.nullness.qual.Nullable;
4646

47-
public class SqlShowTables extends SqlSetOption implements BeamSqlParser.ExecutableStatement {
48-
private static final SqlOperator OPERATOR = new SqlSpecialOperator("SHOW TABLES", SqlKind.OTHER);
47+
public class SqlShowTables extends SqlCall implements BeamSqlParser.ExecutableStatement {
48+
private static final SqlOperator OPERATOR =
49+
new SqlSpecialOperator("SHOW TABLES", SqlKind.OTHER_DDL);
4950
private final @Nullable SqlIdentifier databaseName;
5051
private final @Nullable SqlNode regex;
5152

5253
public SqlShowTables(
53-
SqlParserPos pos,
54-
String scope,
55-
@Nullable SqlIdentifier databaseName,
56-
@Nullable SqlNode regex) {
57-
super(pos, scope, new SqlIdentifier("", pos), null);
54+
SqlParserPos pos, @Nullable SqlIdentifier databaseName, @Nullable SqlNode regex) {
55+
super(pos);
5856
this.databaseName = databaseName;
5957
this.regex = regex;
6058
}

sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/catalog/Catalog.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public interface Catalog {
5151
@Nullable
5252
String currentDatabase();
5353

54-
@Nullable
5554
Collection<String> databases();
5655

5756
/**

sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/catalog/InMemoryCatalog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void useDatabase(String database) {
9999
}
100100

101101
@Override
102-
public @Nullable Collection<String> databases() {
102+
public Collection<String> databases() {
103103
return databases;
104104
}
105105

0 commit comments

Comments
 (0)