Skip to content

Commit 4913a00

Browse files
make format prefix optional for format options in COPY (#9723)
* make format prefix optional for format options in COPY * fix clippy lint error * Add negative test case for unknown option * Improve test comments --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent d321ba3 commit 4913a00

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

datafusion/sql/src/statement.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,16 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
850850
return plan_err!("Unsupported Value in COPY statement {}", value);
851851
}
852852
};
853-
options.insert(key.to_lowercase(), value_string.to_lowercase());
853+
if !(&key.contains('.')) {
854+
// If config does not belong to any namespace, assume it is
855+
// a format option and apply the format prefix for backwards
856+
// compatibility.
857+
858+
let renamed_key = format!("format.{}", key);
859+
options.insert(renamed_key.to_lowercase(), value_string.to_lowercase());
860+
} else {
861+
options.insert(key.to_lowercase(), value_string.to_lowercase());
862+
}
854863
}
855864

856865
let file_type = if let Some(file_type) = statement.stored_as {

datafusion/sqllogictest/test_files/copy.slt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,45 @@ select * from validate_arrow;
474474
1 Foo
475475
2 Bar
476476

477+
# Format Options Support without the 'format.' prefix
478+
479+
# Copy with format options for Parquet without the 'format.' prefix
480+
query IT
481+
COPY source_table TO 'test_files/scratch/copy/format_table.parquet'
482+
OPTIONS (
483+
compression snappy,
484+
'compression::col1' 'zstd(5)'
485+
);
486+
----
487+
2
488+
489+
# Copy with format options for JSON without the 'format.' prefix
490+
query IT
491+
COPY source_table to 'test_files/scratch/copy/format_table'
492+
STORED AS JSON OPTIONS (compression gzip);
493+
----
494+
2
495+
496+
# Copy with format options for CSV without the 'format.' prefix
497+
query IT
498+
COPY source_table to 'test_files/scratch/copy/format_table.csv'
499+
OPTIONS (
500+
has_header false,
501+
compression xz,
502+
datetime_format '%FT%H:%M:%S.%9f',
503+
delimiter ';',
504+
null_value 'NULLVAL'
505+
);
506+
----
507+
2
508+
509+
# Copy with unknown format options without the 'format.' prefix to ensure error is sensible
510+
query error DataFusion error: Invalid or Unsupported Configuration: Config value "unknown_option" not found on CsvOptions
511+
COPY source_table to 'test_files/scratch/copy/format_table2.csv'
512+
OPTIONS (
513+
unknown_option false,
514+
);
515+
477516

478517
# Error cases:
479518

0 commit comments

Comments
 (0)