kosiew commented on code in PR #26031: URL: https://github.com/apache/datafusion/pull/26031#discussion_r4387310211
########## datafusion/sqllogictest/test_files/topk_dynamic_filter_remap.slt: ########## @@ -0,0 +1,88 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +statement ok +SET datafusion.execution.target_partitions = 1; + +statement ok +SET datafusion.execution.parquet.pushdown_filters = true; + +statement ok +COPY ( + SELECT value AS b FROM generate_series(0, 31999) +) TO 'test_files/scratch/topk_dynamic_filter_remap.parquet' +STORED AS PARQUET OPTIONS ('format.max_row_group_size' '500'); + +statement ok +CREATE EXTERNAL TABLE t STORED AS PARQUET +LOCATION 'test_files/scratch/topk_dynamic_filter_remap.parquet'; + +# A computed sort key avoids limit pushdown, so this plan must show TopK's +# DynamicFilter at the Parquet scan. +query TT +EXPLAIN SELECT b FROM t ORDER BY b + 1 LIMIT 3; +---- +logical_plan +01)Sort: t.b + Int64(1) ASC NULLS LAST, fetch=3 +02)--TableScan: t projection=[b] +physical_plan +01)SortExec: TopK(fetch=3), expr=[b@0 + 1 ASC NULLS LAST], preserve_partitioning=[false] +02)--DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/topk_dynamic_filter_remap.parquet]]}, projection=[b], output_ordering=[b@0 ASC NULLS LAST], file_type=parquet, predicate=DynamicFilter [ empty ], dynamic_rg_pruning=eligible + +# A CASE sort key that also references b must still plan TopK dynamic filtering +# at the Parquet scan; the result assertion below alone would pass if filtering +# were disabled. +query TT +EXPLAIN WITH s AS (SELECT b, 31999 - b AS p FROM t) +SELECT p FROM s +ORDER BY CASE WHEN b % 2 = 0 THEN p ELSE p + 1 END, b Review Comment: Non-blocking: could we also EXPLAIN the exact result query below, using `ELSE q` with equal `p`/`q` expressions, and assert TopK plus the Parquet scan's dynamic predicate? The current `ELSE p + 1` query guards a related plan, but planner changes affecting only the equal-arm query could bypass dynamic filtering while these assertions still pass. Please retain the runtime result check. -- 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]
