You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ch...@apache.org on 2025/07/29 06:09:13 UTC
(shardingsphere) branch master updated: fix:Support for the OPENDATASOURCE function in INSERT statements (#36093)
This is an automated email from the ASF dual-hosted git repository.
chengzhang 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 0ddf849c9df fix:Support for the OPENDATASOURCE function in INSERT statements (#36093)
0ddf849c9df is described below
commit 0ddf849c9dfacc9144a172e851a4aeac08a7ae16
Author: cxy <xi...@qq.com>
AuthorDate: Tue Jul 29 14:09:07 2025 +0800
fix:Support for the OPENDATASOURCE function in INSERT statements (#36093)
---
.../src/main/antlr4/imports/sqlserver/BaseRule.g4 | 2 +-
.../statement/SQLServerStatementVisitor.java | 17 ++++++++++++-
.../parser/src/main/resources/case/dml/insert.xml | 28 ++++++++++++++++++++++
.../main/resources/sql/supported/dml/insert.xml | 1 +
4 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4
index b661482ce05..aefc76943c2 100644
--- a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4
+++ b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4
@@ -465,7 +465,7 @@ openQueryFunction
;
rowSetFunction
- : openRowSetFunction | openQueryFunction
+ : openRowSetFunction | openQueryFunction | openDatasourceFunction
;
regularFunction
diff --git a/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java b/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java
index ed5b594f827..f22e72b5bcf 100644
--- a/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java
+++ b/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java
@@ -252,6 +252,7 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.Par
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TryParseFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableHintExtendedContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.LinkedServerNameContext;
+import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OpenDatasourceFunctionContext;
import java.util.Collection;
import java.util.Collections;
@@ -1068,6 +1069,18 @@ public abstract class SQLServerStatementVisitor extends SQLServerStatementBaseVi
return getFunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.OPENQUERY().getText(), getOriginalText(ctx), ctx.expr());
}
+ @Override
+ public ASTNode visitOpenDatasourceFunction(final OpenDatasourceFunctionContext ctx) {
+ FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.OPENDATASOURCE().getText(), getOriginalText(ctx));
+ for (ExprContext each : ctx.expr()) {
+ result.getParameters().add((ExpressionSegment) visit(each));
+ }
+ if (null != ctx.tableName()) {
+ result.getParameters().add(new LiteralExpressionSegment(ctx.tableName().getStart().getStartIndex(), ctx.tableName().getStop().getStopIndex(), ctx.tableName().getText()));
+ }
+ return result;
+ }
+
@Override
public final ASTNode visitRegularFunction(final RegularFunctionContext ctx) {
return getFunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.regularFunctionName().getText(), getOriginalText(ctx), ctx.expr());
@@ -1347,8 +1360,10 @@ public abstract class SQLServerStatementVisitor extends SQLServerStatementBaseVi
public ASTNode visitRowSetFunction(final RowSetFunctionContext ctx) {
if (null != ctx.openRowSetFunction()) {
return visit(ctx.openRowSetFunction());
- } else {
+ } else if (null != ctx.openQueryFunction()) {
return visit(ctx.openQueryFunction());
+ } else {
+ return visit(ctx.openDatasourceFunction());
}
}
diff --git a/test/it/parser/src/main/resources/case/dml/insert.xml b/test/it/parser/src/main/resources/case/dml/insert.xml
index 268e6ae5a85..912bcb576da 100644
--- a/test/it/parser/src/main/resources/case/dml/insert.xml
+++ b/test/it/parser/src/main/resources/case/dml/insert.xml
@@ -4387,4 +4387,32 @@
</value>
</values>
</insert>
+
+ <insert sql-case-id="insert_with_opendatasource_function">
+ <rowset-function text="OPENDATASOURCE('SQLNCLI', 'Data Source= <server_name>; Integrated Security=SSPI').AdventureWorks2022.HumanResources.Department" function-name="OPENDATASOURCE" start-index="12" stop-index="137">
+ <parameter>
+ <literal-expression value="SQLNCLI" start-index="27" stop-index="35"/>
+ </parameter>
+ <parameter>
+ <literal-expression value="Data Source= <server_name>; Integrated Security=SSPI" start-index="38" stop-index="91"/>
+ </parameter>
+ <parameter>
+ <literal-expression value="AdventureWorks2022.HumanResources.Department" start-index="94" stop-index="137"/>
+ </parameter>
+ </rowset-function>
+ <columns start-index="139" stop-index="155">
+ <column name="Name" start-index="140" stop-index="143"/>
+ <column name="GroupName" start-index="146" stop-index="154"/>
+ </columns>
+ <values>
+ <value>
+ <assignment-value>
+ <literal-expression value="Standards and Methods" start-index="165" stop-index="188"/>
+ </assignment-value>
+ <assignment-value>
+ <literal-expression value="Quality Assurance" start-index="191" stop-index="209"/>
+ </assignment-value>
+ </value>
+ </values>
+ </insert>
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/insert.xml b/test/it/parser/src/main/resources/sql/supported/dml/insert.xml
index 8e2ec5a4a3c..4d7f3a41e45 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/insert.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/insert.xml
@@ -157,4 +157,5 @@
<sql-case id="insert_with_geom_collection_function" value="INSERT INTO t1 VALUES (GEOMCOLLECTION(POINT(0, 0)))" db-types="MySQL" />
<sql-case id="insert_select_with_brackets" value="insert into t_order (order_id) (select order_id from t_order_item)" db-types="MySQL" />
<sql-case id="insert_into_four_level_naming" value="INSERT INTO MyLinkServer.AdventureWorks2022.HumanResources.Department (Name, GroupName) VALUES (N'Public Relations', N'Executive General and Administration');" db-types="SQLServer"/>
+ <sql-case id="insert_with_opendatasource_function" value="INSERT INTO OPENDATASOURCE('SQLNCLI', 'Data Source= <server_name>; Integrated Security=SSPI').AdventureWorks2022.HumanResources.Department (Name, GroupName) VALUES (N'Standards and Methods', 'Quality Assurance')" db-types="SQLServer"/>
</sql-cases>