Skip to content

Commit 5cb9a33

Browse files
wiedldappletreeisyellow
authored andcommitted
test: demomnstrate API contract for metadata TableParquetOptions
1 parent 0c46a7a commit 5cb9a33

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

datafusion/common/src/config.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,20 @@ impl ConfigField for TableParquetOptions {
13861386
// Determine the key if it's a global or column-specific setting
13871387
if key.contains("::") {
13881388
self.column_specific_options.set(key, value)
1389+
} else if key.eq("metadata") {
1390+
for maybe_pair in value.split('_') {
1391+
let (k, v) = match maybe_pair.split(':').collect::<Vec<_>>()[..] {
1392+
[k, v] => (k.into(), Some(v.into())),
1393+
[k] => (k.into(), None),
1394+
_ => {
1395+
return Err(DataFusionError::Configuration(format!(
1396+
"Invalid metadata provided \"{maybe_pair}\""
1397+
)))
1398+
}
1399+
};
1400+
self.key_value_metadata.insert(k, v);
1401+
}
1402+
Ok(())
13891403
} else {
13901404
self.global.set(key, value)
13911405
}

datafusion/sqllogictest/test_files/copy.slt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,38 @@ OPTIONS (
283283
'format.statistics_enabled::col2' none,
284284
'format.max_statistics_size' 123,
285285
'format.bloom_filter_fpp' 0.001,
286-
'format.bloom_filter_ndv' 100
286+
'format.bloom_filter_ndv' 100,
287+
'format.metadata' 'foo:bar baz'
287288
)
288289
----
289290
2
290291

292+
# valid vs invalid metadata
293+
294+
statement ok
295+
COPY source_table
296+
TO 'test_files/scratch/copy/table_with_metadata/'
297+
STORED AS PARQUET
298+
OPTIONS (
299+
'format.metadata' ''
300+
)
301+
302+
statement error
303+
COPY source_table
304+
TO 'test_files/scratch/copy/table_with_metadata/'
305+
STORED AS PARQUET
306+
OPTIONS (
307+
'format.metadata' 'foo:bar:extra'
308+
)
309+
310+
statement error
311+
COPY source_table
312+
TO 'test_files/scratch/copy/table_with_metadata/'
313+
STORED AS PARQUET
314+
OPTIONS (
315+
'format.wrong-metadata-key' 'foo:bar baz'
316+
)
317+
291318
# validate multiple parquet file output with all options set
292319
statement ok
293320
CREATE EXTERNAL TABLE validate_parquet_with_options STORED AS PARQUET LOCATION 'test_files/scratch/copy/table_with_options/';

0 commit comments

Comments
 (0)