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

suibianwanwan updated CALCITE-6651:
-----------------------------------
    Description: 
In RelToSqlConverter, some unions are created using LogicalUnion.create() and 
some are relBuilder.union(). In RelBuilder.union we configure simplifyValues to 
control whether or not the {_}Union(Project(Values))} to{_}{*}_{@code_{*} 
_Values}._
{code:java}
/** Whether to simplify {@code Union(Values, Values)} or
 * {@code Union(Project(Values))} to {@code Values}; default true. */
@Value.Default default boolean simplifyValues() {
  return true;
}{code}
This will cause the configuration to not take effect where 
LogicalUnion.create() is called.

For example:
{code:java}
select * from (select 'word' i union all select 'w' i) 
{code}
Result:
{code:java}
LogicalUnion(all=[true])
   LogicalValues(tuples=[[{ 'word' }]])
   LogicalValues(tuples=[[{ 'w   ' }]])
{code}

  was:
In SqlToRelConverter, one part of Union is constructed by LogicalUnion.create 
and another part is created by relBuilder. And relBuilder.union will be based 
on RelBuilder.Config to determine whether the value needs to be simplify. but 
LogicalUnion.create will not. But LogicalUnion.create won't. This results in 
some values created by LogicalUnion.create not being simplified.

For example: In SqlToRelConverterTest: (This example may have some overlap with 
CALCITE-6350)
{code:java}
@Test void testUnionChar() {
  final String sql = "select 'a' t1 union SELECT 'ab' t1";
  sql(sql).ok();
} {code}
Result:
{code:java}
LogicalUnion(all=[false])  
  LogicalValues(tuples=[[{ 'a' }]])
  LogicalValues(tuples=[[{ 'ab' }]])
{code}
Expected result:
{code:java}
LogicalUnion(all=[false])  
  LogicalValues(tuples=[[{ 'a ' }]])
  LogicalValues(tuples=[[{ 'ab' }]])
{code}


> Use RelBuilder in SqlToRelConverter to construct Union
> ------------------------------------------------------
>
>                 Key: CALCITE-6651
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6651
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: suibianwanwan
>            Assignee: suibianwanwan
>            Priority: Major
>              Labels: pull-request-available
>
> In RelToSqlConverter, some unions are created using LogicalUnion.create() and 
> some are relBuilder.union(). In RelBuilder.union we configure simplifyValues 
> to control whether or not the {_}Union(Project(Values))} to{_}{*}_{@code_{*} 
> _Values}._
> {code:java}
> /** Whether to simplify {@code Union(Values, Values)} or
>  * {@code Union(Project(Values))} to {@code Values}; default true. */
> @Value.Default default boolean simplifyValues() {
>   return true;
> }{code}
> This will cause the configuration to not take effect where 
> LogicalUnion.create() is called.
> For example:
> {code:java}
> select * from (select 'word' i union all select 'w' i) 
> {code}
> Result:
> {code:java}
> LogicalUnion(all=[true])
>    LogicalValues(tuples=[[{ 'word' }]])
>    LogicalValues(tuples=[[{ 'w   ' }]])
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to