jayzhan211 commented on code in PR #26718: URL: https://github.com/apache/datafusion/pull/26718#discussion_r4499154813
########## datafusion/sqllogictest/test_files/topk.slt: ########## @@ -811,3 +811,104 @@ drop table nested_progress; statement ok set datafusion.execution.target_partitions = 4; + +# The TopK dynamic filter must keep `-0.0` rows when the threshold is `0.0` +# (and vice versa): the heap orders `-0.0` before `0.0`, but comparisons treat +# them as equal. https://github.com/apache/datafusion/issues/26618 +# +# The expected rows assume -0.0 sorts before 0.0 (the current order). +# They will change when -0.0 and 0.0 are treated as equal when sorting, +# see https://github.com/apache/datafusion/issues/26138 +statement ok +set datafusion.execution.target_partitions = 1; + +statement ok +create table float_zero (x double, y int) as values (0.0, 1), (-0.0, 7); + +statement ok +insert into float_zero values (-0.0, 5); + +# `-0.0` is displayed as `0`; `y` tells the rows apart. +query RI +select x, y from float_zero order by x, y; +---- +0 5 +0 7 +0 1 + +query RI +select x, y from float_zero order by x, y limit 2; +---- +0 5 +0 7 + +statement ok +create table float_zero_desc (x double, y int) as values (-0.0, 1), (0.0, 7); + +statement ok +insert into float_zero_desc values (0.0, 5); + +query RI +select x, y from float_zero_desc order by x desc, y limit 2; +---- +0 5 +0 7 + +statement ok +create table float_zero_ree as select arrow_cast(column1, 'RunEndEncoded("run_ends": non-null Int32, "values": Float64)') x, column2 y from (values (0.0, 1), (-0.0, 7)); + +statement ok +insert into float_zero_ree select arrow_cast(-0.0, 'RunEndEncoded("run_ends": non-null Int32, "values": Float64)'), 5; + +query I +select y from float_zero_ree order by x, y limit 2; +---- +5 +7 + +# The filter also prunes files and row groups in the scan. Review Comment: Optional: two more shapes fail on main and pass with this PR but have no test yet, a zero as a later sort key and the single-key query from the issue. ```suggestion # The zero can be a later key, or the only key. statement ok create table float_zero_second_key (a int, x double, y int) as values (1, 0.0, 1), (1, -0.0, 7); statement ok insert into float_zero_second_key values (1, -0.0, 5); query I select y from float_zero_second_key order by a, x, y limit 2; ---- 5 7 statement ok drop table float_zero_second_key; statement ok create table float_zero_single_key (x double, y int) as values (0.0, 1); statement ok insert into float_zero_single_key values (-0.0, 2); query I select y from float_zero_single_key order by x limit 1; ---- 2 statement ok drop table float_zero_single_key; # The filter also prunes files and row groups in the scan. ``` -- 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]
