Skip to content

Commit 0e4b2a3

Browse files
authored
[Beam SQL] Change SET CATALOG to USE CATALOG (#35314)
* USE catalog instead of SET * add missing
1 parent 730388a commit 0e4b2a3

9 files changed

Lines changed: 28 additions & 25 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"comment": "Modify this file in a trivial way to cause this test suite to run",
3-
"modification": 3
3+
"modification": 2
44
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ data: {
3030
"org.apache.beam.sdk.extensions.sql.impl.parser.SqlCreateFunction"
3131
"org.apache.beam.sdk.extensions.sql.impl.parser.SqlDropCatalog"
3232
"org.apache.beam.sdk.extensions.sql.impl.parser.SqlDdlNodes"
33-
"org.apache.beam.sdk.extensions.sql.impl.parser.SqlSetCatalog"
33+
"org.apache.beam.sdk.extensions.sql.impl.parser.SqlUseCatalog"
3434
"org.apache.beam.sdk.extensions.sql.impl.parser.SqlSetOptionBeam"
3535
"org.apache.beam.sdk.extensions.sql.impl.utils.CalciteUtils"
3636
"org.apache.beam.sdk.schemas.Schema"
@@ -46,6 +46,7 @@ data: {
4646
"TBLPROPERTIES"
4747
"PROPERTIES"
4848
"PARTITIONED"
49+
"USE"
4950
]
5051

5152
# List of keywords from "keywords" section that are not reserved.
@@ -370,6 +371,8 @@ data: {
370371
"LOCATION"
371372
"TBLPROPERTIES"
372373
"PROPERTIES"
374+
"PARTITIONED"
375+
"USE"
373376
]
374377

375378
# List of non-reserved keywords to add;
@@ -391,7 +394,7 @@ data: {
391394
# Return type of method implementation should be 'SqlNode'.
392395
# Example: SqlShowDatabases(), SqlShowTables().
393396
statementParserMethods: [
394-
"SqlSetCatalog(Span.of(), null)"
397+
"SqlUseCatalog(Span.of(), null)"
395398
"SqlSetOptionBeam(Span.of(), null)"
396399
]
397400

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ SqlCreate SqlCreateCatalog(Span s, boolean replace) :
213213
}
214214

215215
/**
216-
* SET CATALOG catalog_name
216+
* USE CATALOG catalog_name
217217
*/
218-
SqlCall SqlSetCatalog(Span s, String scope) :
218+
SqlCall SqlUseCatalog(Span s, String scope) :
219219
{
220220
final SqlNode catalogName;
221221
}
222222
{
223-
<SET> {
223+
<USE> {
224224
s.add(this);
225225
}
226226
<CATALOG>
@@ -230,7 +230,7 @@ SqlCall SqlSetCatalog(Span s, String scope) :
230230
catalogName = SimpleIdentifier()
231231
)
232232
{
233-
return new SqlSetCatalog(
233+
return new SqlUseCatalog(
234234
s.end(this),
235235
scope,
236236
catalogName);

sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlSetCatalog.java renamed to sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlUseCatalog.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
import org.slf4j.Logger;
4040
import org.slf4j.LoggerFactory;
4141

42-
public class SqlSetCatalog extends SqlSetOption implements BeamSqlParser.ExecutableStatement {
43-
private static final Logger LOG = LoggerFactory.getLogger(SqlSetCatalog.class);
42+
public class SqlUseCatalog extends SqlSetOption implements BeamSqlParser.ExecutableStatement {
43+
private static final Logger LOG = LoggerFactory.getLogger(SqlUseCatalog.class);
4444
private final SqlIdentifier catalogName;
4545

46-
private static final SqlOperator OPERATOR = new SqlSpecialOperator("SET CATALOG", SqlKind.OTHER);
46+
private static final SqlOperator OPERATOR = new SqlSpecialOperator("USE CATALOG", SqlKind.OTHER);
4747

48-
public SqlSetCatalog(SqlParserPos pos, String scope, SqlNode catalogName) {
48+
public SqlUseCatalog(SqlParserPos pos, String scope, SqlNode catalogName) {
4949
super(pos, scope, SqlDdlNodes.getIdentifier(catalogName, pos), null);
5050
this.catalogName = SqlDdlNodes.getIdentifier(catalogName, pos);
5151
}
@@ -79,13 +79,13 @@ public void execute(CalcitePrepare.Context context) {
7979
catalogName.getParserPosition(),
8080
RESOURCE.internal(
8181
String.format(
82-
"Unexpected 'SET CATALOG' call for Schema '%s' that is not a Catalog.", name)));
82+
"Unexpected 'USE CATALOG' call for Schema '%s' that is not a Catalog.", name)));
8383
}
8484

8585
if (catalogManager.getCatalog(name) == null) {
8686
throw SqlUtil.newContextException(
8787
catalogName.getParserPosition(),
88-
RESOURCE.internal(String.format("Cannot set catalog: '%s' not found.", name)));
88+
RESOURCE.internal(String.format("Cannot use catalog: '%s' not found.", name)));
8989
}
9090

9191
if (catalogManager.currentCatalog().name().equals(name)) {

sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamSqlCliTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ public void testExecute_setCatalog_doesNotExistError() {
310310
BeamSqlCli cli = new BeamSqlCli().catalogManager(catalogManager);
311311

312312
thrown.expect(CalciteContextException.class);
313-
thrown.expectMessage("Cannot set catalog: 'my_catalog' not found.");
314-
cli.execute("SET CATALOG my_catalog");
313+
thrown.expectMessage("Cannot use catalog: 'my_catalog' not found.");
314+
cli.execute("USE CATALOG my_catalog");
315315
}
316316

317317
@Test
@@ -344,15 +344,15 @@ public void testExecute_setCatalog() {
344344

345345
// catalog manager always starts with a "default" catalog
346346
assertEquals("default", catalogManager.currentCatalog().name());
347-
cli.execute("SET CATALOG catalog_1");
347+
cli.execute("USE CATALOG catalog_1");
348348
assertEquals("catalog_1", catalogManager.currentCatalog().name());
349349
assertEquals(catalog1Props, catalogManager.currentCatalog().properties());
350-
cli.execute("SET CATALOG catalog_2");
350+
cli.execute("USE CATALOG catalog_2");
351351
assertEquals("catalog_2", catalogManager.currentCatalog().name());
352352
assertEquals(catalog2Props, catalogManager.currentCatalog().properties());
353353

354354
// DEFAULT is a reserved keyword, so need to encapsulate in backticks
355-
cli.execute("SET CATALOG 'default'");
355+
cli.execute("USE CATALOG 'default'");
356356
assertEquals("default", catalogManager.currentCatalog().name());
357357
}
358358

@@ -405,15 +405,15 @@ public void testExecute_tableScopeAcrossCatalogs() throws Exception {
405405
BeamSqlCli cli = new BeamSqlCli().catalogManager(catalogManager);
406406

407407
cli.execute("CREATE CATALOG my_catalog TYPE 'local'");
408-
cli.execute("SET CATALOG my_catalog");
408+
cli.execute("USE CATALOG my_catalog");
409409
cli.execute(
410410
"CREATE EXTERNAL TABLE person (\n" + "id int, name varchar, age int) \n" + "TYPE 'text'");
411411

412412
assertEquals("my_catalog", catalogManager.currentCatalog().name());
413413
assertNotNull(catalogManager.currentCatalog().metaStore().getTables().get("person"));
414414

415415
cli.execute("CREATE CATALOG my_other_catalog TYPE 'local'");
416-
cli.execute("SET CATALOG my_other_catalog");
416+
cli.execute("USE CATALOG my_other_catalog");
417417
assertEquals("my_other_catalog", catalogManager.currentCatalog().name());
418418
assertNull(catalogManager.currentCatalog().metaStore().getTables().get("person"));
419419
}

sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/PubsubToBigqueryIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class PubsubToBigqueryIT implements Serializable {
5353
@Test
5454
public void testSimpleInsert() throws Exception {
5555
String createCatalog = "CREATE CATALOG my_catalog TYPE `local`";
56-
String setCatalog = "SET CATALOG my_catalog";
56+
String setCatalog = "USE CATALOG my_catalog";
5757
String pubsubTableString =
5858
"CREATE EXTERNAL TABLE pubsub_topic (\n"
5959
+ "event_timestamp TIMESTAMP, \n"

sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/PubsubToIcebergIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static void createDataset() throws IOException, InterruptedException {
9898
+ format(" 'warehouse' = '%s', \n", warehouse)
9999
+ format(" 'gcp_project' = '%s', \n", OPTIONS.getProject())
100100
+ " 'gcp_region' = 'us-central1')";
101-
setCatalogDdl = "SET CATALOG my_catalog";
101+
setCatalogDdl = "USE CATALOG my_catalog";
102102
}
103103

104104
private String tableIdentifier;

sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/meta/provider/iceberg/IcebergReadWriteIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void runSqlWriteAndRead(boolean withPartitionFields)
151151
sqlEnv.executeDdl(createCatalog);
152152

153153
// 2) use the catalog we just created
154-
String setCatalog = "SET CATALOG my_catalog";
154+
String setCatalog = "USE CATALOG my_catalog";
155155
sqlEnv.executeDdl(setCatalog);
156156

157157
// 3) create beam table
@@ -277,7 +277,7 @@ public void testSQLReadWithProjectAndFilterPushDown() {
277277
sqlEnv.executeDdl(createCatalog);
278278

279279
// 2) use the catalog we just created
280-
String setCatalog = "SET CATALOG my_catalog";
280+
String setCatalog = "USE CATALOG my_catalog";
281281
sqlEnv.executeDdl(setCatalog);
282282

283283
// 3) create Beam table

sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/meta/provider/iceberg/IcebergTableProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void testBuildBeamSqlTableWithPartitionFields() {
8484
.build();
8585

8686
sqlEnv.executeDdl("CREATE CATALOG my_catalog TYPE iceberg");
87-
sqlEnv.executeDdl("SET CATALOG my_catalog");
87+
sqlEnv.executeDdl("USE CATALOG my_catalog");
8888
sqlEnv.executeDdl(
8989
"CREATE EXTERNAL TABLE test_partitioned_table(\n"
9090
+ " id INTEGER,\n"

0 commit comments

Comments
 (0)