Skip to content

Commit c6d8663

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 d9864f1 commit c6d8663

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
@@ -231,3 +231,52 @@ logical_plan
231231
physical_plan
232232
01)ProjectionExec: expr=[(random() = 0 OR a@0 = 1) AND a@0 = 2 as c1, random() = 0 AND a@0 = 2 OR a@0 = 1 as c2, CASE WHEN random() = 0 THEN a@0 + 3 ELSE a@0 + 3 END as c3, CASE WHEN random() = 0 THEN 0 WHEN a@0 + 4 = 0 THEN a@0 + 4 ELSE 0 END as c4, CASE WHEN random() = 0 THEN 0 WHEN a@0 + 5 = 0 THEN 0 ELSE a@0 + 5 END as c5, CASE WHEN random() = 0 THEN 0 WHEN random() = 0 THEN a@0 + 6 ELSE a@0 + 6 END as c6]
233233
02)--DataSourceExec: partitions=1, partition_sizes=[0]
234+
235+
# A struct-returning function that keeps its place is evaluated one time when a
236+
# common sub-expression is referenced both bare and through a field access.
237+
# The projection shape is https://github.com/apache/datafusion/issues/23655 and
238+
# the filter shape is https://github.com/apache/datafusion/issues/25329.
239+
statement ok
240+
CREATE TABLE cse_keep_in_place(a INT) AS VALUES (1), (2);
241+
242+
# Projection shape: `arrow_field(a)` appears one time in the physical plan.
243+
query TT
244+
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;
245+
----
246+
logical_plan
247+
01)Projection: CASE WHEN __common_expr_1 IS NOT NULL THEN get_field(__common_expr_1, Utf8("name")) END AS c1
248+
02)--Projection: arrow_field(cse_keep_in_place.a) AS __common_expr_1
249+
03)----TableScan: cse_keep_in_place projection=[a]
250+
physical_plan
251+
01)ProjectionExec: expr=[CASE WHEN __common_expr_1@0 IS NOT NULL THEN get_field(__common_expr_1@0, name) END as c1]
252+
02)--ProjectionExec: expr=[arrow_field(a@0) as __common_expr_1]
253+
03)----DataSourceExec: partitions=1, partition_sizes=[1]
254+
255+
query T
256+
SELECT CASE WHEN arrow_field(a) IS NOT NULL THEN get_field(arrow_field(a), 'name') END AS c1 FROM cse_keep_in_place;
257+
----
258+
a
259+
a
260+
261+
# Filter shape: `arrow_field(a)` appears one time in the physical plan.
262+
query TT
263+
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;
264+
----
265+
logical_plan
266+
01)Projection: cse_keep_in_place.a
267+
02)--Filter: CASE WHEN __common_expr_1 IS NOT NULL THEN get_field(__common_expr_1, Utf8("nullable")) IS NULL END
268+
03)----Projection: arrow_field(cse_keep_in_place.a) AS __common_expr_1, cse_keep_in_place.a
269+
04)------TableScan: cse_keep_in_place projection=[a]
270+
physical_plan
271+
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]
272+
02)--ProjectionExec: expr=[arrow_field(a@0) as __common_expr_1, a@0 as a]
273+
03)----DataSourceExec: partitions=1, partition_sizes=[1]
274+
275+
query I
276+
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;
277+
----
278+
1
279+
2
280+
281+
statement ok
282+
DROP TABLE cse_keep_in_place;

0 commit comments

Comments
 (0)