kosiew commented on code in PR #25999:
URL: https://github.com/apache/datafusion/pull/25999#discussion_r4345632941
##########
datafusion/sqllogictest/test_files/topk.slt:
##########
@@ -396,3 +396,98 @@ set datafusion.explain.physical_plan_only = false
statement ok
set datafusion.execution.batch_size = 8192
+
+#####################################
+## TopK with nested sort keys containing NULL elements
+## The dynamic filter must not drop rows that sort before the current
+## threshold (nested comparisons do not follow the sort's NULL ordering).
+#####################################
+
+statement ok
+set datafusion.execution.target_partitions = 1;
+
+statement ok
+create table nested_list (l int[]) as values (make_array(1, NULL));
+
+statement ok
+insert into nested_list values (make_array(1, 2));
+
+query ?
+select l from nested_list order by l;
+----
+[1, 2]
+[1, NULL]
+
+query ?
+select l from nested_list order by l limit 1;
+----
+[1, 2]
+
+query ?
+select l from nested_list order by l nulls first limit 1;
+----
+[1, NULL]
+
+statement ok
+create table nested_list_desc (l int[]) as values (make_array(1, 2));
+
+statement ok
+insert into nested_list_desc values (make_array(1, NULL));
+
+query ?
+select l from nested_list_desc order by l desc limit 1;
+----
+[1, NULL]
+
+statement ok
+create table nested_struct as
+select named_struct('a', 1, 'b', NULL::int) x
+union all
+select named_struct('a', 1, 'b', 2);
+
+query ?
+select x from nested_struct order by x limit 1;
+----
+{a: 1, b: 2}
+
+# Nested key after a flat key: rows tied on the flat prefix must be kept
+statement ok
+create table nested_second (a int, l int[]) as values (1, make_array(1, NULL));
+
+statement ok
+insert into nested_second values (2, make_array(0)), (1, make_array(1, 2));
+
+query I?
+select a, l from nested_second order by a, l limit 1;
Review Comment:
Optional: could we extend this test with explicit NULLS FIRST/LAST and a
NULL flat-prefix threshold, followed by a better nested value tied on that NULL
prefix? The current non-NULL `a` values do not exercise the retained null-aware
equality branch, which must admit NULL-prefix rows under both orderings. Please
compare LIMIT results against the full ordering.
##########
datafusion/sqllogictest/test_files/topk.slt:
##########
@@ -396,3 +396,98 @@ set datafusion.explain.physical_plan_only = false
statement ok
set datafusion.execution.batch_size = 8192
+
+#####################################
+## TopK with nested sort keys containing NULL elements
+## The dynamic filter must not drop rows that sort before the current
+## threshold (nested comparisons do not follow the sort's NULL ordering).
+#####################################
+
+statement ok
+set datafusion.execution.target_partitions = 1;
+
+statement ok
+create table nested_list (l int[]) as values (make_array(1, NULL));
+
+statement ok
+insert into nested_list values (make_array(1, 2));
+
+query ?
+select l from nested_list order by l;
+----
+[1, 2]
+[1, NULL]
+
+query ?
+select l from nested_list order by l limit 1;
Review Comment:
Lower-priority follow-up: could we add a LIMIT 2 test with ASC NULLS LAST,
initially filling the heap with `[1, NULL]` and `[1, 9]`, then introducing `[1,
8]` and `[1, 7]` in successive batches? The boundary should progress through
`[1, NULL]`, `[1, 9]`, and `[1, 8]`, producing `[1, 7]` and `[1, 8]`. Please
ensure execution preserves the batch boundaries, since separate inserts alone
do not guarantee repeated updates.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]