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

Jess Balint commented on CALCITE-1551:
--------------------------------------

The difficulty that I'm facing is that it's not clear how to handle the case 
when the alias contains more than one entry, i.e. a join node. The resulting 
alias is something like {{\[<left_rel_alias, left_row_type>, <right_rel_alias, 
right_row_type>]}}. The projection can include references to an arbitrary set 
of fields from both sides of the join. Would it make sense to rework the 
{{Frame.right}} field to include the alias for each field in the row type?

I sketch an example here:
* Each frame contains an ordered listed of {{<rel_alias, field_name>}} pairs. 
Current list of {{<rel_alias, row_type>}} pairs is removed.

Given the following rel builder code:
{code:java}
.scan("EMP")
.as("e")
// (1)
.scan("DEPT")
.as("d")
// (2)
.join(JoinRelType.INNER) // condition omitted
// (3)
.project(builder.field("e", "ENAME"),
         builder.field("d", "DNAME"),
         builder.field("e", "MGR"),
         builder.literal(20))
// (4)
.as("x")
// (5)
{code}

At each numbered location above, the top {{Frame.right}} consists of the 
following:
# Scan includes all fields from EMP: {{\[<e, EMPNO>, <e, ENAME>, <e, JOB>, <e, 
MGR>, <e, HIREDATE>, <e, SAL>, <e, COMM>, <e, DEPTNO>]}}
# Scan includes all fields from DEPT: {{\[<d, DEPTNO>, <d, DNAME>, <d, LOC>]}}
# Join builds a concatenation of both lists of fields: {{\[<e, EMPNO>, <e, 
ENAME>, <e, JOB>, <e, MGR>, <e, HIREDATE>, <e, SAL>, <e, COMM>, <e, DEPTNO>, 
<d, DEPTNO>, <d, DNAME>, <d, LOC>]}}
# Project retains rel aliases of individual fields, assigning _null_ to new 
fields: {{\[<e, ENAME>, <d, DNAME>, <e, MGR>, <null, $f2>]}}
# Alias ({{as()}}) sets the alias of all fields: {{\[<x, ENAME>, <x, DNAME>, 
<x, MGR>, <x, $f2>]}}

> RelBuilder's project() doesn't preserve alias
> ---------------------------------------------
>
>                 Key: CALCITE-1551
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1551
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Jess Balint
>            Assignee: Julian Hyde
>            Priority: Minor
>
> The alias should be preserved by the project node, e.g.
> {code:java}
> .scan("EMP")
> .as("EMP_alias")
> .project(...) // resets alias to null
> .project(builder.field("EMP_alias", "DEPTNO")) // fails that no such alias 
> exists
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to