From 10e98920447b35ed0fdc7dea37f90959fcb610d3 Mon Sep 17 00:00:00 2001 From: sundyli <543950155@qq.com> Date: Thu, 9 Jun 2022 16:30:09 +0800 Subject: [PATCH 1/5] feature(query): fix read quoted string --- common/io/src/buffer/buffer_read_ext.rs | 38 ++++++++++++++++++- .../03_dml/03_0016_insert_into_values.result | 2 + .../03_dml/03_0016_insert_into_values.sql | 7 ++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/common/io/src/buffer/buffer_read_ext.rs b/common/io/src/buffer/buffer_read_ext.rs index 5004135111c9..19d364d97ac2 100644 --- a/common/io/src/buffer/buffer_read_ext.rs +++ b/common/io/src/buffer/buffer_read_ext.rs @@ -46,8 +46,42 @@ pub trait BufferReadExt: BufferRead { fn read_quoted_text(&mut self, buf: &mut Vec, quota: u8) -> Result<()> { self.must_ignore_byte(quota)?; - self.keep_read(buf, |b| b != quota)?; - self.must_ignore_byte(quota) + + loop { + self.keep_read(buf, |b| b != quota && b != b'\\')?; + if self.ignore_byte(quota)? { + return Ok(()); + } else if self.ignore_byte(b'\\')? { + let b = self.fill_buf()?; + if b.is_empty() { + return Err(std::io::Error::new( + ErrorKind::InvalidData, + "Expected to have terminated string literal.".to_string(), + )); + } + let c = b[0]; + self.ignore_byte(c)?; + match c { + b'n' => buf.push(b'\n'), + b't' => buf.push(b'\t'), + b'r' => buf.push(b'\r'), + b'0' => buf.push(b'\0'), + b'\'' => buf.push(b'\''), + b'\\' => buf.push(b'\\'), + b'\"' => buf.push(b'\"'), + _ => { + buf.push(b'\\'); + buf.push(c); + } + } + } else { + break; + } + } + return Err(std::io::Error::new( + ErrorKind::InvalidData, + "Expected to have terminated string literal.".to_string(), + )); } fn read_escaped_string_text(&mut self, buf: &mut Vec) -> Result<()> { diff --git a/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.result b/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.result index 9db01e1cc133..dfb66e92553e 100644 --- a/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.result +++ b/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.result @@ -1,3 +1,5 @@ -1 33 2021-08-15 10:00:00.000000 string1234 101 67 2021-11-15 10:00:00.000000 string5678 100 100 +a"b"c'd +a"b"c\\'d diff --git a/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.sql b/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.sql index 390d86f83b6d..eb498ca7ee72 100644 --- a/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.sql +++ b/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.sql @@ -12,4 +12,11 @@ select * from t1; select sum(a),sum(b) from t1; +CREATE TABLE IF NOT EXISTS t_str(a Varchar); +INSERT INTO t_str(a) values( 'a"b\"c\'d'); +INSERT INTO t_str(a) values( 'a"b\"c\\\'d'); +select * from t_str; + +drop table t_str; + DROP DATABASE db1; From 0756984c1e35e97d1c60856945c0c4f87c24648e Mon Sep 17 00:00:00 2001 From: sundyli <543950155@qq.com> Date: Thu, 9 Jun 2022 16:47:31 +0800 Subject: [PATCH 2/5] feature(query): fix read quoted string --- common/io/src/buffer/buffer_read_ext.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/io/src/buffer/buffer_read_ext.rs b/common/io/src/buffer/buffer_read_ext.rs index 19d364d97ac2..93852d2c6656 100644 --- a/common/io/src/buffer/buffer_read_ext.rs +++ b/common/io/src/buffer/buffer_read_ext.rs @@ -78,7 +78,7 @@ pub trait BufferReadExt: BufferRead { break; } } - return Err(std::io::Error::new( + Err(std::io::Error::new( ErrorKind::InvalidData, "Expected to have terminated string literal.".to_string(), )); From 6037ca96a91dc252e6f9a73f5fe53e80dbc3c37e Mon Sep 17 00:00:00 2001 From: sundyli <543950155@qq.com> Date: Thu, 9 Jun 2022 17:36:02 +0800 Subject: [PATCH 3/5] feature(query): fix read quoted string --- common/io/src/buffer/buffer_read_ext.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/io/src/buffer/buffer_read_ext.rs b/common/io/src/buffer/buffer_read_ext.rs index 93852d2c6656..77214c4b78c8 100644 --- a/common/io/src/buffer/buffer_read_ext.rs +++ b/common/io/src/buffer/buffer_read_ext.rs @@ -81,7 +81,7 @@ pub trait BufferReadExt: BufferRead { Err(std::io::Error::new( ErrorKind::InvalidData, "Expected to have terminated string literal.".to_string(), - )); + )) } fn read_escaped_string_text(&mut self, buf: &mut Vec) -> Result<()> { From a4effc62828c6f55ccc59327b5dd10b21bb84897 Mon Sep 17 00:00:00 2001 From: sundyli <543950155@qq.com> Date: Thu, 9 Jun 2022 22:12:35 +0800 Subject: [PATCH 4/5] feature(query): fix tests --- .../logictest/suites/gen/09_fuse_engine/09_0001_remote_insert | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/logictest/suites/gen/09_fuse_engine/09_0001_remote_insert b/tests/logictest/suites/gen/09_fuse_engine/09_0001_remote_insert index a623d1e8957d..3eefd87ed2f2 100644 --- a/tests/logictest/suites/gen/09_fuse_engine/09_0001_remote_insert +++ b/tests/logictest/suites/gen/09_fuse_engine/09_0001_remote_insert @@ -22,7 +22,8 @@ SELECT * FROM t1; ---- http 1 1 1 -2 2 \"2\"-\"2\" +2 2 "2"-"2" + statement ok CREATE TABLE IF NOT EXISTS t2(a Boolean, b Timestamp, c Date) Engine = fuse; From a43fc8ad635291630af9b32ef173ee2500f08691 Mon Sep 17 00:00:00 2001 From: sundyli <543950155@qq.com> Date: Thu, 9 Jun 2022 23:01:08 +0800 Subject: [PATCH 5/5] feature(query): fix tests --- tests/suites/0_stateless/03_dml/03_0016_insert_into_values.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.sql b/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.sql index eb498ca7ee72..dcfe97f21925 100644 --- a/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.sql +++ b/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.sql @@ -15,7 +15,7 @@ select sum(a),sum(b) from t1; CREATE TABLE IF NOT EXISTS t_str(a Varchar); INSERT INTO t_str(a) values( 'a"b\"c\'d'); INSERT INTO t_str(a) values( 'a"b\"c\\\'d'); -select * from t_str; +select * from t_str order by a; drop table t_str;