[
https://issues.apache.org/jira/browse/CALCITE-6770?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17911282#comment-17911282
]
Julian Hyde commented on CALCITE-6770:
--------------------------------------
Is this for relational algebra or SQL or both? Would {{SELECT CAST(empno AS
VARCHAR) FROM emp}} generate a column with alias "{{empno}}". I presume no.
If a {{Project}} contains two casts of the same column, would they have
distinct names? E.g.
{noformat}
LogicalProject(EMPNO=$1, EMPNO1=[CAST($1):VARCHAR) NOT NULL],
EMPNO2=[CAST($1):REAL) NOT NULL])
LogicalTableScan(table=[[scott, emp]])
{noformat}
Does this change apply only to {{SqlToRelConverter}} or does it also apply if I
invoke {{RelBuilder.project}}?
> Preserve column names when casts are inserted in projects
> ---------------------------------------------------------
>
> Key: CALCITE-6770
> URL: https://issues.apache.org/jira/browse/CALCITE-6770
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Affects Versions: 1.38.0
> Reporter: Mihai Budiu
> Assignee: Mihai Budiu
> Priority: Minor
> Labels: pull-request-available
>
> Consider this SQL:
> {code:sql}
> CREATE TABLE B(id VARCHAR);
> CREATE VIEW V1 AS SELECT id, 'x' as y FROM B;
> CREATE VIEW V2 AS SELECT id, 'xx' as y FROM B;
> CREATE VIEW U AS SELECT * FROM V1 UNION ALL SELECT * FROM V2;
> {code}
> The generated plan looks like this:
> {code}
> LogicalUnion(all=[true]), id = 187
> LogicalProject(id=[$0], EXPR$1=[CAST($1):VARCHAR(2) NOT NULL]), id = 182
> LogicalTableScan(table=[[schema, v1]]), id = 115
> LogicalProject(id=[$0], EXPR$1=[CAST($1):VARCHAR(2) NOT NULL]), id = 185
> LogicalTableScan(table=[[schema, v2]]), id = 118
> {code}
> Notice that the second column has a new name, EXPR$1. Preserving the original
> column name would produce a more readable plan and error messages.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)