Skip to content

Commit 8ae9271

Browse files
committed
fix(format): format option values are unescaped twice.
1 parent 4533c87 commit 8ae9271

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

src/query/sql/src/planner/binder/copy.rs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use common_ast::parser::parse_sql;
2424
use common_ast::parser::tokenize_sql;
2525
use common_ast::Backtrace;
2626
use common_ast::Dialect;
27-
use common_base::base::unescape_string;
2827
use common_catalog::plan::DataSourceInfo;
2928
use common_catalog::plan::DataSourcePlan;
3029
use common_catalog::plan::Partitions;
@@ -611,44 +610,41 @@ pub fn parse_copy_file_format_options(
611610
.parse::<u64>()?;
612611

613612
// Field delimiter.
614-
let field_delimiter = unescape_string(
615-
file_format_options
616-
.get("field_delimiter")
617-
.unwrap_or(&"".to_string()),
618-
)?;
613+
let field_delimiter = file_format_options
614+
.get("field_delimiter")
615+
.unwrap_or(&"".to_string())
616+
.to_string();
619617

620618
// Record delimiter.
621-
let record_delimiter = unescape_string(
622-
file_format_options
623-
.get("record_delimiter")
624-
.unwrap_or(&"".to_string()),
625-
)?;
619+
let record_delimiter = file_format_options
620+
.get("record_delimiter")
621+
.unwrap_or(&"".to_string())
622+
.to_string();
626623

627624
// NaN display.
628-
let nan_display = unescape_string(
629-
file_format_options
630-
.get("nan_display")
631-
.unwrap_or(&"".to_string()),
632-
)?;
625+
let nan_display = file_format_options
626+
.get("nan_display")
627+
.unwrap_or(&"".to_string())
628+
.to_string();
633629

634630
// Escape
635-
let escape = unescape_string(file_format_options.get("escape").unwrap_or(&"".to_string()))?;
631+
let escape = file_format_options
632+
.get("escape")
633+
.unwrap_or(&"".to_string())
634+
.to_string();
636635

637636
// Compression delimiter.
638-
let compression = unescape_string(
639-
file_format_options
640-
.get("compression")
641-
.unwrap_or(&"none".to_string()),
642-
)?
643-
.parse()
644-
.map_err(ErrorCode::UnknownCompressionType)?;
637+
let compression = file_format_options
638+
.get("compression")
639+
.unwrap_or(&"none".to_string())
640+
.parse()
641+
.map_err(ErrorCode::UnknownCompressionType)?;
645642

646643
// Row tag in xml.
647-
let row_tag = unescape_string(
648-
file_format_options
649-
.get("row_tag")
650-
.unwrap_or(&"".to_string()),
651-
)?;
644+
let row_tag = file_format_options
645+
.get("row_tag")
646+
.unwrap_or(&"".to_string())
647+
.to_string();
652648

653649
Ok(FileFormatOptions {
654650
format: file_format,

tests/suites/1_stateful/05_formats/05_02_csv/05_02_01_csv_escape.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ curl -sH "insert_sql:insert into test_csv format CSV" -H "format_escape:'\\\'" -
4949
echo "select * from test_csv" | $MYSQL_CLIENT_CONNECT
5050
echo "truncate table test_csv" | $MYSQL_CLIENT_CONNECT
5151

52+
## just need `\\` in sql client, `\\\\` is for shell
5253
aws --endpoint-url http://127.0.0.1:9900/ s3 cp /tmp/escape_slash2.csv s3://testbucket/admin/data/csv/escape_slash2.csv > /dev/null 2>&1
53-
echo "copy into test_csv from 'fs:///tmp/escape_slash2.csv' FILE_FORMAT = (type = 'CSV' escape='\\\\\\\\')" | $MYSQL_CLIENT_CONNECT
54+
echo "copy into test_csv from 'fs:///tmp/escape_slash2.csv' FILE_FORMAT = (type = 'CSV' escape='\\\\')" | $MYSQL_CLIENT_CONNECT
5455
echo "select * from test_csv" | $MYSQL_CLIENT_CONNECT
5556

5657
aws --endpoint-url http://127.0.0.1:9900/ s3 cp /tmp/escape_slash3.csv s3://testbucket/admin/data/csv/escape_slash3.csv > /dev/null 2>&1
57-
echo "copy into test_csv2 from 'fs:///tmp/escape_slash3.csv' FILE_FORMAT = (type = 'CSV' escape='\\\\\\\\' skip_header=1)" | $MYSQL_CLIENT_CONNECT
58+
echo "copy into test_csv2 from 'fs:///tmp/escape_slash3.csv' FILE_FORMAT = (type = 'CSV' escape='\\\\' skip_header=1)" | $MYSQL_CLIENT_CONNECT
5859
echo "select * from test_csv2" | $MYSQL_CLIENT_CONNECT
5960

6061
echo "drop table if exists test_csv" | $MYSQL_CLIENT_CONNECT

0 commit comments

Comments
 (0)