[jira] [Created] (FLINK-16320) Can not use sub-queries in the VALUES clause

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (FLINK-16320) Can not use sub-queries in the VALUES clause

Shang Yuanchun (Jira)
Dawid Wysakowicz created FLINK-16320:
----------------------------------------

             Summary: Can not use sub-queries in the VALUES clause
                 Key: FLINK-16320
                 URL: https://issues.apache.org/jira/browse/FLINK-16320
             Project: Flink
          Issue Type: Improvement
          Components: Table SQL / Legacy Planner, Table SQL / Planner
    Affects Versions: 1.11.0
            Reporter: Dawid Wysakowicz


{code}
StreamExecutionEnvironment sEnv = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tableEnvironment = StreamTableEnvironment.create(
        sEnv,
        EnvironmentSettings.newInstance().useBlinkPlanner().build());

Table table = tableEnvironment.sqlQuery("SELECT * FROM (VALUES(1), (SELECT 1))");

tableEnvironment.toRetractStream(table, Row.class).print();

System.out.println(tableEnvironment.explain(table));
{code}

Produces:

{code}
== Optimized Logical Plan ==
Union(all=[true], union=[EXPR$0])
:- Calc(select=[CAST(1) AS EXPR$0])
:  +- Values(type=[RecordType(INTEGER ZERO)], tuples=[[{ 0 }]])
+- Calc(select=[$f0 AS EXPR$0])
   +- Join(joinType=[LeftOuterJoin], where=[true], select=[ZERO, $f0], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
      :- Exchange(distribution=[single])
      :  +- Values(type=[RecordType(INTEGER ZERO)], tuples=[[{ 0 }]], reuse_id=[1])
      +- Exchange(distribution=[single])
         +- GroupAggregate(select=[SINGLE_VALUE(EXPR$0) AS $f0])
            +- Exchange(distribution=[single])
               +- Calc(select=[1 AS EXPR$0])
                  +- Reused(reference_id=[1])
{code}

which is wrong.

Legacy planner fails with:

{code}
validated type:
RecordType(INTEGER EXPR$0) NOT NULL
converted type:
RecordType(INTEGER NOT NULL EXPR$0) NOT NULL
rel:
LogicalProject(EXPR$0=[$0])
  LogicalUnion(all=[true])
    LogicalProject(EXPR$0=[1])
      LogicalValues(tuples=[[{ 0 }]])
    LogicalAggregate(group=[{}], agg#0=[SINGLE_VALUE($0)])
      LogicalProject(EXPR$0=[1])
        LogicalValues(tuples=[[{ 0 }]])
{code}



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