Apache DataFusion SQL Query Engine
Upgrade to arrow 56.1.0 (#17275)
Andrew Lamb980c948d8a63
diff --git a/Cargo.lock b/Cargo.lockindex efdd102b9c..80425a87af 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -234,9 +234,9 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"[[package]]name = "arrow"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "fd798aea3553913a5986813e9c6ad31a2d2b04e931fe8ea4a37155eb541cebb5"+checksum = "c26b57282a08ae92f727497805122fec964c6245cfa0e13f0e75452eaf3bc41f"dependencies = ["arrow-arith","arrow-array",@@ -258,9 +258,9 @@ dependencies = [[[package]]name = "arrow-arith"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "508dafb53e5804a238cab7fd97a59ddcbfab20cc4d9814b1ab5465b9fa147f2e"+checksum = "cebf38ca279120ff522f4954b81a39527425b6e9f615e6b72842f4de1ffe02b8"dependencies = ["arrow-array","arrow-buffer",@@ -272,9 +272,9 @@ dependencies = [[[package]]name = "arrow-array"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e2730bc045d62bb2e53ef8395b7d4242f5c8102f41ceac15e8395b9ac3d08461"+checksum = "744109142cdf8e7b02795e240e20756c2a782ac9180d4992802954a8f871c0de"dependencies = ["ahash 0.8.12","arrow-buffer",@@ -289,9 +289,9 @@ dependencies = [[[package]]name = "arrow-buffer"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "54295b93beb702ee9a6f6fbced08ad7f4d76ec1c297952d4b83cf68755421d1d"+checksum = "601bb103c4c374bcd1f62c66bcea67b42a2ee91a690486c37d4c180236f11ccc"dependencies = ["bytes","half",@@ -300,9 +300,9 @@ dependencies = [[[package]]name = "arrow-cast"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "67e8bcb7dc971d779a7280593a1bf0c2743533b8028909073e804552e85e75b5"+checksum = "eed61d9d73eda8df9e3014843def37af3050b5080a9acbe108f045a316d5a0be"dependencies = ["arrow-array","arrow-buffer",@@ -321,9 +321,9 @@ dependencies = [[[package]]name = "arrow-csv"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "673fd2b5fb57a1754fdbfac425efd7cf54c947ac9950c1cce86b14e248f1c458"+checksum = "fa95b96ce0c06b4d33ac958370db8c0d31e88e54f9d6e08b0353d18374d9f991"dependencies = ["arrow-array","arrow-cast",@@ -336,9 +336,9 @@ dependencies = [[[package]]name = "arrow-data"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "97c22fe3da840039c69e9f61f81e78092ea36d57037b4900151f063615a2f6b4"+checksum = "43407f2c6ba2367f64d85d4603d6fb9c4b92ed79d2ffd21021b37efa96523e12"dependencies = ["arrow-buffer","arrow-schema",@@ -348,9 +348,9 @@ dependencies = [[[package]]name = "arrow-flight"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "6808d235786b721e49e228c44dd94242f2e8b46b7e95b233b0733c46e758bfee"+checksum = "d7c66c5e4a7aedc2bfebffeabc2116d76adb22e08d230b968b995da97f8b11ca"dependencies = ["arrow-arith","arrow-array",@@ -375,14 +375,15 @@ dependencies = [[[package]]name = "arrow-ipc"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "778de14c5a69aedb27359e3dd06dd5f9c481d5f6ee9fbae912dba332fd64636b"+checksum = "e4b0487c4d2ad121cbc42c4db204f1509f8618e589bc77e635e9c40b502e3b90"dependencies = ["arrow-array","arrow-buffer","arrow-data","arrow-schema",+ "arrow-select","flatbuffers","lz4_flex","zstd",@@ -390,9 +391,9 @@ dependencies = [[[package]]name = "arrow-json"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "3860db334fe7b19fcf81f6b56f8d9d95053f3839ffe443d56b5436f7a29a1794"+checksum = "26d747573390905905a2dc4c5a61a96163fe2750457f90a04ee2a88680758c79"dependencies = ["arrow-array","arrow-buffer",@@ -412,9 +413,9 @@ dependencies = [[[package]]name = "arrow-ord"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "425fa0b42a39d3ff55160832e7c25553e7f012c3f187def3d70313e7a29ba5d9"+checksum = "c142a147dceb59d057bad82400f1693847c80dca870d008bf7b91caf902810ae"dependencies = ["arrow-array","arrow-buffer",@@ -425,9 +426,9 @@ dependencies = [[[package]]name = "arrow-pyarrow"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "d944d8ae9b77230124e6570865b570416c33a5809f32c4136c679bbe774e45c9"+checksum = "5b9038de599df1b81f63b42220e2b6cd6fd4f09af333858cd320db9bef5ac757"dependencies = ["arrow-array","arrow-data",@@ -437,9 +438,9 @@ dependencies = [[[package]]name = "arrow-row"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "df9c9423c9e71abd1b08a7f788fcd203ba2698ac8e72a1f236f1faa1a06a7414"+checksum = "dac6620667fccdab4204689ca173bd84a15de6bb6b756c3a8764d4d7d0c2fc04"dependencies = ["arrow-array","arrow-buffer",@@ -450,9 +451,9 @@ dependencies = [[[package]]name = "arrow-schema"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "85fa1babc4a45fdc64a92175ef51ff00eba5ebbc0007962fecf8022ac1c6ce28"+checksum = "dfa93af9ff2bb80de539e6eb2c1c8764abd0f4b73ffb0d7c82bf1f9868785e66"dependencies = ["bitflags 2.9.1","serde",@@ -461,9 +462,9 @@ dependencies = [[[package]]name = "arrow-select"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "d8854d15f1cf5005b4b358abeb60adea17091ff5bdd094dca5d3f73787d81170"+checksum = "be8b2e0052cd20d36d64f32640b68a5ab54d805d24a473baee5d52017c85536c"dependencies = ["ahash 0.8.12","arrow-array",@@ -475,9 +476,9 @@ dependencies = [[[package]]name = "arrow-string"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "2c477e8b89e1213d5927a2a84a72c384a9bf4dd0dbf15f9fd66d821aafd9e95e"+checksum = "c2155e26e17f053c8975c546fc70cf19c00542f9abf43c23a88a46ef7204204f"dependencies = ["arrow-array","arrow-buffer",@@ -4449,9 +4450,9 @@ dependencies = [[[package]]name = "parquet"-version = "56.0.0"+version = "56.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "c7288a07ed5d25939a90f9cb1ca5afa6855faa08ec7700613511ae64bdb0620c"+checksum = "89b56b41d1bd36aae415e42f91cae70ee75cf6cba74416b14dce3e958d5990ec"dependencies = ["ahash 0.8.12","arrow-array",diff --git a/Cargo.toml b/Cargo.tomlindex 92392a1991..720ea25f32 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -90,19 +90,19 @@ ahash = { version = "0.8", default-features = false, features = ["runtime-rng",] }apache-avro = { version = "0.20", default-features = false }-arrow = { version = "56.0.0", features = [+arrow = { version = "56.1.0", features = ["prettyprint","chrono-tz",] }-arrow-buffer = { version = "56.0.0", default-features = false }-arrow-flight = { version = "56.0.0", features = [+arrow-buffer = { version = "56.1.0", default-features = false }+arrow-flight = { version = "56.1.0", features = ["flight-sql-experimental",] }-arrow-ipc = { version = "56.0.0", default-features = false, features = [+arrow-ipc = { version = "56.1.0", default-features = false, features = ["lz4",] }-arrow-ord = { version = "56.0.0", default-features = false }-arrow-schema = { version = "56.0.0", default-features = false }+arrow-ord = { version = "56.1.0", default-features = false }+arrow-schema = { version = "56.1.0", default-features = false }async-trait = "0.1.89"bigdecimal = "0.4.8"bytes = "1.10"@@ -157,7 +157,7 @@ itertools = "0.14"log = "^0.4"object_store = { version = "0.12.3", default-features = false }parking_lot = "0.12"-parquet = { version = "56.0.0", default-features = false, features = [+parquet = { version = "56.1.0", default-features = false, features = ["arrow","async","object_store",diff --git a/datafusion-cli/src/main.rs b/datafusion-cli/src/main.rsindex ab1726f226..a6b818c109 100644--- a/datafusion-cli/src/main.rs+++ b/datafusion-cli/src/main.rs@@ -571,15 +571,15 @@ mod tests {let df = ctx.sql(sql).await?;let rbs = df.collect().await?;- assert_snapshot!(batches_to_string(&rbs),@r#"+ assert_snapshot!(batches_to_string(&rbs),@r"+-----------------------------------+-----------------+---------------------+------+------------------+| filename | file_size_bytes | metadata_size_bytes | hits | extra |+-----------------------------------+-----------------+---------------------+------+------------------+| alltypes_plain.parquet | 1851 | 10181 | 2 | page_index=false |- | alltypes_tiny_pages.parquet | 454233 | 881634 | 2 | page_index=true |+ | alltypes_tiny_pages.parquet | 454233 | 881418 | 2 | page_index=true || lz4_raw_compressed_larger.parquet | 380836 | 2939 | 2 | page_index=false |+-----------------------------------+-----------------+---------------------+------+------------------+- "#);+ ");// increase the number of hitsctx.sql("select * from alltypes_plain")@@ -602,15 +602,15 @@ mod tests {let df = ctx.sql(sql).await?;let rbs = df.collect().await?;- assert_snapshot!(batches_to_string(&rbs),@r#"+ assert_snapshot!(batches_to_string(&rbs),@r"+-----------------------------------+-----------------+---------------------+------+------------------+| filename | file_size_bytes | metadata_size_bytes | hits | extra |+-----------------------------------+-----------------+---------------------+------+------------------+| alltypes_plain.parquet | 1851 | 10181 | 5 | page_index=false |- | alltypes_tiny_pages.parquet | 454233 | 881634 | 2 | page_index=true |+ | alltypes_tiny_pages.parquet | 454233 | 881418 | 2 | page_index=true || lz4_raw_compressed_larger.parquet | 380836 | 2939 | 3 | page_index=false |+-----------------------------------+-----------------+---------------------+------+------------------+- "#);+ ");Ok(())}diff --git a/datafusion/common/src/config.rs b/datafusion/common/src/config.rsindex 68968e7296..adfb1a6efd 100644--- a/datafusion/common/src/config.rs+++ b/datafusion/common/src/config.rs@@ -566,6 +566,14 @@ config_namespace! {/// (reading) Use any available bloom filters when reading parquet filespub bloom_filter_on_read: bool, default = true+ /// (reading) The maximum predicate cache size, in bytes. When+ /// `pushdown_filters` is enabled, sets the maximum memory used to cache+ /// the results of predicate evaluation between filter evaluation and+ /// output generation. Decreasing this value will reduce memory usage,+ /// but may increase IO and CPU usage. None means use the default+ /// parquet reader setting. 0 means no caching.+ pub max_predicate_cache_size: Option<usize>, default = None+// The following options affect writing to parquet files// and map to parquet::file::properties::WriterPropertiesdiff --git a/datafusion/common/src/file_options/parquet_writer.rs b/datafusion/common/src/file_options/parquet_writer.rsindex a48700a9ee..3977f2b489 100644--- a/datafusion/common/src/file_options/parquet_writer.rs+++ b/datafusion/common/src/file_options/parquet_writer.rs@@ -208,6 +208,7 @@ impl ParquetOptions {binary_as_string: _, // not used for writer propscoerce_int96: _, // not used for writer propsskip_arrow_metadata: _,+ max_predicate_cache_size: _,} = self;let mut builder = WriterProperties::builder()@@ -400,6 +401,10 @@ pub(crate) fn parse_statistics_string(str_setting: &str) -> Result<EnabledStatis#[cfg(feature = "parquet")]#[cfg(test)]mod tests {+ use super::*;+ use crate::config::{ParquetColumnOptions, ParquetEncryptionOptions, ParquetOptions};+ #[cfg(feature = "parquet_encryption")]+ use crate::encryption::map_encryption_to_config_encryption;use parquet::{basic::Compression,file::properties::{@@ -409,11 +414,6 @@ mod tests {};use std::collections::HashMap;- use super::*;- use crate::config::{ParquetColumnOptions, ParquetEncryptionOptions, ParquetOptions};- #[cfg(feature = "parquet_encryption")]- use crate::encryption::map_encryption_to_config_encryption;-const COL_NAME: &str = "configured";/// Take the column defaults provided in [`ParquetOptions`], and generate a non-default col config.@@ -475,6 +475,7 @@ mod tests {binary_as_string: defaults.binary_as_string,skip_arrow_metadata: defaults.skip_arrow_metadata,coerce_int96: None,+ max_predicate_cache_size: defaults.max_predicate_cache_size,}}@@ -581,6 +582,8 @@ mod tests {maximum_buffered_record_batches_per_stream: global_options_defaults.maximum_buffered_record_batches_per_stream,bloom_filter_on_read: global_options_defaults.bloom_filter_on_read,+ max_predicate_cache_size: global_options_defaults+ .max_predicate_cache_size,schema_force_view_types: global_options_defaults.schema_force_view_types,binary_as_string: global_options_defaults.binary_as_string,skip_arrow_metadata: global_options_defaults.skip_arrow_metadata,diff --git a/datafusion/core/tests/parquet/filter_pushdown.rs b/datafusion/core/tests/parquet/filter_pushdown.rsindex b8d570916c..b769fec7d3 100644--- a/datafusion/core/tests/parquet/filter_pushdown.rs+++ b/datafusion/core/tests/parquet/filter_pushdown.rs@@ -26,8 +26,6 @@//! select * from data limit 10;//! ```-use std::path::Path;-use arrow::compute::concat_batches;use arrow::record_batch::RecordBatch;use datafusion::physical_plan::collect;@@ -37,7 +35,10 @@ use datafusion::prelude::{};use datafusion::test_util::parquet::{ParquetScanOptions, TestParquetFile};use datafusion_expr::utils::{conjunction, disjunction, split_conjunction};+use std::path::Path;+use datafusion_common::test_util::parquet_test_data;+use datafusion_execution::config::SessionConfig;use itertools::Itertools;use parquet::file::properties::WriterProperties;use tempfile::TempDir;@@ -601,3 +602,99 @@ fn get_value(metrics: &MetricsSet, metric_name: &str) -> usize {}}}++#[tokio::test]+async fn predicate_cache_default() -> datafusion_common::Result<()> {+ let ctx = SessionContext::new();+ // The cache is on by default, but not used unless filter pushdown is enabled+ PredicateCacheTest {+ expected_inner_records: 0,+ expected_records: 0,+ }+ .run(&ctx)+ .await+}++#[tokio::test]+async fn predicate_cache_pushdown_default() -> datafusion_common::Result<()> {+ let mut config = SessionConfig::new();+ config.options_mut().execution.parquet.pushdown_filters = true;+ let ctx = SessionContext::new_with_config(config);+ // The cache is on by default, and used when filter pushdown is enabled+ PredicateCacheTest {+ expected_inner_records: 8,+ expected_records: 4,+ }+ .run(&ctx)+ .await+}++#[tokio::test]+async fn predicate_cache_pushdown_disable() -> datafusion_common::Result<()> {+ // Can disable the cache even with filter pushdown by setting the size to 0. In this case we+ // expect the inner records are reported but no records are read from the cache+ let mut config = SessionConfig::new();+ config.options_mut().execution.parquet.pushdown_filters = true;+ config+ .options_mut()+ .execution+ .parquet+ .max_predicate_cache_size = Some(0);+ let ctx = SessionContext::new_with_config(config);+ PredicateCacheTest {+ // file has 8 rows, which need to be read twice, one for filter, one for+ // final output+ expected_inner_records: 16,+ // Expect this to 0 records read as the cache is disabled. However, it is+ // non zero due to https://github.com/apache/arrow-rs/issues/8307+ expected_records: 3,+ }+ .run(&ctx)+ .await+}++/// Runs the query "SELECT * FROM alltypes_plain WHERE double_col != 0.0"+/// with a given SessionContext and asserts that the predicate cache metrics+/// are as expected+#[derive(Debug)]+struct PredicateCacheTest {+ /// Expected records read from the underlying reader (to evaluate filters)+ /// -- this is the total number of records in the file+ expected_inner_records: usize,+ /// Expected records to be read from the cache (after filtering)+ expected_records: usize,+}++impl PredicateCacheTest {+ async fn run(self, ctx: &SessionContext) -> datafusion_common::Result<()> {+ let Self {+ expected_inner_records,+ expected_records,+ } = self;+ // Create a dataframe that scans the "alltypes_plain.parquet" file with+ // a filter on `double_col != 0.0`+ let path = parquet_test_data() + "/alltypes_plain.parquet";+ let exec = ctx+ .read_parquet(path, ParquetReadOptions::default())+ .await?+ .filter(col("double_col").not_eq(lit(0.0)))?+ .create_physical_plan()+ .await?;++ // run the plan to completion+ let _ = collect(exec.clone(), ctx.task_ctx()).await?; // run plan+ let metrics =+ TestParquetFile::parquet_metrics(&exec).expect("found parquet metrics");++ // verify the predicate cache metrics+ assert_eq!(+ get_value(&metrics, "predicate_cache_inner_records"),+ expected_inner_records+ );+ assert_eq!(+ get_value(&metrics, "predicate_cache_records"),+ expected_records+ );+ Ok(())+ }+}diff --git a/datafusion/datasource-parquet/src/metadata.rs b/datafusion/datasource-parquet/src/metadata.rsindex 81d5511d69..4de68793ce 100644--- a/datafusion/datasource-parquet/src/metadata.rs+++ b/datafusion/datasource-parquet/src/metadata.rs@@ -39,7 +39,9 @@ use object_store::path::Path;use object_store::{ObjectMeta, ObjectStore};use parquet::arrow::arrow_reader::statistics::StatisticsConverter;use parquet::arrow::parquet_to_arrow_schema;-use parquet::file::metadata::{ParquetMetaData, ParquetMetaDataReader, RowGroupMetaData};+use parquet::file::metadata::{+ PageIndexPolicy, ParquetMetaData, ParquetMetaDataReader, RowGroupMetaData,+};use std::any::Any;use std::collections::HashMap;use std::sync::Arc;@@ -148,7 +150,7 @@ impl<'a> DFParquetMetadata<'a> {if cache_metadata && file_metadata_cache.is_some() {// Need to retrieve the entire metadata for the caching to be effective.- reader = reader.with_page_indexes(true);+ reader = reader.with_page_index_policy(PageIndexPolicy::Optional);}let metadata = Arc::new(diff --git a/datafusion/datasource-parquet/src/metrics.rs b/datafusion/datasource-parquet/src/metrics.rsindex 574fe2a040..d75a979d4c 100644--- a/datafusion/datasource-parquet/src/metrics.rs+++ b/datafusion/datasource-parquet/src/metrics.rs@@ -72,6 +72,13 @@ pub struct ParquetFileMetrics {pub page_index_eval_time: Time,/// Total time spent reading and parsing metadata from the footerpub metadata_load_time: Time,+ /// Predicate Cache: number of records read directly from the inner reader.+ /// This is the number of rows decoded while evaluating predicates+ pub predicate_cache_inner_records: Count,+ /// Predicate Cache: number of records read from the cache. This is the+ /// number of rows that were stored in the cache after evaluating predicates+ /// reused for the output.+ pub predicate_cache_records: Count,}impl ParquetFileMetrics {@@ -140,6 +147,14 @@ impl ParquetFileMetrics {let files_ranges_pruned_statistics = MetricBuilder::new(metrics).counter("files_ranges_pruned_statistics", partition);+ let predicate_cache_inner_records = MetricBuilder::new(metrics)+ .with_new_label("filename", filename.to_string())+ .counter("predicate_cache_inner_records", partition);++ let predicate_cache_records = MetricBuilder::new(metrics)+ .with_new_label("filename", filename.to_string())+ .counter("predicate_cache_records", partition);+Self {files_ranges_pruned_statistics,predicate_evaluation_errors,@@ -157,6 +172,8 @@ impl ParquetFileMetrics {bloom_filter_eval_time,page_index_eval_time,metadata_load_time,+ predicate_cache_inner_records,+ predicate_cache_records,}}}diff --git a/datafusion/datasource-parquet/src/opener.rs b/datafusion/datasource-parquet/src/opener.rsindex bd9406588c..aed7293831 100644--- a/datafusion/datasource-parquet/src/opener.rs+++ b/datafusion/datasource-parquet/src/opener.rs@@ -51,10 +51,11 @@ use datafusion_execution::parquet_encryption::EncryptionFactory;use futures::{ready, Stream, StreamExt, TryStreamExt};use itertools::Itertools;use log::debug;+use parquet::arrow::arrow_reader::metrics::ArrowReaderMetrics;use parquet::arrow::arrow_reader::{ArrowReaderMetadata, ArrowReaderOptions};use parquet::arrow::async_reader::AsyncFileReader;use parquet::arrow::{ParquetRecordBatchStreamBuilder, ProjectionMask};-use parquet::file::metadata::ParquetMetaDataReader;+use parquet::file::metadata::{PageIndexPolicy, ParquetMetaDataReader};/// Implements [`FileOpener`] for a parquet filepub(super) struct ParquetOpener {@@ -106,6 +107,9 @@ pub(super) struct ParquetOpener {#[cfg(feature = "parquet_encryption")]pub encryption_factory:Option<(Arc<dyn EncryptionFactory>, EncryptionFactoryOptions)>,+ /// Maximum size of the predicate cache, in bytes. If none, uses+ /// the arrow-rs default.+ pub max_predicate_cache_size: Option<usize>,}impl FileOpener for ParquetOpener {@@ -154,6 +158,7 @@ impl FileOpener for ParquetOpener {let enable_page_index = self.enable_page_index;#[cfg(feature = "parquet_encryption")]let encryption_context = self.get_encryption_context();+ let max_predicate_cache_size = self.max_predicate_cache_size;Ok(Box::pin(async move {#[cfg(feature = "parquet_encryption")]@@ -404,21 +409,42 @@ impl FileOpener for ParquetOpener {builder = builder.with_limit(limit)}+ if let Some(max_predicate_cache_size) = max_predicate_cache_size {+ builder = builder.with_max_predicate_cache_size(max_predicate_cache_size);+ }++ // metrics from the arrow reader itself+ let arrow_reader_metrics = ArrowReaderMetrics::enabled();+let stream = builder.with_projection(mask).with_batch_size(batch_size).with_row_groups(row_group_indexes)+ .with_metrics(arrow_reader_metrics.clone()).build()?;- let stream = stream- .map_err(DataFusionError::from)- .map(move |b| b.and_then(|b| schema_mapping.map_batch(b)));+ let files_ranges_pruned_statistics =+ file_metrics.files_ranges_pruned_statistics.clone();+ let predicate_cache_inner_records =+ file_metrics.predicate_cache_inner_records.clone();+ let predicate_cache_records = file_metrics.predicate_cache_records.clone();++ let stream = stream.map_err(DataFusionError::from).map(move |b| {+ b.and_then(|b| {+ copy_arrow_reader_metrics(+ &arrow_reader_metrics,+ &predicate_cache_inner_records,+ &predicate_cache_records,+ );+ schema_mapping.map_batch(b)+ })+ });if let Some(file_pruner) = file_pruner {Ok(EarlyStoppingStream::new(stream,file_pruner,- file_metrics.files_ranges_pruned_statistics.clone(),+ files_ranges_pruned_statistics,).boxed())} else {@@ -428,6 +454,22 @@ impl FileOpener for ParquetOpener {}}+/// Copies metrics from ArrowReaderMetrics (the metrics collected by the+/// arrow-rs parquet reader) to the parquet file metrics for DataFusion+fn copy_arrow_reader_metrics(+ arrow_reader_metrics: &ArrowReaderMetrics,+ predicate_cache_inner_records: &Count,+ predicate_cache_records: &Count,+) {+ if let Some(v) = arrow_reader_metrics.records_read_from_inner() {+ predicate_cache_inner_records.add(v);+ }++ if let Some(v) = arrow_reader_metrics.records_read_from_cache() {+ predicate_cache_records.add(v);+ }+}+/// Wraps an inner RecordBatchStream and a [`FilePruner`]////// This can terminate the scan early when some dynamic filters is updated after@@ -658,8 +700,8 @@ async fn load_page_index<T: AsyncFileReader>(if missing_column_index || missing_offset_index {let m = Arc::try_unwrap(Arc::clone(parquet_metadata)).unwrap_or_else(|e| e.as_ref().clone());- let mut reader =- ParquetMetaDataReader::new_with_metadata(m).with_page_indexes(true);+ let mut reader = ParquetMetaDataReader::new_with_metadata(m)+ .with_page_index_policy(PageIndexPolicy::Optional);reader.load_page_index(input).await?;let new_parquet_metadata = reader.finish()?;let new_arrow_reader =@@ -830,6 +872,7 @@ mod test {expr_adapter_factory: Some(Arc::new(DefaultPhysicalExprAdapterFactory)),#[cfg(feature = "parquet_encryption")]encryption_factory: None,+ max_predicate_cache_size: None,}};@@ -919,6 +962,7 @@ mod test {expr_adapter_factory: Some(Arc::new(DefaultPhysicalExprAdapterFactory)),#[cfg(feature = "parquet_encryption")]encryption_factory: None,+ max_predicate_cache_size: None,}};@@ -1024,6 +1068,7 @@ mod test {expr_adapter_factory: Some(Arc::new(DefaultPhysicalExprAdapterFactory)),#[cfg(feature = "parquet_encryption")]encryption_factory: None,+ max_predicate_cache_size: None,}};let make_meta = || FileMeta {@@ -1139,6 +1184,7 @@ mod test {expr_adapter_factory: Some(Arc::new(DefaultPhysicalExprAdapterFactory)),#[cfg(feature = "parquet_encryption")]encryption_factory: None,+ max_predicate_cache_size: None,}};@@ -1255,6 +1301,7 @@ mod test {expr_adapter_factory: Some(Arc::new(DefaultPhysicalExprAdapterFactory)),#[cfg(feature = "parquet_encryption")]encryption_factory: None,+ max_predicate_cache_size: None,}};@@ -1438,6 +1485,7 @@ mod test {expr_adapter_factory: None,#[cfg(feature = "parquet_encryption")]encryption_factory: None,+ max_predicate_cache_size: None,};let predicate = logical2physical(&col("a").eq(lit(1u64)), &table_schema);diff --git a/datafusion/datasource-parquet/src/source.rs b/datafusion/datasource-parquet/src/source.rsindex 644cea85ca..f32725aa66 100644--- a/datafusion/datasource-parquet/src/source.rs+++ b/datafusion/datasource-parquet/src/source.rs@@ -427,6 +427,12 @@ impl ParquetSource {self.table_parquet_options.global.bloom_filter_on_read}+ /// Return the maximum predicate cache size, in bytes, used when+ /// `pushdown_filters`+ pub fn max_predicate_cache_size(&self) -> Option<usize> {+ self.table_parquet_options.global.max_predicate_cache_size+ }+/// Applies schema adapter factory from the FileScanConfig if present.////// # Arguments@@ -583,6 +589,7 @@ impl FileSource for ParquetSource {expr_adapter_factory,#[cfg(feature = "parquet_encryption")]encryption_factory: self.get_encryption_factory_with_config(),+ max_predicate_cache_size: self.max_predicate_cache_size(),})}diff --git a/datafusion/physical-plan/src/spill/mod.rs b/datafusion/physical-plan/src/spill/mod.rsindex 33a7cdbe3f..5b9a91e781 100644--- a/datafusion/physical-plan/src/spill/mod.rs+++ b/datafusion/physical-plan/src/spill/mod.rs@@ -783,7 +783,7 @@ mod tests {.unwrap();let size = get_record_batch_memory_size(&batch);- assert_eq!(size, 8320);+ assert_eq!(size, 8208);}// ==== Spill manager tests ====diff --git a/datafusion/proto-common/proto/datafusion_common.proto b/datafusion/proto-common/proto/datafusion_common.protoindex d89f73269c..267953556b 100644--- a/datafusion/proto-common/proto/datafusion_common.proto+++ b/datafusion/proto-common/proto/datafusion_common.proto@@ -581,6 +581,10 @@ message ParquetOptions {oneof coerce_int96_opt {string coerce_int96 = 32;}++ oneof max_predicate_cache_size_opt {+ uint64 max_predicate_cache_size = 33;+ }}enum JoinSide {diff --git a/datafusion/proto-common/src/from_proto/mod.rs b/datafusion/proto-common/src/from_proto/mod.rsindex bbfd0dfd2a..ea43de5c03 100644--- a/datafusion/proto-common/src/from_proto/mod.rs+++ b/datafusion/proto-common/src/from_proto/mod.rs@@ -1000,6 +1000,9 @@ impl TryFrom<&protobuf::ParquetOptions> for ParquetOptions {protobuf::parquet_options::CoerceInt96Opt::CoerceInt96(v) => Some(v),}).unwrap_or(None),skip_arrow_metadata: value.skip_arrow_metadata,+ max_predicate_cache_size: value.max_predicate_cache_size_opt.map(|opt| match opt {+ protobuf::parquet_options::MaxPredicateCacheSizeOpt::MaxPredicateCacheSize(v) => Some(v as usize),+ }).unwrap_or(None),})}}diff --git a/datafusion/proto-common/src/generated/pbjson.rs b/datafusion/proto-common/src/generated/pbjson.rsindex d0c699106f..e63f345459 100644--- a/datafusion/proto-common/src/generated/pbjson.rs+++ b/datafusion/proto-common/src/generated/pbjson.rs@@ -2007,7 +2007,7 @@ impl<'de> serde::Deserialize<'de> for CsvOptions {if truncated_rows__.is_some() {return Err(serde::de::Error::duplicate_field("truncatedRows"));}- truncated_rows__ =+ truncated_rows__ =Some(map_.next_value::<::pbjson::private::BytesDeserialize<_>>()?.0);}@@ -5632,6 +5632,9 @@ impl serde::Serialize for ParquetOptions {if self.coerce_int96_opt.is_some() {len += 1;}+ if self.max_predicate_cache_size_opt.is_some() {+ len += 1;+ }let mut struct_ser = serializer.serialize_struct("datafusion_common.ParquetOptions", len)?;if self.enable_page_index {struct_ser.serialize_field("enablePageIndex", &self.enable_page_index)?;@@ -5785,6 +5788,15 @@ impl serde::Serialize for ParquetOptions {}}}+ if let Some(v) = self.max_predicate_cache_size_opt.as_ref() {+ match v {+ parquet_options::MaxPredicateCacheSizeOpt::MaxPredicateCacheSize(v) => {+ #[allow(clippy::needless_borrow)]+ #[allow(clippy::needless_borrows_for_generic_args)]+ struct_ser.serialize_field("maxPredicateCacheSize", ToString::to_string(&v).as_str())?;+ }+ }+ }struct_ser.end()}}@@ -5852,6 +5864,8 @@ impl<'de> serde::Deserialize<'de> for ParquetOptions {"bloomFilterNdv","coerce_int96","coerceInt96",+ "max_predicate_cache_size",+ "maxPredicateCacheSize",];#[allow(clippy::enum_variant_names)]@@ -5886,6 +5900,7 @@ impl<'de> serde::Deserialize<'de> for ParquetOptions {BloomFilterFpp,BloomFilterNdv,CoerceInt96,+ MaxPredicateCacheSize,}impl<'de> serde::Deserialize<'de> for GeneratedField {fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>@@ -5937,6 +5952,7 @@ impl<'de> serde::Deserialize<'de> for ParquetOptions {"bloomFilterFpp" | "bloom_filter_fpp" => Ok(GeneratedField::BloomFilterFpp),"bloomFilterNdv" | "bloom_filter_ndv" => Ok(GeneratedField::BloomFilterNdv),"coerceInt96" | "coerce_int96" => Ok(GeneratedField::CoerceInt96),+ "maxPredicateCacheSize" | "max_predicate_cache_size" => Ok(GeneratedField::MaxPredicateCacheSize),_ => Err(serde::de::Error::unknown_field(value, FIELDS)),}}@@ -5986,6 +6002,7 @@ impl<'de> serde::Deserialize<'de> for ParquetOptions {let mut bloom_filter_fpp_opt__ = None;let mut bloom_filter_ndv_opt__ = None;let mut coerce_int96_opt__ = None;+ let mut max_predicate_cache_size_opt__ = None;while let Some(k) = map_.next_key()? {match k {GeneratedField::EnablePageIndex => {@@ -6182,6 +6199,12 @@ impl<'de> serde::Deserialize<'de> for ParquetOptions {}coerce_int96_opt__ = map_.next_value::<::std::option::Option<_>>()?.map(parquet_options::CoerceInt96Opt::CoerceInt96);}+ GeneratedField::MaxPredicateCacheSize => {+ if max_predicate_cache_size_opt__.is_some() {+ return Err(serde::de::Error::duplicate_field("maxPredicateCacheSize"));+ }+ max_predicate_cache_size_opt__ = map_.next_value::<::std::option::Option<::pbjson::private::NumberDeserialize<_>>>()?.map(|x| parquet_options::MaxPredicateCacheSizeOpt::MaxPredicateCacheSize(x.0));+ }}}Ok(ParquetOptions {@@ -6215,6 +6238,7 @@ impl<'de> serde::Deserialize<'de> for ParquetOptions {bloom_filter_fpp_opt: bloom_filter_fpp_opt__,bloom_filter_ndv_opt: bloom_filter_ndv_opt__,coerce_int96_opt: coerce_int96_opt__,+ max_predicate_cache_size_opt: max_predicate_cache_size_opt__,})}}diff --git a/datafusion/proto-common/src/generated/prost.rs b/datafusion/proto-common/src/generated/prost.rsindex f09eef6786..bd7162e992 100644--- a/datafusion/proto-common/src/generated/prost.rs+++ b/datafusion/proto-common/src/generated/prost.rs@@ -836,6 +836,10 @@ pub struct ParquetOptions {pub bloom_filter_ndv_opt: ::core::option::Option<parquet_options::BloomFilterNdvOpt>,#[prost(oneof = "parquet_options::CoerceInt96Opt", tags = "32")]pub coerce_int96_opt: ::core::option::Option<parquet_options::CoerceInt96Opt>,+ #[prost(oneof = "parquet_options::MaxPredicateCacheSizeOpt", tags = "33")]+ pub max_predicate_cache_size_opt: ::core::option::Option<+ parquet_options::MaxPredicateCacheSizeOpt,+ >,}/// Nested message and enum types in `ParquetOptions`.pub mod parquet_options {@@ -889,6 +893,11 @@ pub mod parquet_options {#[prost(string, tag = "32")]CoerceInt96(::prost::alloc::string::String),}+ #[derive(Clone, Copy, PartialEq, ::prost::Oneof)]+ pub enum MaxPredicateCacheSizeOpt {+ #[prost(uint64, tag = "33")]+ MaxPredicateCacheSize(u64),+ }}#[derive(Clone, PartialEq, ::prost::Message)]pub struct Precision {diff --git a/datafusion/proto-common/src/to_proto/mod.rs b/datafusion/proto-common/src/to_proto/mod.rsindex 8ba41fee6a..fae1e2b1c6 100644--- a/datafusion/proto-common/src/to_proto/mod.rs+++ b/datafusion/proto-common/src/to_proto/mod.rs@@ -842,6 +842,7 @@ impl TryFrom<&ParquetOptions> for protobuf::ParquetOptions {binary_as_string: value.binary_as_string,skip_arrow_metadata: value.skip_arrow_metadata,coerce_int96_opt: value.coerce_int96.clone().map(protobuf::parquet_options::CoerceInt96Opt::CoerceInt96),+ max_predicate_cache_size_opt: value.max_predicate_cache_size.map(|v| protobuf::parquet_options::MaxPredicateCacheSizeOpt::MaxPredicateCacheSize(v as u64)),})}}diff --git a/datafusion/proto/src/generated/datafusion_proto_common.rs b/datafusion/proto/src/generated/datafusion_proto_common.rsindex f09eef6786..bd7162e992 100644--- a/datafusion/proto/src/generated/datafusion_proto_common.rs+++ b/datafusion/proto/src/generated/datafusion_proto_common.rs@@ -836,6 +836,10 @@ pub struct ParquetOptions {pub bloom_filter_ndv_opt: ::core::option::Option<parquet_options::BloomFilterNdvOpt>,#[prost(oneof = "parquet_options::CoerceInt96Opt", tags = "32")]pub coerce_int96_opt: ::core::option::Option<parquet_options::CoerceInt96Opt>,+ #[prost(oneof = "parquet_options::MaxPredicateCacheSizeOpt", tags = "33")]+ pub max_predicate_cache_size_opt: ::core::option::Option<+ parquet_options::MaxPredicateCacheSizeOpt,+ >,}/// Nested message and enum types in `ParquetOptions`.pub mod parquet_options {@@ -889,6 +893,11 @@ pub mod parquet_options {#[prost(string, tag = "32")]CoerceInt96(::prost::alloc::string::String),}+ #[derive(Clone, Copy, PartialEq, ::prost::Oneof)]+ pub enum MaxPredicateCacheSizeOpt {+ #[prost(uint64, tag = "33")]+ MaxPredicateCacheSize(u64),+ }}#[derive(Clone, PartialEq, ::prost::Message)]pub struct Precision {diff --git a/datafusion/proto/src/logical_plan/file_formats.rs b/datafusion/proto/src/logical_plan/file_formats.rsindex 492795855c..1de175ae96 100644--- a/datafusion/proto/src/logical_plan/file_formats.rs+++ b/datafusion/proto/src/logical_plan/file_formats.rs@@ -417,6 +417,9 @@ impl TableParquetOptionsProto {coerce_int96_opt: global_options.global.coerce_int96.map(|compression| {parquet_options::CoerceInt96Opt::CoerceInt96(compression)}),+ max_predicate_cache_size_opt: global_options.global.max_predicate_cache_size.map(|size| {+ parquet_options::MaxPredicateCacheSizeOpt::MaxPredicateCacheSize(size as u64)+ }),}),column_specific_options: column_specific_options.into_iter().map(|(column_name, options)| {ParquetColumnSpecificOptions {@@ -510,6 +513,9 @@ impl From<&ParquetOptionsProto> for ParquetOptions {coerce_int96: proto.coerce_int96_opt.as_ref().map(|opt| match opt {parquet_options::CoerceInt96Opt::CoerceInt96(coerce_int96) => coerce_int96.clone(),}),+ max_predicate_cache_size: proto.max_predicate_cache_size_opt.as_ref().map(|opt| match opt {+ parquet_options::MaxPredicateCacheSizeOpt::MaxPredicateCacheSize(size) => *size as usize,+ }),}}}diff --git a/datafusion/sqllogictest/test_files/explain_tree.slt b/datafusion/sqllogictest/test_files/explain_tree.sltindex 0df361a75b..b4916cb6e6 100644--- a/datafusion/sqllogictest/test_files/explain_tree.slt+++ b/datafusion/sqllogictest/test_files/explain_tree.slt@@ -1314,7 +1314,7 @@ physical_plan11)┌─────────────┴─────────────┐┌─────────────┴─────────────┐12)│ DataSourceExec ││ DataSourceExec │13)│ -------------------- ││ -------------------- │-14)│ bytes: 6040 ││ bytes: 6040 │+14)│ bytes: 5932 ││ bytes: 5932 │15)│ format: memory ││ format: memory │16)│ rows: 1 ││ rows: 1 │17)└───────────────────────────┘└───────────────────────────┘@@ -1798,7 +1798,7 @@ physical_plan11)┌─────────────┴─────────────┐12)│ DataSourceExec │13)│ -------------------- │-14)│ bytes: 2672 │+14)│ bytes: 2576 │15)│ format: memory │16)│ rows: 1 │17)└───────────────────────────┘@@ -1821,7 +1821,7 @@ physical_plan11)┌─────────────┴─────────────┐12)│ DataSourceExec │13)│ -------------------- │-14)│ bytes: 2672 │+14)│ bytes: 2576 │15)│ format: memory │16)│ rows: 1 │17)└───────────────────────────┘@@ -1844,7 +1844,7 @@ physical_plan11)┌─────────────┴─────────────┐12)│ DataSourceExec │13)│ -------------------- │-14)│ bytes: 2672 │+14)│ bytes: 2576 │15)│ format: memory │16)│ rows: 1 │17)└───────────────────────────┘diff --git a/datafusion/sqllogictest/test_files/information_schema.slt b/datafusion/sqllogictest/test_files/information_schema.sltindex 361bc97a17..670992633b 100644--- a/datafusion/sqllogictest/test_files/information_schema.slt+++ b/datafusion/sqllogictest/test_files/information_schema.slt@@ -242,6 +242,7 @@ datafusion.execution.parquet.dictionary_enabled truedatafusion.execution.parquet.dictionary_page_size_limit 1048576datafusion.execution.parquet.enable_page_index truedatafusion.execution.parquet.encoding NULL+datafusion.execution.parquet.max_predicate_cache_size NULLdatafusion.execution.parquet.max_row_group_size 1048576datafusion.execution.parquet.maximum_buffered_record_batches_per_stream 2datafusion.execution.parquet.maximum_parallel_row_group_writers 1@@ -357,6 +358,7 @@ datafusion.execution.parquet.dictionary_enabled true (writing) Sets if dictionardatafusion.execution.parquet.dictionary_page_size_limit 1048576 (writing) Sets best effort maximum dictionary page size, in bytesdatafusion.execution.parquet.enable_page_index true (reading) If true, reads the Parquet data page level metadata (the Page Index), if present, to reduce the I/O and number of rows decoded.datafusion.execution.parquet.encoding NULL (writing) Sets default encoding for any column. Valid values are: plain, plain_dictionary, rle, bit_packed, delta_binary_packed, delta_length_byte_array, delta_byte_array, rle_dictionary, and byte_stream_split. These values are not case sensitive. If NULL, uses default parquet writer setting+datafusion.execution.parquet.max_predicate_cache_size NULL (reading) The maximum predicate cache size, in bytes. When `pushdown_filters` is enabled, sets the maximum memory used to cache the results of predicate evaluation between filter evaluation and output generation. Decreasing this value will reduce memory usage, but may increase IO and CPU usage. None means use the default parquet reader setting. 0 means no caching.datafusion.execution.parquet.max_row_group_size 1048576 (writing) Target maximum number of rows in each row group (defaults to 1M rows). Writing larger row groups requires more memory to write, but can get better compression and be faster to read.datafusion.execution.parquet.maximum_buffered_record_batches_per_stream 2 (writing) By default parallel parquet writer is tuned for minimum memory usage in a streaming execution plan. You may see a performance benefit when writing large parquet files by increasing maximum_parallel_row_group_writers and maximum_buffered_record_batches_per_stream if your system has idle cores and can tolerate additional memory usage. Boosting these values is likely worthwhile when writing out already in-memory data, such as from a cached data frame.datafusion.execution.parquet.maximum_parallel_row_group_writers 1 (writing) By default parallel parquet writer is tuned for minimum memory usage in a streaming execution plan. You may see a performance benefit when writing large parquet files by increasing maximum_parallel_row_group_writers and maximum_buffered_record_batches_per_stream if your system has idle cores and can tolerate additional memory usage. Boosting these values is likely worthwhile when writing out already in-memory data, such as from a cached data frame.diff --git a/docs/source/user-guide/configs.md b/docs/source/user-guide/configs.mdindex f00c4c2acc..4d0b897648 100644--- a/docs/source/user-guide/configs.md+++ b/docs/source/user-guide/configs.md@@ -88,6 +88,7 @@ The following configuration settings are available:| datafusion.execution.parquet.binary_as_string | false | (reading) If true, parquet reader will read columns of `Binary/LargeBinary` with `Utf8`, and `BinaryView` with `Utf8View`. Parquet files generated by some legacy writers do not correctly set the UTF8 flag for strings, causing string columns to be loaded as BLOB instead. || datafusion.execution.parquet.coerce_int96 | NULL | (reading) If true, parquet reader will read columns of physical type int96 as originating from a different resolution than nanosecond. This is useful for reading data from systems like Spark which stores microsecond resolution timestamps in an int96 allowing it to write values with a larger date range than 64-bit timestamps with nanosecond resolution. || datafusion.execution.parquet.bloom_filter_on_read | true | (reading) Use any available bloom filters when reading parquet files |+| datafusion.execution.parquet.max_predicate_cache_size | NULL | (reading) The maximum predicate cache size, in bytes. When `pushdown_filters` is enabled, sets the maximum memory used to cache the results of predicate evaluation between filter evaluation and output generation. Decreasing this value will reduce memory usage, but may increase IO and CPU usage. None means use the default parquet reader setting. 0 means no caching. || datafusion.execution.parquet.data_pagesize_limit | 1048576 | (writing) Sets best effort maximum size of data page in bytes || datafusion.execution.parquet.write_batch_size | 1024 | (writing) Sets write_batch_size in bytes || datafusion.execution.parquet.writer_version | 1.0 | (writing) Sets parquet writer version valid values are "1.0" and "2.0" |