You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Danny Chen (Jira)" <ji...@apache.org> on 2019/10/28 01:48:00 UTC

[jira] [Commented] (CALCITE-3449) Use the foreign catalog, schema and table names if they exist rather than the qualified name of the shadow table

    [ https://issues.apache.org/jira/browse/CALCITE-3449?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16960715#comment-16960715 ] 

Danny Chen commented on CALCITE-3449:
-------------------------------------

Thanks [~zhuangdy] for reporting this, can you fire a patch for this, sync the table name logic from TableScan into the TableModify.

> Use the foreign catalog, schema and table names if they exist rather than the qualified name of the shadow table
> ----------------------------------------------------------------------------------------------------------------
>
>                 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
>            Priority: Major
>   Original Estimate: 12h
>  Remaining Estimate: 12h
>
> 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)