Zhuang created CALCITE-3449: ------------------------------- Summary: Modify sql will have sub schema in it's table name Key: CALCITE-3449 URL: https://issues.apache.org/jira/browse/CALCITE-3449 Project: Calcite Issue Type: Bug Components: core Affects Versions: 1.21.0 Reporter: Zhuang
When sending queries to target databse, sub schemas should be removed from the sql, but not for modify statement(update\delete\insert). For example, {quote}delete from "sub_schema".target_table where ... {quote} will send following sql to target database {quote}delete from {color:#ff0000}"sub_schema"{color}.target_table where ... {quote} But select quries worked as expect. {quote}select * from "sub_schema".target_table {quote} will be translated into following and send to target databse. {quote}select * from target_table {quote} I've done some inspect, and find that the code are different. In org.apache.calcite.rel.rel2sql.RelToSqlConverter.java, the table names have sub schemas in it. {code:title=RelToSqlConverter.java|borderStyle=solid}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); {code} But in select query , the table name are just table name, without sub schema. {code:title=Bar.java|borderStyle=solid} 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); } {code} I'm really new to Caicite and commit issues, thanks! -- This message was sent by Atlassian Jira (v8.3.4#803005)