Skip to content

Commit b924da1

Browse files
DeviousCardiclaude
andcommitted
test: cover a volatile last coalesce argument that would divide by zero
`coalesce(a, y / x + random())` with a non-null `a` and `x = 0` must still take the lazy CASE rewrite and return `a` without evaluating the division. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Y1b55sEL1gA1c3FCMcQCbm
1 parent aa2ab2d commit b924da1

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎datafusion/sqllogictest/test_files/coalesce.slt‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,30 @@ logical_plan
533533
physical_plan
534534
01)ProjectionExec: expr=[CASE WHEN column1@0 IS NOT NULL THEN column1@0 ELSE column2@1 END as c]
535535
02)--DataSourceExec: partitions=1, partition_sizes=[1]
536+
537+
# A volatile *last* argument still takes the lazy CASE rewrite, so it is not
538+
# evaluated when an earlier argument is non-null: `y / x` must not divide by
539+
# zero here.
540+
statement ok
541+
create table volatile_last_t(a int, x int, y int) as values (1, 0, 1), (2, 0, 2);
542+
543+
query TT
544+
explain select coalesce(a, y / x + random()) as c from volatile_last_t;
545+
----
546+
logical_plan
547+
01)Projection: CASE WHEN __common_expr_1 IS NOT NULL THEN __common_expr_1 ELSE CAST(volatile_last_t.y / volatile_last_t.x AS Float64) + random() END AS c
548+
02)--Projection: CAST(volatile_last_t.a AS Float64) AS __common_expr_1, volatile_last_t.x, volatile_last_t.y
549+
03)----TableScan: volatile_last_t projection=[a, x, y]
550+
physical_plan
551+
01)ProjectionExec: expr=[CASE WHEN __common_expr_1@0 IS NOT NULL THEN __common_expr_1@0 ELSE CAST(y@2 / x@1 AS Float64) + random() END as c]
552+
02)--ProjectionExec: expr=[CAST(a@0 AS Float64) as __common_expr_1, x@1 as x, y@2 as y]
553+
03)----DataSourceExec: partitions=1, partition_sizes=[1]
554+
555+
query R rowsort
556+
select coalesce(a, y / x + random()) as c from volatile_last_t;
557+
----
558+
1
559+
2
560+
561+
statement ok
562+
drop table volatile_last_t;

0 commit comments

Comments
 (0)