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 aa79540f23d  Enhance SQLNodeConverterEngine to support 
'select_with_database_name_and_schema_name_in_table' (#27394)
aa79540f23d is described below

commit aa79540f23d433def57d5f2c0b8a972fa86267b5
Author: Yunbo Ni <[email protected]>
AuthorDate: Mon Jul 24 16:43:07 2023 +0800

     Enhance SQLNodeConverterEngine to support 
'select_with_database_name_and_schema_name_in_table' (#27394)
    
    * fix(task8): add recursive owner names to table conversion
    
    * fix: check style
    
    * fix(task8): format
---
 .../segment/from/impl/SimpleTableConverter.java    | 10 +++++++++-
 .../src/test/resources/converter/select.xml        | 22 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/from/impl/SimpleTableConverter.java
 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/from/impl/SimpleTableConverter.java
index 42f739948f7..8fc798cd352 100644
--- 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/from/impl/SimpleTableConverter.java
+++ 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/from/impl/SimpleTableConverter.java
@@ -22,6 +22,7 @@ import org.apache.calcite.sql.SqlIdentifier;
 import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.sql.parser.SqlParserPos;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
 import 
org.apache.shardingsphere.sqlfederation.compiler.converter.segment.SQLSegmentConverter;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
@@ -41,7 +42,7 @@ public final class SimpleTableConverter implements 
SQLSegmentConverter<SimpleTab
         TableNameSegment tableName = segment.getTableName();
         List<String> names = new ArrayList<>();
         if (segment.getOwner().isPresent()) {
-            names.add(segment.getOwner().get().getIdentifier().getValue());
+            addOwnerNames(names, segment.getOwner().get());
         }
         names.add(tableName.getIdentifier().getValue());
         SqlNode tableNameSQLNode = new SqlIdentifier(names, SqlParserPos.ZERO);
@@ -51,4 +52,11 @@ public final class SimpleTableConverter implements 
SQLSegmentConverter<SimpleTab
         }
         return Optional.of(tableNameSQLNode);
     }
+    
+    private void addOwnerNames(List<String> names, OwnerSegment owner) {
+        if (null != owner) {
+            addOwnerNames(names, owner.getOwner().orElse(null));
+            names.add(owner.getIdentifier().getValue());
+        }
+    }
 }
diff --git a/test/it/optimizer/src/test/resources/converter/select.xml 
b/test/it/optimizer/src/test/resources/converter/select.xml
new file mode 100644
index 00000000000..8bcd8cc3c15
--- /dev/null
+++ b/test/it/optimizer/src/test/resources/converter/select.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<sql-node-converter-test-cases>
+    <test-cases 
sql-case-id="select_with_database_name_and_schema_name_in_table" 
expected-sql="SELECT &quot;order_id&quot; FROM 
&quot;sharding_db&quot;.&quot;public&quot;.&quot;t_order&quot; WHERE 
&quot;user_id&quot; = ? AND &quot;order_id&quot; = ?" 
db-types="PostgreSQL,openGauss" sql-case-types="PLACEHOLDER" />
+    <test-cases 
sql-case-id="select_with_database_name_and_schema_name_in_table" 
expected-sql="SELECT &quot;order_id&quot; FROM 
&quot;sharding_db&quot;.&quot;public&quot;.&quot;t_order&quot; WHERE 
&quot;user_id&quot; = 1 AND &quot;order_id&quot; = 1" 
db-types="PostgreSQL,openGauss" sql-case-types="LITERAL" />
+</sql-node-converter-test-cases>

Reply via email to