[
https://issues.apache.org/jira/browse/CALCITE-6770?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17911284#comment-17911284
]
Mihai Budiu commented on CALCITE-6770:
--------------------------------------
The implementation only affects SELECT lists that are subject to coercion.
Prior to this change, if an item in a select list has an explicit name
specified using an AS operator, it is preserved even after applying the cast.
In other words SELECT _expression_ AS X is converted to SELECT (CAST
_expression_ AS TYPE) AS X.
After the change if an item is just an identifier, its name is also preserved.
In other words, SELECT "a" is converted to SELECT (CAST "a" AS TYPE) AS "a".
Thus the names produced by a SELECT list do not change after this fix.
> 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)