You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by da...@apache.org on 2019/11/01 06:20:23 UTC

[calcite] 01/01: [CALCITE-3449] Sync the table name logic from TableScan into the TableModify (dy.Zhuang)

This is an automated email from the ASF dual-hosted git repository.

danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git

commit a5c63c954f91e3502e0eea489fb2f7dab0930aac
Author: zhuangdy <zh...@dragonsoft.com.cn>
AuthorDate: Mon Oct 28 17:56:06 2019 +0800

    [CALCITE-3449] Sync the table name logic from TableScan into the TableModify (dy.Zhuang)
    
    When sending queries to target databse, sub schemas should be removed
    from the sql.
    
    close apache/calcite#1541
---
 .../calcite/rel/rel2sql/RelToSqlConverter.java     | 29 +++++++++++++---------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
index e4618c8..074471d 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
@@ -398,16 +398,7 @@ public class RelToSqlConverter extends SqlImplementor
 
   /** @see #dispatch */
   public Result visit(TableScan e) {
-    final SqlIdentifier identifier;
-    final JdbcTable jdbcTable = e.getTable().unwrap(JdbcTable.class);
-    if (jdbcTable != null) {
-      // Use the foreign catalog, schema and table names, if they exist,
-      // rather than the qualified name of the shadow table in Calcite.
-      identifier = jdbcTable.tableName();
-    } else {
-      final List<String> qualifiedName = e.getTable().getQualifiedName();
-      identifier = new SqlIdentifier(qualifiedName, SqlParserPos.ZERO);
-    }
+    final SqlIdentifier identifier = getSqlTargetTable(e);
     return result(identifier, ImmutableList.of(Clause.FROM), e, null);
   }
 
@@ -652,14 +643,28 @@ public class RelToSqlConverter extends SqlImplementor
             fc.getFieldIndex() < aggregate.getGroupSet().cardinality());
   }
 
+  private SqlIdentifier getSqlTargetTable(RelNode e) {
+    final SqlIdentifier sqlTargetTable;
+    final JdbcTable jdbcTable = e.getTable().unwrap(JdbcTable.class);
+    if (jdbcTable != null) {
+      // Use the foreign catalog, schema and table names, if they exist,
+      // rather than the qualified name of the shadow table in Calcite.
+      sqlTargetTable = jdbcTable.tableName();
+    } else {
+      final List<String> qualifiedName = e.getTable().getQualifiedName();
+      sqlTargetTable = new SqlIdentifier(qualifiedName, SqlParserPos.ZERO);
+    }
+
+    return sqlTargetTable;
+  }
+
   /** @see #dispatch */
   public Result visit(TableModify modify) {
     final Map<String, RelDataType> pairs = ImmutableMap.of();
     final Context context = aliasContext(pairs, false);
 
     // Target Table Name
-    final SqlIdentifier sqlTargetTable =
-        new SqlIdentifier(modify.getTable().getQualifiedName(), POS);
+    final SqlIdentifier sqlTargetTable = getSqlTargetTable(modify);
 
     switch (modify.getOperation()) {
     case INSERT: {