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

Yu Xu updated CALCITE-7672:
---------------------------
    Description: 
The empty CAL result in the current SQL cannot be pruned by PruneEmptyRules:
@Test void testEmptyCalc() {  final String sql = "select z + x from (\n"      + 
"  select x + y as z, x from (\n"      + "    select * from (values (10, 1), 
(30, 3)) as t (x, y)\n"      + "    where x + y > 50))";
  sql(sql)
      .withPreRule(CoreRules.FILTER_VALUES_MERGE,
          CoreRules.PROJECT_TO_CALC)
      .withRule(PruneEmptyRules.CALC_INSTANCE)
      .check();
} 
plan is:
{code:java}
<TestCase name="testEmptyCalc">
    <Resource name="sql">
      <![CDATA[select z + x from (
  select x + y as z, x from (
    select * from (values (10, 1), (30, 3)) as t (x, y)
    where x + y > 50))]]>
    </Resource>
    <Resource name="planBefore">
      <![CDATA[
LogicalProject(EXPR$0=[+(+($0, $1), $0)])
  LogicalFilter(condition=[>(+($0, $1), 50)])
    LogicalValues(tuples=[[{ 10, 1 }, { 30, 3 }]])
]]>
    </Resource>
    <Resource name="planAfter">
      <![CDATA[
LogicalCalc(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[+($t2, $t0)], 
EXPR$0=[$t3])
  LogicalValues(tuples=[[]])
]]>
    </Resource>
  </TestCase> {code}
should be pruned to 
{code:java}
<TestCase name="testEmptyCalc">
    <Resource name="sql">
      <![CDATA[select z + x from (
  select x + y as z, x from (
    select * from (values (10, 1), (30, 3)) as t (x, y)
    where x + y > 50))]]>
    </Resource>
    <Resource name="planBefore">
      <![CDATA[
LogicalProject(EXPR$0=[+(+($0, $1), $0)])
  LogicalFilter(condition=[>(+($0, $1), 50)])
    LogicalValues(tuples=[[{ 10, 1 }, { 30, 3 }]])
]]>
    </Resource>
    <Resource name="planAfter">
      <![CDATA[
LogicalValues(tuples=[[]])
]]>
    </Resource>
  </TestCase> {code}
 

  was:
The empty CAL result in the current SQL cannot be pruned by PruneEmptyRules:
{code:java}
select z + x from (
  select x + y as z, x from (
    select * from (values (10, 1), (30, 3)) as t (x, y)
    where x + y > 50)) {code}
plan is:
{code:java}
<TestCase name="testEmptyCalc">
    <Resource name="sql">
      <![CDATA[select z + x from (
  select x + y as z, x from (
    select * from (values (10, 1), (30, 3)) as t (x, y)
    where x + y > 50))]]>
    </Resource>
    <Resource name="planBefore">
      <![CDATA[
LogicalProject(EXPR$0=[+(+($0, $1), $0)])
  LogicalFilter(condition=[>(+($0, $1), 50)])
    LogicalValues(tuples=[[{ 10, 1 }, { 30, 3 }]])
]]>
    </Resource>
    <Resource name="planAfter">
      <![CDATA[
LogicalCalc(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[+($t2, $t0)], 
EXPR$0=[$t3])
  LogicalValues(tuples=[[]])
]]>
    </Resource>
  </TestCase> {code}
should be pruned to 
{code:java}
<TestCase name="testEmptyCalc">
    <Resource name="sql">
      <![CDATA[select z + x from (
  select x + y as z, x from (
    select * from (values (10, 1), (30, 3)) as t (x, y)
    where x + y > 50))]]>
    </Resource>
    <Resource name="planBefore">
      <![CDATA[
LogicalProject(EXPR$0=[+(+($0, $1), $0)])
  LogicalFilter(condition=[>(+($0, $1), 50)])
    LogicalValues(tuples=[[{ 10, 1 }, { 30, 3 }]])
]]>
    </Resource>
    <Resource name="planAfter">
      <![CDATA[
LogicalValues(tuples=[[]])
]]>
    </Resource>
  </TestCase> {code}
 


> PruneEmptyRules should support pruning empty Calc
> -------------------------------------------------
>
>                 Key: CALCITE-7672
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7672
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.42.0
>            Reporter: Yu Xu
>            Assignee: Yu Xu
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.43.0
>
>
> The empty CAL result in the current SQL cannot be pruned by PruneEmptyRules:
> @Test void testEmptyCalc() {  final String sql = "select z + x from (\n"      
> + "  select x + y as z, x from (\n"      + "    select * from (values (10, 
> 1), (30, 3)) as t (x, y)\n"      + "    where x + y > 50))";
>   sql(sql)
>       .withPreRule(CoreRules.FILTER_VALUES_MERGE,
>           CoreRules.PROJECT_TO_CALC)
>       .withRule(PruneEmptyRules.CALC_INSTANCE)
>       .check();
> } 
> plan is:
> {code:java}
> <TestCase name="testEmptyCalc">
>     <Resource name="sql">
>       <![CDATA[select z + x from (
>   select x + y as z, x from (
>     select * from (values (10, 1), (30, 3)) as t (x, y)
>     where x + y > 50))]]>
>     </Resource>
>     <Resource name="planBefore">
>       <![CDATA[
> LogicalProject(EXPR$0=[+(+($0, $1), $0)])
>   LogicalFilter(condition=[>(+($0, $1), 50)])
>     LogicalValues(tuples=[[{ 10, 1 }, { 30, 3 }]])
> ]]>
>     </Resource>
>     <Resource name="planAfter">
>       <![CDATA[
> LogicalCalc(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[+($t2, $t0)], 
> EXPR$0=[$t3])
>   LogicalValues(tuples=[[]])
> ]]>
>     </Resource>
>   </TestCase> {code}
> should be pruned to 
> {code:java}
> <TestCase name="testEmptyCalc">
>     <Resource name="sql">
>       <![CDATA[select z + x from (
>   select x + y as z, x from (
>     select * from (values (10, 1), (30, 3)) as t (x, y)
>     where x + y > 50))]]>
>     </Resource>
>     <Resource name="planBefore">
>       <![CDATA[
> LogicalProject(EXPR$0=[+(+($0, $1), $0)])
>   LogicalFilter(condition=[>(+($0, $1), 50)])
>     LogicalValues(tuples=[[{ 10, 1 }, { 30, 3 }]])
> ]]>
>     </Resource>
>     <Resource name="planAfter">
>       <![CDATA[
> LogicalValues(tuples=[[]])
> ]]>
>     </Resource>
>   </TestCase> {code}
>  



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

Reply via email to