[ 
https://issues.apache.org/jira/browse/CALCITE-4133?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jiatao Tao updated CALCITE-4133:
--------------------------------
    Description: 
Consider case like this:

 
{code:java}
String sql =
    "select \n"
    + "   gender, \n"
    + "   count(*) \n"
    + "from \n"
    + "(\n"
    + "  (select gender, empno from EMPS) \n"
    + "  union \n"
    + "  (select gender, empno from EMPS)\n"
    + ") group by gender";

{code}
And the plan is:

 
{code:java}
EnumerableAggregate(group=[{0}], EXPR$1=[COUNT()])
  EnumerableUnion(all=[false])
    EnumerableProject(GENDER=[$3])
      EnumerableTableScan(table=[[SALES, EMPS]])
    EnumerableProject(GENDER=[$3])
      EnumerableTableScan(table=[[SALES, EMPS]])

{code}
 

The col empno has been trimmed, this changes the semantics cuz union will 
distinct values.

 

 

> Shouldn't trim fields when it's under Union
> -------------------------------------------
>
>                 Key: CALCITE-4133
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4133
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Jiatao Tao
>            Assignee: Jiatao Tao
>            Priority: Major
>
> Consider case like this:
>  
> {code:java}
> String sql =
>     "select \n"
>     + "   gender, \n"
>     + "   count(*) \n"
>     + "from \n"
>     + "(\n"
>     + "  (select gender, empno from EMPS) \n"
>     + "  union \n"
>     + "  (select gender, empno from EMPS)\n"
>     + ") group by gender";
> {code}
> And the plan is:
>  
> {code:java}
> EnumerableAggregate(group=[{0}], EXPR$1=[COUNT()])
>   EnumerableUnion(all=[false])
>     EnumerableProject(GENDER=[$3])
>       EnumerableTableScan(table=[[SALES, EMPS]])
>     EnumerableProject(GENDER=[$3])
>       EnumerableTableScan(table=[[SALES, EMPS]])
> {code}
>  
> The col empno has been trimmed, this changes the semantics cuz union will 
> distinct values.
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to