From 10b6287f50f2ded6937a1b821d93c4293e84fdc9 Mon Sep 17 00:00:00 2001 From: wiedld Date: Wed, 24 Apr 2024 11:53:47 -0700 Subject: [PATCH] test: demomnstrate API contract for metadata TableParquetOptions --- datafusion/common/src/config.rs | 14 ++++++++++ datafusion/sqllogictest/test_files/copy.slt | 29 ++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/datafusion/common/src/config.rs b/datafusion/common/src/config.rs index 8378bbb154c4e..eea27911e9c5a 100644 --- a/datafusion/common/src/config.rs +++ b/datafusion/common/src/config.rs @@ -1384,6 +1384,20 @@ impl ConfigField for TableParquetOptions { // Determine the key if it's a global or column-specific setting if key.contains("::") { self.column_specific_options.set(key, value) + } else if key.eq("metadata") { + for maybe_pair in value.split('_') { + let (k, v) = match maybe_pair.split(':').collect::>()[..] { + [k, v] => (k.into(), Some(v.into())), + [k] => (k.into(), None), + _ => { + return Err(DataFusionError::Configuration(format!( + "Invalid metadata provided \"{maybe_pair}\"" + ))) + } + }; + self.key_value_metadata.insert(k, v); + } + Ok(()) } else { self.global.set(key, value) } diff --git a/datafusion/sqllogictest/test_files/copy.slt b/datafusion/sqllogictest/test_files/copy.slt index fca892dfcdadc..230f157026d4c 100644 --- a/datafusion/sqllogictest/test_files/copy.slt +++ b/datafusion/sqllogictest/test_files/copy.slt @@ -283,11 +283,38 @@ OPTIONS ( 'format.statistics_enabled::col2' none, 'format.max_statistics_size' 123, 'format.bloom_filter_fpp' 0.001, -'format.bloom_filter_ndv' 100 +'format.bloom_filter_ndv' 100, +'format.metadata' 'foo:bar baz' ) ---- 2 +# valid vs invalid metadata + +statement ok +COPY source_table +TO 'test_files/scratch/copy/table_with_metadata/' +STORED AS PARQUET +OPTIONS ( +'format.metadata' '' +) + +statement error +COPY source_table +TO 'test_files/scratch/copy/table_with_metadata/' +STORED AS PARQUET +OPTIONS ( +'format.metadata' 'foo:bar:extra' +) + +statement error +COPY source_table +TO 'test_files/scratch/copy/table_with_metadata/' +STORED AS PARQUET +OPTIONS ( +'format.wrong-metadata-key' 'foo:bar baz' +) + # validate multiple parquet file output with all options set statement ok CREATE EXTERNAL TABLE validate_parquet_with_options STORED AS PARQUET LOCATION 'test_files/scratch/copy/table_with_options/';