Skip to content

Commit 10268fb

Browse files
adriangbclaude
andcommitted
test: cover a struct-returning function evaluated one time in cse.slt
Add the two end-to-end shapes of the issue: the common sub-expression is referenced bare and through a field access, in a projection and in a filter. Both plans must show `arrow_field(a)` one time. Covers apache#23655 and apache#25329 Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 29513fb commit 10268fb

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

  • datafusion/sqllogictest/test_files

‎datafusion/sqllogictest/test_files/cse.slt‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,52 @@ FROM cse_agg_filter
355355

356356
statement ok
357357
DROP TABLE cse_agg_filter
358+
359+
# A struct-returning function that keeps its place is evaluated one time when a
360+
# common sub-expression is referenced both bare and through a field access.
361+
# The projection shape is https://github.com/apache/datafusion/issues/23655 and
362+
# the filter shape is https://github.com/apache/datafusion/issues/25329.
363+
statement ok
364+
CREATE TABLE cse_keep_in_place(a INT) AS VALUES (1), (2);
365+
366+
# Projection shape: `arrow_field(a)` appears one time in the physical plan.
367+
query TT
368+
EXPLAIN SELECT CASE WHEN arrow_field(a) IS NOT NULL THEN get_field(arrow_field(a), 'name') END AS c1 FROM cse_keep_in_place;
369+
----
370+
logical_plan
371+
01)Projection: CASE WHEN __common_expr_1 IS NOT NULL THEN get_field(__common_expr_1, Utf8("name")) END AS c1
372+
02)--Projection: arrow_field(cse_keep_in_place.a) AS __common_expr_1
373+
03)----TableScan: cse_keep_in_place projection=[a]
374+
physical_plan
375+
01)ProjectionExec: expr=[CASE WHEN __common_expr_1@0 IS NOT NULL THEN get_field(__common_expr_1@0, name) END as c1]
376+
02)--ProjectionExec: expr=[arrow_field(a@0) as __common_expr_1]
377+
03)----DataSourceExec: partitions=1, partition_sizes=[1]
378+
379+
query T
380+
SELECT CASE WHEN arrow_field(a) IS NOT NULL THEN get_field(arrow_field(a), 'name') END AS c1 FROM cse_keep_in_place;
381+
----
382+
a
383+
a
384+
385+
# Filter shape: `arrow_field(a)` appears one time in the physical plan.
386+
query TT
387+
EXPLAIN SELECT a FROM cse_keep_in_place WHERE CASE WHEN arrow_field(a) IS NOT NULL THEN arrow_field(a)['nullable'] IS NULL END;
388+
----
389+
logical_plan
390+
01)Projection: cse_keep_in_place.a
391+
02)--Filter: CASE WHEN __common_expr_1 IS NOT NULL THEN get_field(__common_expr_1, Utf8("nullable")) IS NULL END
392+
03)----Projection: arrow_field(cse_keep_in_place.a) AS __common_expr_1, cse_keep_in_place.a
393+
04)------TableScan: cse_keep_in_place projection=[a]
394+
physical_plan
395+
01)FilterExec: CASE WHEN __common_expr_1@0 IS NOT NULL THEN get_field(__common_expr_1@0, nullable) IS NULL END, projection=[a@1]
396+
02)--ProjectionExec: expr=[arrow_field(a@0) as __common_expr_1, a@0 as a]
397+
03)----DataSourceExec: partitions=1, partition_sizes=[1]
398+
399+
query I
400+
SELECT a FROM cse_keep_in_place WHERE CASE WHEN arrow_field(a) IS NOT NULL THEN arrow_field(a)['nullable'] END ORDER BY a;
401+
----
402+
1
403+
2
404+
405+
statement ok
406+
DROP TABLE cse_keep_in_place;

0 commit comments

Comments
 (0)