Skip to content

Commit

Permalink
test: demomnstrate API contract for metadata TableParquetOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedld committed Apr 24, 2024
1 parent c964df5 commit 8beb16a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
14 changes: 14 additions & 0 deletions datafusion/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()[..] {
[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)
}
Expand Down
29 changes: 28 additions & 1 deletion datafusion/sqllogictest/test_files/copy.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
Expand Down

0 comments on commit 8beb16a

Please sign in to comment.