alamb commented on code in PR #19962: URL: https://github.com/apache/datafusion/pull/19962#discussion_r2723374327
########## datafusion/core/Cargo.toml: ########## @@ -241,6 +241,11 @@ harness = false name = "parquet_query_sql" required-features = ["parquet"] Review Comment: Is there any reason not to just add the benchmarks to parquet_query_sql? ########## datafusion/sqllogictest/test_files/projection_pushdown.slt: ########## @@ -0,0 +1,1054 @@ +# 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. + +########## +# Tests for projection pushdown behavior with get_field expressions +# +# This file tests the ExtractTrivialProjections optimizer rule and +# physical projection pushdown for: +# - get_field expressions (struct field access like s['foo']) +# - Pushdown through Filter, Sort, and TopK operators +# - Multi-partition scenarios with SortPreservingMergeExec +########## + +##################### +# Section 1: Setup - Single Partition Tests +##################### + +# Set target_partitions = 1 for deterministic plan output +statement ok +SET datafusion.execution.target_partitions = 1; + +# Create parquet file with struct column containing value and label fields +statement ok +COPY ( + SELECT + column1 as id, + column2 as s + FROM VALUES + (1, {value: 100, label: 'alpha'}), + (2, {value: 200, label: 'beta'}), + (3, {value: 150, label: 'gamma'}), + (4, {value: 300, label: 'delta'}), + (5, {value: 250, label: 'epsilon'}) +) TO 'test_files/scratch/projection_pushdown/simple.parquet' +STORED AS PARQUET; + +# Create table for simple struct tests +statement ok +CREATE EXTERNAL TABLE simple_struct STORED AS PARQUET +LOCATION 'test_files/scratch/projection_pushdown/simple.parquet'; + +# Create parquet file with nested struct column +statement ok +COPY ( + SELECT + column1 as id, + column2 as nested + FROM VALUES + (1, {outer: {inner: 10, name: 'one'}, extra: 'x'}), + (2, {outer: {inner: 20, name: 'two'}, extra: 'y'}), + (3, {outer: {inner: 30, name: 'three'}, extra: 'z'}) +) TO 'test_files/scratch/projection_pushdown/nested.parquet' +STORED AS PARQUET; + +# Create table for nested struct tests +statement ok +CREATE EXTERNAL TABLE nested_struct STORED AS PARQUET +LOCATION 'test_files/scratch/projection_pushdown/nested.parquet'; + +# Create parquet file with nullable struct column +statement ok +COPY ( + SELECT + column1 as id, + column2 as s + FROM VALUES + (1, {value: 100, label: 'alpha'}), + (2, NULL), + (3, {value: 150, label: 'gamma'}), + (4, NULL), + (5, {value: 250, label: 'epsilon'}) +) TO 'test_files/scratch/projection_pushdown/nullable.parquet' +STORED AS PARQUET; + +# Create table for nullable struct tests +statement ok +CREATE EXTERNAL TABLE nullable_struct STORED AS PARQUET +LOCATION 'test_files/scratch/projection_pushdown/nullable.parquet'; + + +##################### +# Section 2: Basic get_field Pushdown (Projection above scan) +##################### + +### +# Test 2.1: Simple s['value'] - pushed into DataSourceExec +### + +query TT +EXPLAIN SELECT id, s['value'] FROM simple_struct; +---- +logical_plan +01)Projection: simple_struct.id, get_field(simple_struct.s, Utf8("value")) +02)--TableScan: simple_struct projection=[id, s] +physical_plan DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/projection_pushdown/simple.parquet]]}, projection=[id, get_field(s@1, value) as simple_struct.s[value]], file_type=parquet Review Comment: It is interesting that these expressions have already been pushed down to the datasource -- 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]
