Skip to content

Commit

Permalink
try to support columns with single quotes in name
Browse files Browse the repository at this point in the history
  • Loading branch information
devinjdangelo committed Feb 16, 2024
1 parent aed4d08 commit 8b6b6b0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
19 changes: 15 additions & 4 deletions datafusion/common/src/file_options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,21 @@ impl StatementOptions {
pub fn take_partition_by(&mut self) -> Vec<String> {
let partition_by = self.take_str_option("partition_by");
match partition_by {
Some(part_cols) => part_cols
.split(',')
.map(|s| s.trim().replace('\'', ""))
.collect::<Vec<_>>(),
Some(part_cols) => {
let dequoted = part_cols
.chars()
.enumerate()
.filter(|(idx, c)| {
!((*idx == 0 || *idx == part_cols.len() - 1)
&& (*c == '\'' || *c == '"'))
})
.map(|(_idx, c)| c)
.collect::<String>();
dequoted
.split(',')
.map(|s| s.trim().replace("''", "'"))
.collect::<Vec<_>>()
}
None => vec![],
}
}
Expand Down
29 changes: 29 additions & 0 deletions datafusion/sqllogictest/test_files/copy.slt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ select * from validate_partitioned_parquet_a_x order by column1;
----
1

statement ok
create table test ("'test'" varchar, "'test2'" varchar, "'test3'" varchar);

query TTT
insert into test VALUES ('a', 'x', 'aa'), ('b','y', 'bb'), ('c', 'z', 'cc')
----
3

query T
select "'test'" from test
----
a
b
c

# Note to place a single ' inside of a literal string escape by putting two ''
query TTT
copy test to 'test_files/scratch/copy/escape_quote' (format csv, partition_by '''test2'',''test3''')
----
3

statement ok
CREATE EXTERNAL TABLE validate_partitioned_escape_quote STORED AS CSV
LOCATION 'test_files/scratch/copy/escape_quote/' PARTITIONED BY ("'test2'", "'test3'");

# This triggers a panic (index out of bounds)
#query
#select * from validate_partitioned_escape_quote;

query TT
EXPLAIN COPY source_table TO 'test_files/scratch/copy/table/' (format parquet, compression 'zstd(10)');
----
Expand Down

0 comments on commit 8b6b6b0

Please sign in to comment.