Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(query): NDJSON copy into allow cast bool and number to string #15308

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/query/formats/src/field_decoder/json_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,24 @@ impl FieldJsonAstDecoder {
match value {
Value::String(s) => {
column.put_str(s.as_str());
column.commit_row();
Ok(())
}
_ => Err(ErrorCode::BadBytes("Incorrect json value, must be string")),
Value::Bool(v) => {
if *v {
column.put_str("true");
} else {
column.put_str("false");
}
}
Value::Number(n) => {
column.put_str(n.to_string().as_str());
}
Value::Null => {
column.put_str("null");
}
_ => return Err(ErrorCode::BadBytes("Incorrect json value, must be string")),
}
column.commit_row();
Ok(())
}

fn read_date(&self, column: &mut Vec<i32>, value: &Value) -> Result<()> {
Expand Down
3 changes: 3 additions & 0 deletions tests/data/ndjson/cast_sample.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"name":"data1","tags":{"env":"test1","length":"ok"}}
{"name":"data2","tags":{"env":"test2","length":true}}
{"name":"data3","tags":{"env":"test3","length":10}}
17 changes: 17 additions & 0 deletions tests/sqllogictests/suites/stage/formats/ndjson/ndjson_cast.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
statement ok
drop table if exists cast_ndjson

statement ok
CREATE TABLE cast_ndjson (name String, tags Map(String, String))

query
copy into cast_ndjson from @data/ndjson/cast_sample.ndjson file_format = (type = NDJSON) ON_ERROR=continue
----
ndjson/cast_sample.ndjson 3 0 NULL NULL

query
select * from cast_ndjson
----
data1 {'env':'test1','length':'ok'}
data2 {'env':'test2','length':'true'}
data3 {'env':'test3','length':'10'}
Loading