Flink SQL 1.0+ UT Cases

Flink SQL UT Case

截止當前flink master分支最新的代碼(未完成的1.1版本),Flink Table項目的UT,batch sql(即直接調用.sql())的sql, logicalPlan, physicalPlan整理。

/** Filter **/

SELECT * FROM MyTable WHERE false

LogicalProject(_1=[$0], _2=[$1], _3=[$2])
  LogicalFilter(condition=[false])
    LogicalTableScan(table=[[MyTable]])

DataSetCalc(select=[_1, _2, _3], where=[false]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 9000.0 cpu, 0.0 io}, id = 99
  DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 93


SELECT * FROM MyTable WHERE true

LogicalProject(_1=[$0], _2=[$1], _3=[$2])
  LogicalTableScan(table=[[MyTable]])

DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 13


SELECT * FROM MyTable WHERE c LIKE '%world%'

LogicalProject(a=[$0], b=[$1], c=[$2])
  LogicalFilter(condition=[LIKE($2, '%world%')])
    LogicalTableScan(table=[[MyTable]])

DataSetCalc(select=[AS(_1, 'a') AS _1, AS(_2, 'b') AS _2, AS(_3, 'c') AS _3], where=[LIKE(AS(_3, 'c'), '%world%')]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 16000.0 cpu, 0.0 io}, id = 44
  DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 28


SELECT * FROM MyTable WHERE MOD(a,2)=0

LogicalProject(a=[$0], b=[$1], c=[$2])
  LogicalFilter(condition=[=(MOD($0, 2), 0)])
    LogicalTableScan(table=[[MyTable]])

DataSetCalc(select=[AS(_1, 'a') AS _1, AS(_2, 'b') AS _2, AS(_3, 'c') AS _3], where=[=(MOD(AS(_1, 'a'), 2), 0)]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 18000.0 cpu, 0.0 io}, id = 44
  DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 28


SELECT * FROM MyTable WHERE a < 2 OR a > 20

LogicalProject(a=[$0], b=[$1], c=[$2])
  LogicalFilter(condition=[OR(<($0, 2), >($0, 20))])
    LogicalTableScan(table=[[MyTable]])

DataSetCalc(select=[AS(_1, 'a') AS _1, AS(_2, 'b') AS _2, AS(_3, 'c') AS _3], where=[OR(<(AS(_1, 'a'), 2), >(AS(_1, 'a'), 20))]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 19000.0 cpu, 0.0 io}, id = 44
  DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 28


SELECT * FROM MyTable WHERE MOD(a,2)<>0 AND MOD(b,2)=0

LogicalProject(a=[$0], b=[$1], c=[$2])
  LogicalFilter(condition=[AND(<>(MOD($0, 2), 0), =(MOD($1, 2), 0))])
    LogicalTableScan(table=[[MyTable]])

DataSetCalc(select=[AS(_1, 'a') AS _1, AS(_2, 'b') AS _2, AS(_3, 'c') AS _3], where=[AND(<>(MOD(AS(_1, 'a'), 2), 0), =(MOD(AS(_2, 'b'), 2), 0))]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 21000.0 cpu, 0.0 io}, id = 44
  DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 28


/** Join **/

SELECT c, g FROM Table3, Table5 WHERE b = e

LogicalProject(c=[$2], g=[$6])
  LogicalFilter(condition=[=($1, $4)])
    LogicalJoin(condition=[true], joinType=[inner])
      LogicalTableScan(table=[[Table3]])
      LogicalTableScan(table=[[Table5]])

