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 65c44cd  fix postgresql/openguass delete with schema (#13401)
65c44cd is described below

commit 65c44cd0c2ed39cce9b3b149ae21ec2d18f4cb04
Author: tuichenchuxin <[email protected]>
AuthorDate: Tue Nov 2 10:26:00 2021 +0800

    fix postgresql/openguass delete with schema (#13401)
---
 .../visitor/statement/impl/OpenGaussStatementSQLVisitor.java     | 9 +--------
 .../visitor/statement/impl/PostgreSQLStatementSQLVisitor.java    | 9 +--------
 .../src/main/resources/case/dml/delete.xml                       | 6 ++++++
 .../src/main/resources/sql/supported/dml/delete.xml              | 1 +
 .../src/test/resources/scenario/sharding/case/delete.xml         | 8 ++++----
 5 files changed, 13 insertions(+), 20 deletions(-)

diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
index 0b78534..3991666 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
@@ -687,16 +687,9 @@ public abstract class OpenGaussStatementSQLVisitor extends 
OpenGaussStatementBas
     
     @Override
     public ASTNode visitRelationExprOptAlias(final RelationExprOptAliasContext 
ctx) {
-        SimpleTableSegment result;
+        SimpleTableSegment result = 
generateTableFromRelationExpr(ctx.relationExpr());
         if (null != ctx.colId()) {
-            ColIdContext colId = ctx.relationExpr().qualifiedName().colId();
-            TableNameSegment tableName = new 
TableNameSegment(colId.start.getStartIndex(), colId.stop.getStopIndex(), new 
IdentifierValue(colId.getText()));
-            result = new SimpleTableSegment(tableName);
             result.setAlias(new 
AliasSegment(ctx.colId().start.getStartIndex(), ctx.stop.getStopIndex(), new 
IdentifierValue(ctx.colId().getText())));
-        } else {
-            ColIdContext colId = ctx.relationExpr().qualifiedName().colId();
-            TableNameSegment tableName = new 
TableNameSegment(colId.start.getStartIndex(), colId.stop.getStopIndex(), new 
IdentifierValue(colId.getText()));
-            result = new SimpleTableSegment(tableName);
         }
         return result;
     }
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
index 8c30ea5..11a3298 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
@@ -687,16 +687,9 @@ public abstract class PostgreSQLStatementSQLVisitor 
extends PostgreSQLStatementB
     
     @Override
     public ASTNode visitRelationExprOptAlias(final RelationExprOptAliasContext 
ctx) {
-        SimpleTableSegment result;
+        SimpleTableSegment result = 
generateTableFromRelationExpr(ctx.relationExpr());
         if (null != ctx.colId()) {
-            ColIdContext colId = ctx.relationExpr().qualifiedName().colId();
-            TableNameSegment tableName = new 
TableNameSegment(colId.start.getStartIndex(), colId.stop.getStopIndex(), new 
IdentifierValue(colId.getText()));
-            result = new SimpleTableSegment(tableName);
             result.setAlias(new 
AliasSegment(ctx.colId().start.getStartIndex(), ctx.stop.getStopIndex(), new 
IdentifierValue(ctx.colId().getText())));
-        } else {
-            ColIdContext colId = ctx.relationExpr().qualifiedName().colId();
-            TableNameSegment tableName = new 
TableNameSegment(colId.start.getStartIndex(), colId.stop.getStopIndex(), new 
IdentifierValue(colId.getText()));
-            result = new SimpleTableSegment(tableName);
         }
         return result;
     }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/delete.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/delete.xml
index 3a2fede..ae91987 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/delete.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/delete.xml
@@ -682,4 +682,10 @@
     <delete sql-case-id="delete_with_table">
         <table name="product_price_history" start-index="7" stop-index="27" />
     </delete>
+
+    <delete sql-case-id="delete_with_schema">
+        <table name="t_order" start-index="12" stop-index="22">
+            <owner name="db1" start-index="12" stop-index="14" />
+        </table>
+    </delete>
 </sql-parser-test-cases>
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/delete.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/delete.xml
index 6bcd57f..c9f94f8 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/delete.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/delete.xml
@@ -41,4 +41,5 @@
     <sql-case id="delete_with_returning_into" value="DELETE FROM employees 
WHERE job_id = 'SA_REP' AND hire_date + TO_YMINTERVAL('01-00') &lt; SYSDATE 
RETURNING salary INTO bnd1" db-types="Oracle" />
     <sql-case id="delete_with_partition" value="DELETE FROM sales PARTITION 
(sales_q1_1998) WHERE amount_sold > 1000" db-types="Oracle" />
     <sql-case id="delete_with_table" value="DELETE product_price_history" 
db-types="Oracle" />
+    <sql-case id="delete_with_schema" value="DELETE FROM db1.t_order" />
 </sql-cases>
diff --git 
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/delete.xml
 
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/delete.xml
index aef1892..d5b7864 100644
--- 
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/delete.xml
+++ 
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/delete.xml
@@ -17,23 +17,23 @@
   -->
 
 <rewrite-assertions yaml-rule="scenario/sharding/config/sharding-rule.yaml">
-    <rewrite-assertion id="delete_with_sharding_value_for_parameters" 
db-types="SQL92">
+    <rewrite-assertion id="delete_with_sharding_value_for_parameters">
         <input sql="DELETE FROM t_account WHERE account_id = ?" 
parameters="100" />
         <output sql="DELETE FROM t_account_0 WHERE account_id = ?" 
parameters="100" />
     </rewrite-assertion>
     
-    <rewrite-assertion id="delete_with_sharding_value_for_literals" 
db-types="SQL92">
+    <rewrite-assertion id="delete_with_sharding_value_for_literals">
         <input sql="DELETE FROM t_account WHERE account_id = 100" />
         <output sql="DELETE FROM t_account_0 WHERE account_id = 100" />
     </rewrite-assertion>
     
-    <rewrite-assertion id="delete_without_sharding_value_for_parameters" 
db-types="SQL92">
+    <rewrite-assertion id="delete_without_sharding_value_for_parameters">
         <input sql="DELETE FROM sharding_db.t_account WHERE status = ?" 
parameters="OK" />
         <output sql="DELETE FROM t_account_0 WHERE status = ?" parameters="OK" 
/>
         <output sql="DELETE FROM t_account_1 WHERE status = ?" parameters="OK" 
/>
     </rewrite-assertion>
     
-    <rewrite-assertion id="delete_without_sharding_value_for_literals" 
db-types="SQL92">
+    <rewrite-assertion id="delete_without_sharding_value_for_literals">
         <input sql="DELETE FROM sharding_db.t_account WHERE status = 'OK'" />
         <output sql="DELETE FROM t_account_0 WHERE status = 'OK'" />
         <output sql="DELETE FROM t_account_1 WHERE status = 'OK'" />

Reply via email to