Skip to content

Commit a5c63c9

Browse files
zhuangdydanny0405
authored andcommitted
[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 #1541
1 parent aa98c15 commit a5c63c9

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,16 +398,7 @@ private SqlNode groupItem(List<SqlNode> groupKeys,
398398

399399
/** @see #dispatch */
400400
public Result visit(TableScan e) {
401-
final SqlIdentifier identifier;
402-
final JdbcTable jdbcTable = e.getTable().unwrap(JdbcTable.class);
403-
if (jdbcTable != null) {
404-
// Use the foreign catalog, schema and table names, if they exist,
405-
// rather than the qualified name of the shadow table in Calcite.
406-
identifier = jdbcTable.tableName();
407-
} else {
408-
final List<String> qualifiedName = e.getTable().getQualifiedName();
409-
identifier = new SqlIdentifier(qualifiedName, SqlParserPos.ZERO);
410-
}
401+
final SqlIdentifier identifier = getSqlTargetTable(e);
411402
return result(identifier, ImmutableList.of(Clause.FROM), e, null);
412403
}
413404

@@ -652,14 +643,28 @@ public boolean hasTrickyRollup(Sort e, Aggregate aggregate) {
652643
fc.getFieldIndex() < aggregate.getGroupSet().cardinality());
653644
}
654645

646+
private SqlIdentifier getSqlTargetTable(RelNode e) {
647+
final SqlIdentifier sqlTargetTable;
648+
final JdbcTable jdbcTable = e.getTable().unwrap(JdbcTable.class);
649+
if (jdbcTable != null) {
650+
// Use the foreign catalog, schema and table names, if they exist,
651+
// rather than the qualified name of the shadow table in Calcite.
652+
sqlTargetTable = jdbcTable.tableName();
653+
} else {
654+
final List<String> qualifiedName = e.getTable().getQualifiedName();
655+
sqlTargetTable = new SqlIdentifier(qualifiedName, SqlParserPos.ZERO);
656+
}
657+
658+
return sqlTargetTable;
659+
}
660+
655661
/** @see #dispatch */
656662
public Result visit(TableModify modify) {
657663
final Map<String, RelDataType> pairs = ImmutableMap.of();
658664
final Context context = aliasContext(pairs, false);
659665

660666
// Target Table Name
661-
final SqlIdentifier sqlTargetTable =
662-
new SqlIdentifier(modify.getTable().getQualifiedName(), POS);
667+
final SqlIdentifier sqlTargetTable = getSqlTargetTable(modify);
663668

664669
switch (modify.getOperation()) {
665670
case INSERT: {

0 commit comments

Comments
 (0)