Skip to content

Commit b761f85

Browse files
committed
test: add unit test for strip_null_value on variant.rs
Signed-off-by: Kould <[email protected]>
1 parent 002b15c commit b761f85

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

src/query/functions/tests/it/scalars/testdata/variant.txt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5815,3 +5815,75 @@ evaluation (internal):
58155815
+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
58165816

58175817

5818+
ast : strip_null_value(parse_json('1234'))
5819+
raw expr : strip_null_value(parse_json('1234'))
5820+
checked expr : strip_null_value<Variant NULL>(CAST(parse_json<String>("1234") AS Variant NULL))
5821+
optimized expr : 0x20000000200000035004d2
5822+
output type : Variant NULL
5823+
output domain : Undefined
5824+
output : '1234'
5825+
5826+
5827+
ast : strip_null_value(parse_json('null'))
5828+
raw expr : strip_null_value(parse_json('null'))
5829+
checked expr : strip_null_value<Variant NULL>(CAST(parse_json<String>("null") AS Variant NULL))
5830+
optimized expr : NULL
5831+
output type : Variant NULL
5832+
output domain : {NULL}
5833+
output : NULL
5834+
5835+
5836+
ast : strip_null_value(null)
5837+
raw expr : strip_null_value(NULL)
5838+
checked expr : strip_null_value<Variant NULL>(CAST(NULL AS Variant NULL))
5839+
optimized expr : NULL
5840+
output type : Variant NULL
5841+
output domain : {NULL}
5842+
output : NULL
5843+
5844+
5845+
ast : strip_null_value(parse_json(s))
5846+
raw expr : strip_null_value(parse_json(s::String))
5847+
checked expr : strip_null_value<Variant NULL>(CAST(parse_json<String>(s) AS Variant NULL))
5848+
evaluation:
5849+
+--------+-------------------------------------------------------+--------------------+
5850+
| | s | Output |
5851+
+--------+-------------------------------------------------------+--------------------+
5852+
| Type | String | Variant NULL |
5853+
| Domain | {"[\"a\",\"b\",\"c\"]"..="{ \"a\": 1, \"b\": null }"} | Unknown |
5854+
| Row 0 | '{ "a": 1, "b": null }' | '{"a":1,"b":null}' |
5855+
| Row 1 | 'null' | NULL |
5856+
| Row 2 | '["a","b","c"]' | '["a","b","c"]' |
5857+
+--------+-------------------------------------------------------+--------------------+
5858+
evaluation (internal):
5859+
+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
5860+
| Column | Data |
5861+
+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
5862+
| s | StringColumn[{ "a": 1, "b": null }, null, ["a","b","c"]] |
5863+
| Output | NullableColumn { column: BinaryColumn { data: 0x40000002100000011000000120000002000000006162500180000003100000011000000110000001616263, offsets: [0, 24, 24, 43] }, validity: [0b_____101] } |
5864+
+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
5865+
5866+
5867+
ast : strip_null_value(parse_json(s))
5868+
raw expr : strip_null_value(parse_json(s::String NULL))
5869+
checked expr : strip_null_value<Variant NULL>(parse_json<String NULL>(s))
5870+
evaluation:
5871+
+--------+----------------------------------------------------------------+--------------------+
5872+
| | s | Output |
5873+
+--------+----------------------------------------------------------------+--------------------+
5874+
| Type | String NULL | Variant NULL |
5875+
| Domain | {"[\"a\",\"b\",\"c\"]"..="{ \"a\": 1, \"b\": null }"} ∪ {NULL} | Unknown |
5876+
| Row 0 | '{ "a": 1, "b": null }' | '{"a":1,"b":null}' |
5877+
| Row 1 | 'null' | NULL |
5878+
| Row 2 | NULL | NULL |
5879+
| Row 3 | '["a","b","c"]' | '["a","b","c"]' |
5880+
+--------+----------------------------------------------------------------+--------------------+
5881+
evaluation (internal):
5882+
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
5883+
| Column | Data |
5884+
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
5885+
| s | NullableColumn { column: StringColumn[{ "a": 1, "b": null }, null, , ["a","b","c"]], validity: [0b____1011] } |
5886+
| Output | NullableColumn { column: BinaryColumn { data: 0x40000002100000011000000120000002000000006162500180000003100000011000000110000001616263, offsets: [0, 24, 24, 24, 43] }, validity: [0b____1001] } |
5887+
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
5888+
5889+

src/query/functions/tests/it/scalars/variant.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ fn test_variant() {
7272
test_json_object_insert(file);
7373
test_json_object_delete(file);
7474
test_json_object_pick(file);
75+
test_strip_null_value(file);
7576
}
7677

7778
fn test_parse_json(file: &mut impl Write) {
@@ -2131,3 +2132,22 @@ fn test_json_object_pick(file: &mut impl Write) {
21312132
),
21322133
)]);
21332134
}
2135+
2136+
fn test_strip_null_value(file: &mut impl Write) {
2137+
run_ast(file, "strip_null_value(parse_json('1234'))", &[]);
2138+
run_ast(file, "strip_null_value(parse_json('null'))", &[]);
2139+
run_ast(file, "strip_null_value(null)", &[]);
2140+
2141+
run_ast(file, "strip_null_value(parse_json(s))", &[(
2142+
"s",
2143+
StringType::from_data(vec![r#"{ "a": 1, "b": null }"#, "null", "[\"a\",\"b\",\"c\"]"]),
2144+
)]);
2145+
2146+
run_ast(file, "strip_null_value(parse_json(s))", &[(
2147+
"s",
2148+
StringType::from_data_with_validity(
2149+
vec![r#"{ "a": 1, "b": null }"#, "null", "", "[\"a\",\"b\",\"c\"]"],
2150+
vec![true, true, false, true],
2151+
),
2152+
)]);
2153+
}

0 commit comments

Comments
 (0)