You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2021/11/22 01:37:21 UTC
[shardingsphere] branch master updated: Add SQLServer CREATE REMOTE TABLE AS SELECT statement (#13709)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new e9a3372 Add SQLServer CREATE REMOTE TABLE AS SELECT statement (#13709)
e9a3372 is described below
commit e9a3372bbae56d06e423bf6aa1da4269069c253a
Author: Thanoshan MV <48...@users.noreply.github.com>
AuthorDate: Mon Nov 22 07:06:23 2021 +0530
Add SQLServer CREATE REMOTE TABLE AS SELECT statement (#13709)
---
.../main/antlr4/imports/sqlserver/DDLStatement.g4 | 12 ++++++--
.../src/main/antlr4/imports/sqlserver/Keyword.g4 | 4 +++
.../antlr4/imports/sqlserver/SQLServerKeyword.g4 | 4 +++
.../impl/SQLServerDDLStatementSQLVisitor.java | 2 ++
.../src/main/resources/case/ddl/create-table.xml | 36 ++++++++++++++++++++++
.../resources/sql/supported/ddl/create-table.xml | 1 +
6 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DDLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DDLStatement.g4
index 11b74ea..d27cc43 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DDLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DDLStatement.g4
@@ -20,7 +20,7 @@ grammar DDLStatement;
import Symbol, Keyword, SQLServerKeyword, Literals, BaseRule, DMLStatement, DCLStatement;
createTable
- : CREATE TABLE tableName fileTableClause createDefinitionClause
+ : CREATE createTableSpecification TABLE tableName fileTableClause createDefinitionClause
;
createIndex
@@ -148,7 +148,7 @@ fileTableClause
;
createDefinitionClause
- : createTableAsSelect? createTableDefinitions partitionScheme fileGroup
+ : createTableAsSelect? createRemoteTableAsSelect? createTableDefinitions partitionScheme fileGroup
;
createTableDefinitions
@@ -1078,3 +1078,11 @@ withDistributionOption
optionQueryHintClause
: (OPTION LP_ queryHint (COMMA_ queryHint)* RP_)?
;
+
+createTableSpecification
+ : REMOTE?
+ ;
+
+createRemoteTableAsSelect
+ : AT LP_ stringLiterals RP_ (WITH LP_ BATCH_SIZE EQ_ INT_NUM_ RP_)? AS select
+ ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4
index 900d9c4..b1c9ce5 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4
@@ -679,3 +679,7 @@ RETURN
READONLY
: R E A D O N L Y
;
+
+AT
+ : A T
+ ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4
index 59ebbb4..ad80eae 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4
@@ -1750,3 +1750,7 @@ EXPLAIN
WITH_RECOMMENDATIONS
: W I T H UL_ R E C O M M E N D A T I O N S
;
+
+BATCH_SIZE
+ : B A T C H UL_ S I Z E
+ ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerDDLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerDDLStatementSQLVisitor.java
index 6e1dd40..f7e80b4 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerDDLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerDDLStatementSQLVisitor.java
@@ -144,6 +144,8 @@ public final class SQLServerDDLStatementSQLVisitor extends SQLServerStatementSQL
}
}
result.setSelectStatement((SQLServerSelectStatement) visit(ctx.createDefinitionClause().createTableAsSelect().select()));
+ } else if (null != ctx.createDefinitionClause().createRemoteTableAsSelect()) {
+ result.setSelectStatement((SQLServerSelectStatement) visit(ctx.createDefinitionClause().createRemoteTableAsSelect().select()));
} else {
CollectionValue<CreateDefinitionSegment> createDefinitions =
(CollectionValue<CreateDefinitionSegment>) generateCreateDefinitionSegment(ctx.createDefinitionClause().createTableDefinitions());
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/create-table.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/create-table.xml
index 0b973cd..cd01813 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/create-table.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/create-table.xml
@@ -1664,4 +1664,40 @@
</projections>
</select>
</create-table>
+
+ <create-table sql-case-id="create_remote_table_as_select">
+ <table name="t_order_new" start-index="20" stop-index="30" />
+ <select>
+ <from>
+ <join-table>
+ <left>
+ <simple-table name="t_order_item" alias="i" start-index="119" stop-index="132" />
+ </left>
+ <right>
+ <simple-table name="t_order" alias="o" start-index="139" stop-index="147" />
+ </right>
+ <on-condition>
+ <binary-operation-expression start-index="152" stop-index="174">
+ <left>
+ <column name="order_id" start-index="152" stop-index="161">
+ <owner name="i" start-index="152" stop-index="152" />
+ </column>
+ </left>
+ <operator>=</operator>
+ <right>
+ <column name="order_id" start-index="165" stop-index="174">
+ <owner name="o" start-index="165" stop-index="165" />
+ </column>
+ </right>
+ </binary-operation-expression>
+ </on-condition>
+ </join-table>
+ </from>
+ <projections start-index="110" stop-index="112">
+ <shorthand-projection start-index="110" stop-index="112">
+ <owner name="i" start-index="110" stop-index="110" />
+ </shorthand-projection>
+ </projections>
+ </select>
+ </create-table>
</sql-parser-test-cases>
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/create-table.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/create-table.xml
index bd91deb..f915b52 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/create-table.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/create-table.xml
@@ -117,4 +117,5 @@
<sql-case id="create_table_as_select" value="CREATE TABLE t_order_new WITH (DISTRIBUTION = HASH(product_key), CLUSTERED COLUMNSTORE INDEX, PARTITION (order_date RANGE RIGHT FOR VALUES (20000101,20010101))) AS SELECT * FROM t_order" db-types="SQLServer" />
<sql-case id="create_table_as_select_with_explicit_column_names" value="CREATE TABLE t_order_new (order_id_new, user_id_new) WITH (DISTRIBUTION = HASH(product_key), CLUSTERED COLUMNSTORE INDEX, PARTITION (order_date RANGE RIGHT FOR VALUES (20000101,20010101))) AS SELECT order_id, user_id FROM t_order" db-types="SQLServer" />
<sql-case id="create_table_as_select_with_query_hint" value="CREATE TABLE dbo.t_order_new WITH (DISTRIBUTION = ROUND_ROBIN, CLUSTERED COLUMNSTORE INDEX) AS SELECT i.* FROM t_order o JOIN t_order_item i ON o.order_id = i.order_id OPTION ( HASH JOIN )" db-types="SQLServer" />
+ <sql-case id="create_remote_table_as_select" value="CREATE REMOTE TABLE t_order_new AT ('Data Source = ds_0, 3306; User ID = ROOT; Password = 123456;') AS SELECT i.* FROM t_order_item i JOIN t_order o ON i.order_id = o.order_id" db-types="SQLServer" />
</sql-cases>