You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "lihaosky (via GitHub)" <gi...@apache.org> on 2026/05/21 16:43:16 UTC
[PR] [FLINK-39726][table] Support USING CONNECTION clause in CREATE TABLE [flink]
lihaosky opened a new pull request, #28222:
URL: https://github.com/apache/flink/pull/28222
## What is the purpose of the change
Adds parser support for an optional `USING CONNECTION <identifier>` clause in `CREATE TABLE` and `CREATE TABLE ... LIKE` statements, per [FLIP-529](https://cwiki.apache.org/confluence/display/FLINK/FLIP-529%3A+Connections+in+Flink+SQL+and+TableAPI). This lets a table reference a previously registered connection (catalog object) for connector configuration:
```sql
CREATE TABLE orders (
order_id INT,
customer_id INT,
amount DECIMAL(10, 2)
) USING CONNECTION mycat.mydb.mysql_prod
WITH (
'connector' = 'jdbc',
'tables' = 'orders'
);
```
The clause is intentionally not allowed with CTAS / RTAS — those raise a parser error.
## Brief change log
- Grammar: added optional `[ <USING> <CONNECTION> CompoundIdentifier() ]` between `PARTITIONED BY` and `WITH` in the `SqlCreateTable` production.
- `SqlCreateTable` / `SqlCreateTableLike`: new optional `connection` field, constructor parameter, `getConnection()` getter, `getOperandList()` entry, and `unparse` output.
- `SqlCreateTableAs` / `SqlReplaceTableAs`: explicitly pass `null` for `connection`; parser rejects `USING CONNECTION` combined with `AS` via a new `ParserResource#usingConnectionWithAsUnsupported` message.
- Tests: positive cases for plain `CREATE TABLE`, `CREATE TABLE` with partition/distribution, and `CREATE TABLE ... LIKE`; negative case for CTAS.
## Verifying this change
This change is covered by unit tests in `FlinkSqlParserImplTest`:
- `testCreateTableUsingConnection`
- `testCreateTableUsingConnectionWithPartitionAndDistribution`
- `testCreateTableLikeUsingConnection`
- `testCreateTableAsWithUsingConnectionFails`
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (no)
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no)
- The serializers: (no)
- The runtime per-record code paths (performance sensitive): (no)
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
- The S3 file system connector: (no)
## Documentation
- Does this pull request introduce a new feature? (yes, parser-level syntax addition; planner / runtime wiring will come in follow-up subtasks of FLIP-529)
- If yes, how is the feature documented? (not documented yet — user-facing docs to follow once the planner/runtime side lands)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39726][table] Support USING CONNECTION clause in CREATE TABLE [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #28222:
URL: https://github.com/apache/flink/pull/28222#discussion_r3287867537
##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/table/SqlCreateTable.java:
##########
@@ -214,6 +225,11 @@ public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
SqlUnparseUtils.unparseComment(comment, true, writer, leftPrec, rightPrec);
SqlUnparseUtils.unparseDistribution(distribution, writer, leftPrec, rightPrec);
SqlUnparseUtils.unparsePartitionKeyList(partitionKeyList, writer, leftPrec, rightPrec);
+ if (connection != null) {
+ writer.newlineAndIndent();
+ writer.keyword("USING CONNECTION");
Review Comment:
Also in general: I wonder if also need to move it to
`SqlUnparseUtils.unparseUsingConnection`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39726][table] Support USING CONNECTION clause in CREATE TABLE [flink]
Posted by "lihaosky (via GitHub)" <gi...@apache.org>.
lihaosky commented on code in PR #28222:
URL: https://github.com/apache/flink/pull/28222#discussion_r3289884576
##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/table/SqlCreateTable.java:
##########
@@ -214,6 +225,11 @@ public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
SqlUnparseUtils.unparseComment(comment, true, writer, leftPrec, rightPrec);
SqlUnparseUtils.unparseDistribution(distribution, writer, leftPrec, rightPrec);
SqlUnparseUtils.unparsePartitionKeyList(partitionKeyList, writer, leftPrec, rightPrec);
+ if (connection != null) {
+ writer.newlineAndIndent();
+ writer.keyword("USING CONNECTION");
Review Comment:
Moved it to utils
##########
flink-table/flink-sql-parser/src/test/java/org/apache/flink/sql/parser/FlinkSqlParserImplTest.java:
##########
@@ -1050,6 +1050,93 @@ void testCreateTable() {
sql(sql).ok(expected);
}
+ @Test
+ void testCreateTableUsingConnection() {
+ final String sql =
+ "CREATE TABLE orders (\n"
+ + " order_id INT,\n"
+ + " customer_id INT,\n"
+ + " amount DECIMAL(10, 2)\n"
+ + ") USING CONNECTION mycat.mydb.mysql_prod\n"
+ + "WITH (\n"
+ + " 'connector' = 'jdbc',\n"
+ + " 'tables' = 'orders'\n"
+ + ")";
+ final String expected =
+ "CREATE TABLE `ORDERS` (\n"
+ + " `ORDER_ID` INTEGER,\n"
+ + " `CUSTOMER_ID` INTEGER,\n"
+ + " `AMOUNT` DECIMAL(10, 2)\n"
+ + ")\n"
+ + "USING CONNECTION `MYCAT`.`MYDB`.`MYSQL_PROD`\n"
+ + "WITH (\n"
+ + " 'connector' = 'jdbc',\n"
+ + " 'tables' = 'orders'\n"
+ + ")";
+ sql(sql).ok(expected);
+ }
+
+ @Test
+ void testCreateTableUsingConnectionWithPartitionAndDistribution() {
+ final String sql =
+ "CREATE TABLE tbl1 (\n"
+ + " a bigint,\n"
+ + " h varchar,\n"
+ + " b varchar\n"
+ + ")\n"
+ + "DISTRIBUTED BY HASH(a) INTO 3 BUCKETS\n"
+ + "PARTITIONED BY (a, h)\n"
+ + "USING CONNECTION cat1.db1.conn1\n"
+ + "WITH (\n"
+ + " 'connector' = 'jdbc'\n"
+ + ")";
+ final String expected =
+ "CREATE TABLE `TBL1` (\n"
+ + " `A` BIGINT,\n"
+ + " `H` VARCHAR,\n"
+ + " `B` VARCHAR\n"
+ + ")\n"
+ + "DISTRIBUTED BY HASH(`A`) INTO 3 BUCKETS\n"
+ + "PARTITIONED BY (`A`, `H`)\n"
+ + "USING CONNECTION `CAT1`.`DB1`.`CONN1`\n"
+ + "WITH (\n"
+ + " 'connector' = 'jdbc'\n"
+ + ")";
+ sql(sql).ok(expected);
+ }
+
+ @Test
+ void testCreateTableAsWithUsingConnectionFails() {
+ final String sql =
Review Comment:
Added tests
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39726][table] Support USING CONNECTION clause in CREATE TABLE [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #28222:
URL: https://github.com/apache/flink/pull/28222#discussion_r3287864441
##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/table/SqlCreateTable.java:
##########
@@ -214,6 +225,11 @@ public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
SqlUnparseUtils.unparseComment(comment, true, writer, leftPrec, rightPrec);
SqlUnparseUtils.unparseDistribution(distribution, writer, leftPrec, rightPrec);
SqlUnparseUtils.unparsePartitionKeyList(partitionKeyList, writer, leftPrec, rightPrec);
+ if (connection != null) {
+ writer.newlineAndIndent();
+ writer.keyword("USING CONNECTION");
Review Comment:
```suggestion
writer.keyword("USING");
writer.keyword("CONNECTION");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39726][table] Support USING CONNECTION clause in CREATE TABLE [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #28222:
URL: https://github.com/apache/flink/pull/28222#discussion_r3287883055
##########
flink-table/flink-sql-parser/src/test/java/org/apache/flink/sql/parser/FlinkSqlParserImplTest.java:
##########
@@ -1050,6 +1050,93 @@ void testCreateTable() {
sql(sql).ok(expected);
}
+ @Test
+ void testCreateTableUsingConnection() {
+ final String sql =
+ "CREATE TABLE orders (\n"
+ + " order_id INT,\n"
+ + " customer_id INT,\n"
+ + " amount DECIMAL(10, 2)\n"
+ + ") USING CONNECTION mycat.mydb.mysql_prod\n"
+ + "WITH (\n"
+ + " 'connector' = 'jdbc',\n"
+ + " 'tables' = 'orders'\n"
+ + ")";
+ final String expected =
+ "CREATE TABLE `ORDERS` (\n"
+ + " `ORDER_ID` INTEGER,\n"
+ + " `CUSTOMER_ID` INTEGER,\n"
+ + " `AMOUNT` DECIMAL(10, 2)\n"
+ + ")\n"
+ + "USING CONNECTION `MYCAT`.`MYDB`.`MYSQL_PROD`\n"
+ + "WITH (\n"
+ + " 'connector' = 'jdbc',\n"
+ + " 'tables' = 'orders'\n"
+ + ")";
+ sql(sql).ok(expected);
+ }
+
+ @Test
+ void testCreateTableUsingConnectionWithPartitionAndDistribution() {
+ final String sql =
+ "CREATE TABLE tbl1 (\n"
+ + " a bigint,\n"
+ + " h varchar,\n"
+ + " b varchar\n"
+ + ")\n"
+ + "DISTRIBUTED BY HASH(a) INTO 3 BUCKETS\n"
+ + "PARTITIONED BY (a, h)\n"
+ + "USING CONNECTION cat1.db1.conn1\n"
+ + "WITH (\n"
+ + " 'connector' = 'jdbc'\n"
+ + ")";
+ final String expected =
+ "CREATE TABLE `TBL1` (\n"
+ + " `A` BIGINT,\n"
+ + " `H` VARCHAR,\n"
+ + " `B` VARCHAR\n"
+ + ")\n"
+ + "DISTRIBUTED BY HASH(`A`) INTO 3 BUCKETS\n"
+ + "PARTITIONED BY (`A`, `H`)\n"
+ + "USING CONNECTION `CAT1`.`DB1`.`CONN1`\n"
+ + "WITH (\n"
+ + " 'connector' = 'jdbc'\n"
+ + ")";
+ sql(sql).ok(expected);
+ }
+
+ @Test
+ void testCreateTableAsWithUsingConnectionFails() {
+ final String sql =
Review Comment:
to be on the safe side can we also add a test for `REPLACE TABLE AS`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39726][table] Support USING CONNECTION clause in CREATE TABLE [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin merged PR #28222:
URL: https://github.com/apache/flink/pull/28222
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39726][table] Support USING CONNECTION clause in CREATE TABLE [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #28222:
URL: https://github.com/apache/flink/pull/28222#issuecomment-4510508271
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "deb8fd43d9f6bca728bc8a7aff62254488ceb462",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "deb8fd43d9f6bca728bc8a7aff62254488ceb462",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* deb8fd43d9f6bca728bc8a7aff62254488ceb462 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org