DataSetCalc(select=[c AS b, g AS c]): rowcount = 1.0, cumulative cost = {6001.0 rows, 24006.0 cpu, 40000.0 io}, id = 265
  DataSetJoin(where=[=(b, e)], join=[b, c, e, g], joinType=[Join]): rowcount = 1.0, cumulative cost = {6000.0 rows, 24000.0 cpu, 40000.0 io}, id = 264
    DataSetCalc(select=[AS(_2, 'b') AS _1, AS(_3, 'c') AS _2]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 10000.0 cpu, 0.0 io}, id = 262
      DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 198
    DataSetCalc(select=[AS(_2, 'e') AS _1, AS(_4, 'g') AS _2]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 12000.0 cpu, 0.0 io}, id = 263
      DataSetScan(table=[[_DataSetTable_1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 200


SELECT c, g FROM Table3, Table5 WHERE b = e AND b < 2

LogicalProject(c=[$2], g=[$6])
  LogicalFilter(condition=[AND(=($1, $4), <($1, 2))])
    LogicalJoin(condition=[true], joinType=[inner])
      LogicalTableScan(table=[[Table3]])
      LogicalTableScan(table=[[Table5]])

 DataSetCalc(select=[c AS b, g AS c]): rowcount = 1.0, cumulative cost = {6001.0 rows, 27006.0 cpu, 40000.0 io}, id = 425
  DataSetJoin(where=[=(b, e)], join=[b, c, e, g], joinType=[Join]): rowcount = 1.0, cumulative cost = {6000.0 rows, 27000.0 cpu, 40000.0 io}, id = 424
    DataSetCalc(select=[AS(_2, 'b') AS _1, AS(_3, 'c') AS _2], where=[<(AS(_2, 'b'), 2)]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 13000.0 cpu, 0.0 io}, id = 422
      DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 278
    DataSetCalc(select=[AS(_2, 'e') AS _1, AS(_4, 'g') AS _2]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 12000.0 cpu, 0.0 io}, id = 423
      DataSetScan(table=[[_DataSetTable_1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 280


SELECT c, g FROM Table3, Table5 WHERE b = e AND a < 6 AND h < b

LogicalProject(c=[$2], g=[$6])
  LogicalFilter(condition=[AND(=($1, $4), <($0, 6), <($7, $1))])
    LogicalJoin(condition=[true], joinType=[inner])
      LogicalTableScan(table=[[Table3]])
      LogicalTableScan(table=[[Table5]])

DataSetCalc(select=[c AS b, g AS c]): rowcount = 1.0, cumulative cost = {6001.0 rows, 32007.0 cpu, 48000.0 io}, id = 208
  DataSetJoin(where=[AND(=(b, e), <(h, b))], join=[b, c, e, g, h], joinType=[Join]): rowcount = 1.0, cumulative cost = {6000.0 rows, 32000.0 cpu, 48000.0 io}, id = 207
    DataSetCalc(select=[AS(_2, 'b') AS _1, AS(_3, 'c') AS _2], where=[<(AS(_1, 'a'), 6)]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 15000.0 cpu, 0.0 io}, id = 205
      DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 65
    DataSetCalc(select=[AS(_2, 'e') AS _1, AS(_4, 'g') AS _2, AS(_5, 'h') AS _3]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 15000.0 cpu, 0.0 io}, id = 206
      DataSetScan(table=[[_DataSetTable_1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 67


SELECT c, g FROM Table3, Table5 WHERE a = d AND b = h

LogicalProject(c=[$2], g=[$6])
  LogicalFilter(condition=[AND(=($0, $3), =($1, $7))])
    LogicalJoin(condition=[true], joinType=[inner])
      LogicalTableScan(table=[[Table3]])
      LogicalTableScan(table=[[Table5]])

DataSetCalc(select=[c AS a, g AS b]): rowcount = 1.0, cumulative cost = {6001.0 rows, 30008.0 cpu, 48000.0 io}, id = 129
  DataSetJoin(where=[AND(=(a, d), =(b, h))], join=[a, b, c, d, g, h], joinType=[Join]): rowcount = 1.0, cumulative cost = {6000.0 rows, 30000.0 cpu, 48000.0 io}, id = 128
    DataSetCalc(select=[AS(_1, 'a') AS _1, AS(_2, 'b') AS _2, AS(_3, 'c') AS _3]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 13000.0 cpu, 0.0 io}, id = 126
      DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 65
    DataSetCalc(select=[AS(_1, 'd') AS _1, AS(_4, 'g') AS _2, AS(_5, 'h') AS _3]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 15000.0 cpu, 0.0 io}, id = 127
      DataSetScan(table=[[_DataSetTable_1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 67


SELECT c, g FROM Table3, Table5 WHERE a = g

LogicalProject(c=[$2], g=[$6])
  LogicalFilter(condition=[=($0, $6)])
    LogicalJoin(condition=[true], joinType=[inner])
      LogicalTableScan(table=[[Table3]])
      LogicalTableScan(table=[[Table5]])

DataSetCalc(select=[c AS a, g AS c]): rowcount = 1.0, cumulative cost = {6001.0 rows, 21005.0 cpu, 28000.0 io}, id = 132
  DataSetJoin(where=[=(a, g)], join=[a, c, g], joinType=[Join]): rowcount = 1.0, cumulative cost = {6000.0 rows, 21000.0 cpu, 28000.0 io}, id = 131
    DataSetCalc(select=[AS(_1, 'a') AS _1, AS(_3, 'c') AS _2]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 10000.0 cpu, 0.0 io}, id = 129
      DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 65
    DataSetCalc(select=[AS(_4, 'g') AS _1]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 9000.0 cpu, 0.0 io}, id = 130
      DataSetScan(table=[[_DataSetTable_1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 67


SELECT Table5.c, Table3.c FROM Table3, Table5 WHERE a = d AND a < 4

LogicalProject(c=[$7], c0=[$2])
  LogicalFilter(condition=[AND(=($0, $3), <($0, 4))])
    LogicalJoin(condition=[true], joinType=[inner])
      LogicalTableScan(table=[[Table3]])
      LogicalTableScan(table=[[Table5]])

DataSetCalc(select=[c0 AS a, c]): rowcount = 1.0, cumulative cost = {6001.0 rows, 27006.0 cpu, 28000.0 io}, id = 212
  DataSetJoin(where=[=(a, d)], join=[a, c, d, c0], joinType=[Join]): rowcount = 1.0, cumulative cost = {6000.0 rows, 27000.0 cpu, 28000.0 io}, id = 211
    DataSetCalc(select=[AS(_1, 'a') AS _1, AS(_3, 'c') AS _2], where=[<(AS(_1, 'a'), 4)]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 13000.0 cpu, 0.0 io}, id = 209
      DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 65
    DataSetCalc(select=[AS(_1, 'd') AS _1, AS(_5, 'c') AS _2]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 12000.0 cpu, 0.0 io}, id = 210
      DataSetScan(table=[[_DataSetTable_1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 67


SELECT COUNT(g), COUNT(b) FROM Table3, Table5 WHERE a = d

LogicalAggregate(group=[{}], EXPR$0=[COUNT($0)], EXPR$1=[COUNT($1)])
  LogicalProject(g=[$6], b=[$1])
    LogicalFilter(condition=[=($0, $3)])
      LogicalJoin(condition=[true], joinType=[inner])
        LogicalTableScan(table=[[Table3]])
        LogicalTableScan(table=[[Table5]])

DataSetAggregate(select=[COUNT(g) AS EXPR$0, COUNT(b) AS EXPR$1]): rowcount = 1.0, cumulative cost = {6002.0 rows, 16008.0 cpu, 28020.0 io}, id = 175
  DataSetCalc(select=[g AS a, b]): rowcount = 1.0, cumulative cost = {6001.0 rows, 16006.0 cpu, 28000.0 io}, id = 174
    DataSetJoin(where=[=(a, d)], join=[a, b, d, g], joinType=[Join]): rowcount = 1.0, cumulative cost = {6000.0 rows, 16000.0 cpu, 28000.0 io}, id = 173
      DataSetCalc(select=[a, b]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 6000.0 cpu, 0.0 io}, id = 171
        DataSetScan(table=[[Table3]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 161
      DataSetCalc(select=[d, g AS e]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 8000.0 cpu, 0.0 io}, id = 172
        DataSetScan(table=[[Table5]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 162


SELECT c, g FROM Table3 FULL OUTER JOIN Table5 ON b = e

LogicalProject(c=[$2], g=[$6])
  LogicalJoin(condition=[=($1, $4)], joinType=[full])
    LogicalTableScan(table=[[Table3]])
    LogicalTableScan(table=[[Table5]])

DataSetCalc(select=[c AS b, g AS c]): rowcount = 1.0, cumulative cost = {6001.0 rows, 24006.0 cpu, 40000.0 io}, id = 74
  DataSetJoin(where=[=(b, e)], join=[b, c, e, g], joinType=[FullOuterJoin]): rowcount = 1.0, cumulative cost = {6000.0 rows, 24000.0 cpu, 40000.0 io}, id = 73
    DataSetCalc(select=[AS(_2, 'b') AS _1, AS(_3, 'c') AS _2]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 10000.0 cpu, 0.0 io}, id = 71
      DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 49
    DataSetCalc(select=[AS(_2, 'e') AS _1, AS(_4, 'g') AS _2]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 12000.0 cpu, 0.0 io}, id = 72
      DataSetScan(table=[[_DataSetTable_1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 51


SELECT c, g FROM Table5 LEFT OUTER JOIN Table3 ON b = e

LogicalProject(c=[$7], g=[$3])
  LogicalJoin(condition=[=($6, $1)], joinType=[left])
    LogicalTableScan(table=[[Table5]])
    LogicalTableScan(table=[[Table3]])

DataSetCalc(select=[c AS e, g]): rowcount = 1.0, cumulative cost = {6001.0 rows, 24006.0 cpu, 40000.0 io}, id = 74
  DataSetJoin(where=[=(b, e)], join=[e, g, b, c], joinType=[LeftOuterJoin]): rowcount = 1.0, cumulative cost = {6000.0 rows, 24000.0 cpu, 40000.0 io}, id = 73
    DataSetCalc(select=[AS(_2, 'e') AS _1, AS(_4, 'g') AS _2]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 12000.0 cpu, 0.0 io}, id = 71
      DataSetScan(table=[[_DataSetTable_1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 51
    DataSetCalc(select=[AS(_2, 'b') AS _1, AS(_3, 'c') AS _2]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 10000.0 cpu, 0.0 io}, id = 72
      DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 49


SELECT c, g FROM Table3 RIGHT OUTER JOIN Table5 ON b = e

LogicalProject(c=[$2], g=[$6])
  LogicalJoin(condition=[=($1, $4)], joinType=[right])
    LogicalTableScan(table=[[Table3]])
    LogicalTableScan(table=[[Table5]])

DataSetCalc(select=[c AS b, g AS c]): rowcount = 1.0, cumulative cost = {6001.0 rows, 24006.0 cpu, 40000.0 io}, id = 74
  DataSetJoin(where=[=(b, e)], join=[b, c, e, g], joinType=[RightOuterJoin]): rowcount = 1.0, cumulative cost = {6000.0 rows, 24000.0 cpu, 40000.0 io}, id = 73
    DataSetCalc(select=[AS(_2, 'b') AS _1, AS(_3, 'c') AS _2]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 10000.0 cpu, 0.0 io}, id = 71
      DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 49
    DataSetCalc(select=[AS(_2, 'e') AS _1, AS(_4, 'g') AS _2]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 12000.0 cpu, 0.0 io}, id = 72
      DataSetScan(table=[[_DataSetTable_1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 51


/** Aggregations **/

SELECT sum(_1), min(_1), max(_1), count(_1), avg(_1) FROM MyTable

LogicalAggregate(group=[{}], EXPR$0=[SUM($0)], EXPR$1=[MIN($0)], EXPR$2=[MAX($0)], EXPR$3=[COUNT($0)], EXPR$4=[AVG($0)])
  LogicalProject(_1=[$0])
    LogicalTableScan(table=[[MyTable]])

DataSetAggregate(select=[SUM(_1) AS EXPR$0, MIN(_1) AS EXPR$1, MAX(_1) AS EXPR$2, COUNT(_1) AS EXPR$3, AVG(_1) AS EXPR$4]): rowcount = 1000.0, cumulative cost = {3000.0 rows, 10000.0 cpu, 4000.0 io}, id = 26
  DataSetCalc(select=[_1]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 5000.0 cpu, 0.0 io}, id = 25
    DataSetScan(table=[[MyTable]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 23


SELECT avg(_1), avg(_2), avg(_3), avg(_4), avg(_5), avg(_6), count(_7), sum(CAST(_6 AS DECIMAL)) FROM MyTable

LogicalAggregate(group=[{}], EXPR$0=[AVG($0)], EXPR$1=[AVG($1)], EXPR$2=[AVG($2)], EXPR$3=[AVG($3)], EXPR$4=[AVG($4)], EXPR$5=[AVG($5)], EXPR$6=[COUNT($6)], EXPR$7=[SUM($7)])
  LogicalProject(_1=[$0], _2=[$1], _3=[$2], _4=[$3], _5=[$4], _6=[$5], _7=[$6], $f7=[CAST($5):DECIMAL(1073741823, 0)])
    LogicalTableScan(table=[[MyTable]])

DataSetAggregate(select=[AVG(_1) AS EXPR$0, AVG(_2) AS EXPR$1, AVG(_3) AS EXPR$2, AVG(_4) AS EXPR$3, AVG(_5) AS EXPR$4, AVG(_6) AS EXPR$5, COUNT(_7) AS EXPR$6, SUM($f7) AS EXPR$7]): rowcount = 1000.0, cumulative cost = {3000.0 rows, 25000.0 cpu, 51000.0 io}, id = 24
  DataSetCalc(select=[_1, _2, _3, _4, _5, _6, _7]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 17000.0 cpu, 0.0 io}, id = 23
    DataSetScan(table=[[MyTable]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 21


SELECT avg(a + 2) + 2, count(b) + 5 FROM MyTable

LogicalProject(EXPR$0=[+($0, 2)], EXPR$1=[+($1, 5)])
  LogicalAggregate(group=[{}], agg#0=[AVG($0)], agg#1=[COUNT($1)])
    LogicalProject($f0=[+($0, 2)], b=[$1])
      LogicalTableScan(table=[[MyTable]])

DataSetCalc(select=[+($f0, 2) AS $f0, +($f1, 5) AS $f1]): rowcount = 1000.0, cumulative cost = {4000.0 rows, 17000.0 cpu, 16000.0 io}, id = 32
  DataSetAggregate(select=[AVG($f0) AS $f0, COUNT(b) AS $f1]): rowcount = 1000.0, cumulative cost = {3000.0 rows, 9000.0 cpu, 16000.0 io}, id = 31
    DataSetCalc(select=[+(a, 2) AS a, b]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 7000.0 cpu, 0.0 io}, id = 30
      DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 26


SELECT avg(a), sum(b), count(c) FROM (SELECT _1 as a, _2 as b, _3 as c FROM MyTable)

LogicalAggregate(group=[{}], EXPR$0=[AVG($0)], EXPR$1=[SUM($1)], EXPR$2=[COUNT($2)])
  LogicalProject(a=[$0], b=[$1], c=[$2])
    LogicalTableScan(table=[[MyTable]])

DataSetAggregate(select=[AVG(a) AS EXPR$0, SUM(b) AS EXPR$1, COUNT(c) AS EXPR$2]): rowcount = 1000.0, cumulative cost = {3000.0 rows, 14000.0 cpu, 7000.0 io}, id = 27
  DataSetCalc(select=[_1, _2, _3]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 11000.0 cpu, 0.0 io}, id = 26
    DataSetScan(table=[[_DataSetTable_0]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 20


SELECT sum(_1) as a, count(distinct _3) as b FROM MyTable

LogicalAggregate(group=[{}], a=[SUM($0)], b=[COUNT(DISTINCT $1)])
  LogicalProject(_1=[$0], _3=[$2])
    LogicalTableScan(table=[[MyTable]])

/** distinct not support**/


SELECT _2, _3, avg(_1) as a FROM MyTable GROUP BY GROUPING SETS (_2, _3)

LogicalProject(_2=[$0], _3=[$1], a=[$4])
  LogicalProject(_2=[CASE($2, null, $0)], _3=[CASE($3, null, $1)], i$_2=[$2], i$_3=[$3], a=[$4])
    LogicalAggregate(group=[{0, 1}], groups=[[{0}, {1}]], indicator=[true], a=[AVG($2)])
      LogicalProject(_2=[$1], _3=[$2], _1=[$0])
        LogicalTableScan(table=[[MyTable]])

/** grouping set not support **/


/** Set **/

SELECT c FROM t1 UNION ALL (SELECT c FROM t2)

LogicalUnion(all=[true])
  LogicalProject(c=[$2])
    LogicalTableScan(table=[[t1]])
  LogicalProject(c=[$2])
    LogicalTableScan(table=[[t2]])

DataSetUnion(union=[c]): rowcount = 1.0, cumulative cost = {6000.0 rows, 10000.0 cpu, 0.0 io}, id = 40
  DataSetCalc(select=[c AS a]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 5000.0 cpu, 0.0 io}, id = 38
    DataSetScan(table=[[t1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 34
  DataSetCalc(select=[c AS a]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 5000.0 cpu, 0.0 io}, id = 39
    DataSetScan(table=[[t2]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 35


SELECT c FROM (SELECT * FROM t1 UNION ALL (SELECT a, b, c FROM t2)) WHERE b < 2

LogicalProject(c=[$2])
  LogicalFilter(condition=[<($1, 2)])
    LogicalUnion(all=[true])
      LogicalProject(a=[$0], b=[$1], c=[$2])
        LogicalTableScan(table=[[t1]])
      LogicalProject(a=[$0], b=[$1], c=[$3])
        LogicalTableScan(table=[[t2]])

DataSetCalc(select=[c AS a], where=[<(b, 2)]): rowcount = 1.0, cumulative cost = {5001.0 rows, 10007.0 cpu, 0.0 io}, id = 93
  DataSetUnion(union=[a, b, c]): rowcount = 1.0, cumulative cost = {5000.0 rows, 10000.0 cpu, 0.0 io}, id = 92
    DataSetScan(table=[[t1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 85
    DataSetCalc(select=[a, b, c AS d]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 9000.0 cpu, 0.0 io}, id = 91
      DataSetScan(table=[[t2]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 89


SELECT count(c) FROM (SELECT * FROM t1 UNION ALL (SELECT a, b, c FROM t2))

LogicalAggregate(group=[{}], EXPR$0=[COUNT($0)])
  LogicalProject(c=[$2])
    LogicalUnion(all=[true])
      LogicalProject(a=[$0], b=[$1], c=[$2])
        LogicalTableScan(table=[[t1]])
      LogicalProject(a=[$0], b=[$1], c=[$3])
        LogicalTableScan(table=[[t2]])

DataSetAggregate(select=[COUNT(c) AS EXPR$0]): rowcount = 1.0, cumulative cost = {5002.0 rows, 10005.0 cpu, 12.0 io}, id = 56
  DataSetCalc(select=[c AS a]): rowcount = 1.0, cumulative cost = {5001.0 rows, 10004.0 cpu, 0.0 io}, id = 55
    DataSetUnion(union=[a, b, c]): rowcount = 1.0, cumulative cost = {5000.0 rows, 10000.0 cpu, 0.0 io}, id = 54
      DataSetScan(table=[[t1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 47
      DataSetCalc(select=[a, b, c AS d]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 9000.0 cpu, 0.0 io}, id = 53
        DataSetScan(table=[[t2]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 51


SELECT c FROM t1 INTERSECT SELECT c FROM t2

LogicalIntersect(all=[false])
  LogicalProject(c=[$2])
    LogicalTableScan(table=[[t1]])
  LogicalProject(c=[$2])
    LogicalTableScan(table=[[t2]])

DataSetIntersect(intersect=[c]): rowcount = 1.0, cumulative cost = {6000.0 rows, 12000.0 cpu, 24000.0 io}, id = 40
  DataSetCalc(select=[c AS a]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 5000.0 cpu, 0.0 io}, id = 38
    DataSetScan(table=[[t1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 34
  DataSetCalc(select=[c AS a]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 5000.0 cpu, 0.0 io}, id = 39
    DataSetScan(table=[[t2]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 35


SELECT c FROM ((SELECT * FROM t1) INTERSECT (SELECT * FROM t2)) WHERE a > 1

LogicalProject(c=[$2])
  LogicalFilter(condition=[>($0, 1)])
    LogicalIntersect(all=[false])
      LogicalProject(a=[$0], b=[$1], c=[$2])
        LogicalTableScan(table=[[t1]])
      LogicalProject(a=[$0], b=[$1], c=[$2])
        LogicalTableScan(table=[[t2]])

DataSetCalc(select=[c AS a], where=[>(a, 1)]): rowcount = 1.0, cumulative cost = {4001.0 rows, 4007.0 cpu, 48000.0 io}, id = 92
  DataSetIntersect(intersect=[a, b, c]): rowcount = 1.0, cumulative cost = {4000.0 rows, 4000.0 cpu, 48000.0 io}, id = 91
    DataSetScan(table=[[t1]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 89
    DataSetScan(table=[[t2]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 86


/** Sort **/

SELECT * FROM MyTable ORDER BY _1 DESC, _2 DESC

LogicalSort(sort0=[$0], sort1=[$1], dir0=[DESC], dir1=[DESC])
  LogicalProject(_1=[$0], _2=[$1], _3=[$2])
    LogicalTableScan(table=[[MyTable]])

DataSetSort(orderBy=[_1 DESC, _2 DESC]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 2000.0 cpu, 0.0 io}, id = 40
  DataSetScan(table=[[MyTable]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 38


/** Expressions **/

SELECT a, b, CAST(NULL AS INT), CAST(NULL AS VARCHAR) = '' FROM MyTable

LogicalProject(a=[$0], b=[$1], EXPR$2=[null], EXPR$3=[=(null, '')])
  LogicalTableScan(table=[[MyTable]])

DataSetCalc(select=[a, b]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 11000.0 cpu, 0.0 io}, id = 17
  DataSetScan(table=[[MyTable]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 15


SELECT
  CASE 11 WHEN 1 THEN 'a' ELSE 'b' END,
  CASE 2 WHEN 1 THEN 'a' ELSE 'b' END,
  CASE 1 WHEN 1, 2 THEN '1 or 2' WHEN 2 THEN 'not possible' WHEN 3, 2 THEN '3' ELSE 'none of the above' END
FROM MyTable

LogicalProject(EXPR$0=[CASE(=(11, 1), 'a', 'b')], EXPR$1=[CASE(=(2, 1), 'a', 'b')], EXPR$2=[CASE(OR(=(1, 1), =(1, 2)), '1 or 2', =(1, 2), 'not possible', OR(=(1, 3), =(1, 2)), '3', 'none of the above')])
  LogicalTableScan(table=[[MyTable]])

DataSetCalc(select=[CASE(=(11, 1), 'a', 'b') AS a, CASE(=(2, 1), 'a', 'b') AS b]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 26000.0 cpu, 0.0 io}, id = 17
  DataSetScan(table=[[MyTable]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 15


SELECT a, b, c, DATE '1984-07-12', TIME '14:34:24', TIMESTAMP '1984-07-12 14:34:24' FROM MyTable

LogicalProject(a=[$0], b=[$1], c=[$2], EXPR$3=[1984-07-12], EXPR$4=[14:34:24], EXPR$5=[1984-07-12 14:34:24])
  LogicalTableScan(table=[[MyTable]])

DataSetCalc(select=[a, b, c]): rowcount = 1000.0, cumulative cost = {2000.0 rows, 13000.0 cpu, 0.0 io}, id = 17
  DataSetScan(table=[[MyTable]]): rowcount = 1000.0, cumulative cost = {1000.0 rows, 1000.0 cpu, 0.0 io}, id = 15
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章