Skip to content

Commit 01ea886

Browse files
committed
bug(format): support hex as format field delimiter
1 parent 466fa2b commit 01ea886

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/query/formats/src/format_option_checker.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ impl FormatOptionChecker for TSVFormatOptionChecker {
138138
"TSV".to_string()
139139
}
140140

141-
fn check_quote(&self, quote: &mut String) -> Result<()> {
142-
check_quote(quote, "\'")
143-
}
144-
145141
fn check_escape(&self, escape: &mut String) -> Result<()> {
146142
check_escape(escape, "\\")
147143
}
148144

145+
fn check_quote(&self, quote: &mut String) -> Result<()> {
146+
check_quote(quote, "\'")
147+
}
148+
149149
fn check_record_delimiter(&self, record_delimiter: &mut String) -> Result<()> {
150150
check_record_delimiter(record_delimiter)
151151
}
@@ -222,7 +222,7 @@ pub fn check_quote(option: &mut String, default: &str) -> Result<()> {
222222
pub fn check_field_delimiter(option: &mut String, default: &str) -> Result<()> {
223223
if option.is_empty() {
224224
*option = default.to_string()
225-
} else if option.len() > 1 {
225+
} else if option.as_bytes().len() > 1 {
226226
return Err(ErrorCode::InvalidArgument(
227227
"field_delimiter can only contain one char",
228228
));

src/query/formats/tests/it/output_format_tcsv.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,30 @@ fn test_data_block_nullable() -> Result<()> {
108108
fn test_data_block_not_nullable() -> Result<()> {
109109
test_data_block(false)
110110
}
111+
112+
#[test]
113+
fn test_field_delimiter_with_ascii_control_code() -> Result<()> {
114+
let block = get_simple_block(false)?;
115+
let schema = block.schema().clone();
116+
117+
let settings = Settings::default_settings("default")?;
118+
settings.set_settings(
119+
"format_record_delimiter".to_string(),
120+
"\r\n".to_string(),
121+
false,
122+
)?;
123+
settings.set_settings(
124+
"format_field_delimiter".to_string(),
125+
"\x01".to_string(),
126+
false,
127+
)?;
128+
129+
let mut formatter = get_output_format_clickhouse_with_setting("csv", schema, &settings)?;
130+
let buffer = formatter.serialize_block(&block)?;
131+
132+
let csv_block = String::from_utf8(buffer)?;
133+
let expect = "1\x01\"a\"\x01true\x011.1\x01\"1970-01-02\"\r\n2\x01\"b\"\"\"\x01true\x012.2\x01\"1970-01-03\"\r\n3\x01\"c'\"\x01false\x01NaN\x01\"1970-01-04\"\r\n";
134+
assert_eq!(&csv_block, expect);
135+
136+
Ok(())
137+
}

0 commit comments

Comments
 (0)