Skip to content

Commit

Permalink
Merge pull request #5870 from sundy-li/fix-quoted
Browse files Browse the repository at this point in the history
feature(query): fix read quoted string
  • Loading branch information
mergify[bot] authored Jun 9, 2022
2 parents 53edeb9 + a43fc8a commit f1935c4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
38 changes: 36 additions & 2 deletions common/io/src/buffer/buffer_read_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,42 @@ pub trait BufferReadExt: BufferRead {

fn read_quoted_text(&mut self, buf: &mut Vec<u8>, 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;
}
}
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<u8>) -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 order by a;

drop table t_str;

DROP DATABASE db1;

0 comments on commit f1935c4

Please sign in to comment.