Skip to content

Commit 96e197e

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 b1c9fa2 commit 96e197e

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
@@ -368,3 +368,52 @@ FROM cse_agg_filter
368368

369369
statement ok
370370
DROP TABLE cse_agg_filter
371+
372+
# A struct-returning function that keeps its place is evaluated one time when a
373+
# common sub-expression is referenced both bare and through a field access.
374+
# The projection shape is https://github.com/apache/datafusion/issues/23655 and
375+
# the filter shape is https://github.com/apache/datafusion/issues/25329.
376+
statement ok
377+
CREATE TABLE cse_keep_in_place(a INT) AS VALUES (1), (2);
378+
379+
# Projection shape: `arrow_field(a)` appears one time in the physical plan.
380+
query TT
381+
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;
382+
----
383+
logical_plan
384+
01)Projection: CASE WHEN __common_expr_1 IS NOT NULL THEN get_field(__common_expr_1, Utf8("name")) END AS c1
385+
02)--Projection: arrow_field(cse_keep_in_place.a) AS __common_expr_1
386+
03)----TableScan: cse_keep_in_place projection=[a]
387+
physical_plan
388+
01)ProjectionExec: expr=[CASE WHEN __common_expr_1@0 IS NOT NULL THEN get_field(__common_expr_1@0, name) END as c1]
389+
02)--ProjectionExec: expr=[arrow_field(a@0) as __common_expr_1]
390+
03)----DataSourceExec: partitions=1, partition_sizes=[1]
391+
392+
query T
393+
SELECT CASE WHEN arrow_field(a) IS NOT NULL THEN get_field(arrow_field(a), 'name') END AS c1 FROM cse_keep_in_place;
394+
----
395+
a
396+
a
397+
398+
# Filter shape: `arrow_field(a)` appears one time in the physical plan.
399+
query TT
400+
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;
401+
----
402+
logical_plan
403+
01)Projection: cse_keep_in_place.a
404+
02)--Filter: CASE WHEN __common_expr_1 IS NOT NULL THEN get_field(__common_expr_1, Utf8("nullable")) IS NULL END
405+
03)----Projection: arrow_field(cse_keep_in_place.a) AS __common_expr_1, cse_keep_in_place.a
406+
04)------TableScan: cse_keep_in_place projection=[a]
407+
physical_plan
408+
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]
409+
02)--ProjectionExec: expr=[arrow_field(a@0) as __common_expr_1, a@0 as a]
410+
03)----DataSourceExec: partitions=1, partition_sizes=[1]
411+
412+
query I
413+
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;
414+
----
415+
1
416+
2
417+
418+
statement ok
419+
DROP TABLE cse_keep_in_place;

0 commit comments

Comments
 (0)