@@ -43,8 +43,7 @@ SELECT *
4343FROM (VALUES (NULL, 0), (1, NULL), (1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (2, 3), (3, 4)) AS t1(k, t)
4444ASOF JOIN (VALUES (1, NULL), (1, 2), (1, 3), (2, 10), (2, 0)) AS t2(k, t)
4545MATCH_CONDITION t2.t < t1.t
46- ON t1.k = t2.k
47- ;
46+ ON t1.k = t2.k;
4847# Not using !ok: this test focuses on plan transformation (see !sub-plan).
4948LogicalProject(K=[$0], T=[$1], K0=[$2], T0=[$3])
5049 LogicalAsofJoin(condition=[=($0, $2)], joinType=[asof], matchCondition=[<($3, $1)])
@@ -84,9 +83,9 @@ LogicalProject(T=[CASE(<(CAST(CASE(>($1, 'abc'), $1, null:VARCHAR(20))):DOUBLE,
8483# function has already been expanded (checkUnchanged).
8584
8685select COUNT(*) over (
87- ORDER BY empno
88- ROWS BETWEEN 5 + 5 PRECEDING AND 1 PRECEDING) AS w_count from emp
89- ;
86+ ORDER BY empno
87+ ROWS BETWEEN 5 + 5 PRECEDING AND 1 PRECEDING) AS w_count
88+ from emp ;
9089# Not using !ok: this test focuses on plan transformation (see !sub-plan).
9190LogicalProject(W_COUNT=[$1])
9291 LogicalWindow(window#0=[window(order by [0] rows between $1 PRECEDING and $2 PRECEDING aggs [COUNT()])], constants=[[10, 1]])
@@ -283,33 +282,6 @@ LogicalProject(EXPR$0=[1], A=[$1])
283282 LogicalValues(tuples=[[{ 0 }]])
284283!sub-plan "NONE, PROJECT_REDUCE_EXPRESSIONS"
285284
286- # testReduceCastAndConsts -------------------------------------------------------
287- # Tests that constant expressions inside a cast can be reduced.
288-
289- select * from emp
290- where cast((empno + (10/2)) as int) = 13;
291- # Not using !ok: this test focuses on plan transformation (see !sub-plan).
292- LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
293- LogicalFilter(condition=[=(CAST(+($0, /(10, 2))):INTEGER NOT NULL, 13)])
294- LogicalTableScan(table=[[CATALOG, SALES, EMP]])
295- !sub-plan "NONE"
296- LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
297- LogicalFilter(condition=[=(+($0, 5), 13)])
298- LogicalTableScan(table=[[CATALOG, SALES, EMP]])
299- !sub-plan "NONE, FILTER_REDUCE_EXPRESSIONS"
300-
301- # testReduceCastTimeUnchanged -------------------------------------------------------
302- # Tests that a cast from a TIME to a TIMESTAMP is not reduced (depends on current date).
303-
304- select cast(time '12:34:56' as timestamp) from emp as e;
305- # Not using !ok: this test focuses on plan transformation (see !sub-plan).
306- LogicalProject(EXPR$0=[CAST(12:34:56):TIMESTAMP(0) NOT NULL])
307- LogicalTableScan(table=[[CATALOG, SALES, EMP]])
308- !sub-plan "NONE"
309- LogicalProject(EXPR$0=[CAST(12:34:56):TIMESTAMP(0) NOT NULL])
310- LogicalTableScan(table=[[CATALOG, SALES, EMP]])
311- !sub-plan "NONE, PROJECT_REDUCE_EXPRESSIONS, FILTER_REDUCE_EXPRESSIONS, JOIN_REDUCE_EXPRESSIONS"
312-
313285# testReduceCase -------------------------------------------------------
314286# PROJECT_REDUCE_EXPRESSIONS reduces a CASE expression with a false condition
315287# to the else branch, unifying numeric types.
@@ -342,6 +314,21 @@ LogicalProject(QX=[CAST(CASE(=($0, 1), 1, 2)):INTEGER])
342314 LogicalTableScan(table=[[CATALOG, SALES, EMP]])
343315!sub-plan "relBuilderSimplify=false, NONE, FILTER_REDUCE_EXPRESSIONS, PROJECT_REDUCE_EXPRESSIONS"
344316
317+ # testReduceCastAndConsts -------------------------------------------------------
318+ # Tests that constant expressions inside a cast can be reduced.
319+
320+ select * from emp
321+ where cast((empno + (10/2)) as int) = 13;
322+ # Not using !ok: this test focuses on plan transformation (see !sub-plan).
323+ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
324+ LogicalFilter(condition=[=(CAST(+($0, /(10, 2))):INTEGER NOT NULL, 13)])
325+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
326+ !sub-plan "NONE"
327+ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
328+ LogicalFilter(condition=[=(+($0, 5), 13)])
329+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
330+ !sub-plan "NONE, FILTER_REDUCE_EXPRESSIONS"
331+
345332# testReduceCasts -------------------------------------------------------
346333# PROJECT_REDUCE_EXPRESSIONS, JOIN_REDUCE_EXPRESSIONS, and FILTER_REDUCE_EXPRESSIONS
347334# remove redundant casts (e.g., CAST(integer AS integer) becomes the column itself).
@@ -371,6 +358,18 @@ LogicalProject(EXPR$0=[CAST($1):VARCHAR(128) NOT NULL], EXPR$1=[$2])
371358 LogicalTableScan(table=[[CATALOG, SALES, EMP]])
372359!sub-plan "relBuilderSimplify=false, NONE, PROJECT_REDUCE_EXPRESSIONS, FILTER_REDUCE_EXPRESSIONS, JOIN_REDUCE_EXPRESSIONS"
373360
361+ # testReduceCastTimeUnchanged -------------------------------------------------------
362+ # Tests that a cast from a TIME to a TIMESTAMP is not reduced (depends on current date).
363+
364+ select cast(time '12:34:56' as timestamp) from emp as e;
365+ # Not using !ok: this test focuses on plan transformation (see !sub-plan).
366+ LogicalProject(EXPR$0=[CAST(12:34:56):TIMESTAMP(0) NOT NULL])
367+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
368+ !sub-plan "NONE"
369+ LogicalProject(EXPR$0=[CAST(12:34:56):TIMESTAMP(0) NOT NULL])
370+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
371+ !sub-plan "NONE, PROJECT_REDUCE_EXPRESSIONS, FILTER_REDUCE_EXPRESSIONS, JOIN_REDUCE_EXPRESSIONS"
372+
374373# testReduceCompositeInSubQuery -------------------------------------------------------
375374# [CALCITE-6887] FILTER_REDUCE_EXPRESSIONS reduces a constant expression in an
376375# OR condition that contains a composite IN subquery.
0 commit comments