Skip to content

Commit

Permalink
Passes SLT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
metesynnada committed Feb 27, 2024
1 parent ea22682 commit fb86d94
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
15 changes: 15 additions & 0 deletions datafusion/core/src/datasource/file_format/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,4 +1207,19 @@ mod tests {

Ok(())
}

#[tokio::test]
async fn test_sql() -> Result<()> {
let config = SessionConfig::new();
let ctx = SessionContext::new_with_config(config);
ctx.sql("create table test (\"'test'\" varchar, \"'test2'\" varchar, \"'test3'\" varchar); ")
.await?.collect().await?;
ctx.sql("insert into test VALUES ('a', 'x', 'aa'), ('b','y', 'bb'), ('c', 'z', 'cc')")
.await?.collect().await?;
ctx.sql("copy test to '/Users/metehanyildirim/Documents/Synnada/Coding/datafusion-upstream/datafusion/sqllogictest/test_files/scratch/copy/escape_quote' (format csv, partition_by '''test2'',''test3''')")
.await?.collect().await?;

Ok(())
}

}
13 changes: 3 additions & 10 deletions datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,20 +1389,13 @@ pub fn take_partition_by(options: &mut HashMap<String, String>) -> Vec<String> {
let partition_by = options.remove("partition_by");
match partition_by {
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
part_cols
.split(',')
.map(|s| s.trim().replace("''", "'"))
.collect::<Vec<_>>()
}
None => vec![],
}
}


10 changes: 5 additions & 5 deletions datafusion/sqllogictest/test_files/copy.slt
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ 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
# 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
Expand Down

0 comments on commit fb86d94

Please sign in to comment.