Skip to content

Commit 4123682

Browse files
authored
Merge pull request #9195 from youngsofun/delimiter
fix(format): format option values are unescaped twice.
2 parents 0d8217c + 32a88fb commit 4123682

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

.github/workflows/dev-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ jobs:
189189
- uses: ./.github/actions/test_stateless_standalone_linux
190190

191191
test_stateless_cluster_linux:
192-
timeout-minutes: 20
192+
timeout-minutes: 30
193193
runs-on: [self-hosted, X64, Linux, development]
194194
needs: build_gnu
195195
steps:

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/logictest/suites/base/05_ddl/05_0016_ddl_stage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ statement query TTTTTITT
2323
desc stage test_stage_internal;
2424

2525
----
26-
test_stage_internal Internal StageParams { storage: Fs(StorageFsConfig { root: "_data" }) } CopyOptions { on_error: None, size_limit: 0, split_size: 0, purge: false, single: false, max_file_size: 0 } FileFormatOptions { format: Csv, skip_header: 0, field_delimiter: "", record_delimiter: "NONE", nan_display: "", escape: "\\", compression: Auto, row_tag: "" } 0 'root'@'127.0.0.1'
26+
test_stage_internal Internal StageParams { storage: Fs(StorageFsConfig { root: "_data" }) } CopyOptions { on_error: None, size_limit: 0, split_size: 0, purge: false, single: false, max_file_size: 0 } FileFormatOptions { format: Csv, skip_header: 0, field_delimiter: "", record_delimiter: "NONE", nan_display: "", escape: "\\\\", compression: Auto, row_tag: "" } 0 'root'@'127.0.0.1'
2727

2828
statement query TTTTT
2929
SHOW STAGES;

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)