From b8f35a799e2934fc480a865e830910cca7f6bd93 Mon Sep 17 00:00:00 2001 From: lihangyu <15605149486@163.com> Date: Wed, 7 Aug 2024 15:02:45 +0800 Subject: [PATCH] [Fix](Json) fix some cast issue (#38683) 1. casting to boolean/double type should consider all numeric types including int , double and boolean 2. casting to floating point type should consisder boolean types and int types --- be/src/vec/functions/function_cast.h | 27 ++++++- .../data/datatype_p0/json/json_cast.out | 37 ++++++++- .../json_p0/test_json_load_and_function.out | 76 +++++++++---------- ...test_json_load_unique_key_and_function.out | 64 ++++++++-------- .../jsonb_p0/test_jsonb_load_and_function.out | 76 +++++++++---------- ...est_jsonb_load_unique_key_and_function.out | 64 ++++++++-------- .../nereids_function_p0/scalar_function/J.out | 76 +++++++++---------- .../json_p0/test_json_load_and_function.out | 76 +++++++++---------- ...test_json_load_unique_key_and_function.out | 64 ++++++++-------- ...est_jsonb_load_unique_key_and_function.out | 64 ++++++++-------- .../suites/datatype_p0/json/json_cast.groovy | 14 ++++ 11 files changed, 354 insertions(+), 284 deletions(-) diff --git a/be/src/vec/functions/function_cast.h b/be/src/vec/functions/function_cast.h index af2fadc84c23e2..964dd8977c3714 100644 --- a/be/src/vec/functions/function_cast.h +++ b/be/src/vec/functions/function_cast.h @@ -856,12 +856,19 @@ struct ConvertImplFromJsonb { res[i] = 0; continue; } - if constexpr (type_index == TypeIndex::UInt8) { + // cast from json value to boolean type if (value->isTrue()) { res[i] = 1; } else if (value->isFalse()) { res[i] = 0; + } else if (value->isInt()) { + res[i] = ((const JsonbIntVal*)value)->val() == 0 ? 0 : 1; + } else if (value->isDouble()) { + res[i] = static_cast( + ((const JsonbDoubleVal*)value)->val()) == 0 + ? 0 + : 1; } else { null_map[i] = 1; res[i] = 0; @@ -871,15 +878,31 @@ struct ConvertImplFromJsonb { type_index == TypeIndex::Int32 || type_index == TypeIndex::Int64 || type_index == TypeIndex::Int128) { + // cast from json value to integer types if (value->isInt()) { res[i] = ((const JsonbIntVal*)value)->val(); + } else if (value->isDouble()) { + res[i] = static_cast( + ((const JsonbDoubleVal*)value)->val()); + } else if (value->isTrue()) { + res[i] = 1; + } else if (value->isFalse()) { + res[i] = 0; } else { null_map[i] = 1; res[i] = 0; } - } else if constexpr (type_index == TypeIndex::Float64) { + } else if constexpr (type_index == TypeIndex::Float64 || + type_index == TypeIndex::Float32) { + // cast from json value to floating point types if (value->isDouble()) { res[i] = ((const JsonbDoubleVal*)value)->val(); + } else if (value->isFloat()) { + res[i] = ((const JsonbFloatVal*)value)->val(); + } else if (value->isTrue()) { + res[i] = 1; + } else if (value->isFalse()) { + res[i] = 0; } else if (value->isInt()) { res[i] = ((const JsonbIntVal*)value)->val(); } else { diff --git a/regression-test/data/datatype_p0/json/json_cast.out b/regression-test/data/datatype_p0/json/json_cast.out index 8f58f45ce7405d..f7d9363df38df8 100644 --- a/regression-test/data/datatype_p0/json/json_cast.out +++ b/regression-test/data/datatype_p0/json/json_cast.out @@ -21,13 +21,13 @@ true -- !sql8 -- -\N +1000 -- !sql9 -- 1000.1111 -- !sql10 -- -\N +true -- !sql11 -- ["CXO0N: 1045901740","HMkTa: 1348450505","44 HHD: 915015173","j9WoJ: -1517316688"] @@ -53,3 +53,36 @@ true -- !sql18 -- \N +-- !sql19 -- +1 + +-- !sql19 -- +0 + +-- !sql20 -- +1.0 + +-- !sql20 -- +0.0 + +-- !sql21 -- +true + +-- !sql22 -- +1024.0 + +-- !sql23 -- +1024.0 + +-- !sql24 -- +1024.0 + +-- !sql24 -- +[1,2,3] + +-- !sql25 -- +[1,2,3] + +-- !sql26 -- +["2020-01-01"] + diff --git a/regression-test/data/json_p0/test_json_load_and_function.out b/regression-test/data/json_p0/test_json_load_and_function.out index b7e51e5acce202..27a99c8959b27f 100644 --- a/regression-test/data/json_p0/test_json_load_and_function.out +++ b/regression-test/data/json_p0/test_json_load_and_function.out @@ -5716,11 +5716,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5733,9 +5733,9 @@ 26 \N \N 27 {"k1":"v1","k2":200} \N 28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} \N -29 12524337771678448270 \N -30 -9223372036854775808 \N -31 18446744073709551615 \N +29 12524337771678448270 true +30 -9223372036854775808 true +31 18446744073709551615 true 32 {"":"v1"} \N 33 {"":1,"":"v1"} \N 34 {"":1,"ab":"v1","":"v1","":2} \N @@ -5743,13 +5743,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5772,13 +5772,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5801,13 +5801,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5830,8 +5830,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1.0 +4 false 0.0 5 100 100.0 6 10000 10000.0 7 1000000000 1.0E9 @@ -5890,11 +5890,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5907,9 +5907,9 @@ 26 \N \N 27 {"k1":"v1","k2":200} \N 28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} \N -29 12524337771678448270 \N -30 -9223372036854775808 \N -31 18446744073709551615 \N +29 12524337771678448270 true +30 -9223372036854775808 true +31 18446744073709551615 true 32 {"":"v1"} \N 33 {"":1,"":"v1"} \N 34 {"":1,"ab":"v1","":"v1","":2} \N @@ -5917,13 +5917,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5946,13 +5946,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5975,13 +5975,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -6004,8 +6004,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 diff --git a/regression-test/data/json_p0/test_json_load_unique_key_and_function.out b/regression-test/data/json_p0/test_json_load_unique_key_and_function.out index 3cb34304af49f3..a0a12b2c2769f5 100644 --- a/regression-test/data/json_p0/test_json_load_unique_key_and_function.out +++ b/regression-test/data/json_p0/test_json_load_unique_key_and_function.out @@ -3934,11 +3934,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -3955,13 +3955,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -3978,13 +3978,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4001,13 +4001,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4024,8 +4024,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1.0 +4 false 0.0 5 100 100.0 6 10000 10000.0 7 1000000000 1.0E9 @@ -4072,11 +4072,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4093,13 +4093,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4116,13 +4116,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4139,13 +4139,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4162,8 +4162,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 diff --git a/regression-test/data/jsonb_p0/test_jsonb_load_and_function.out b/regression-test/data/jsonb_p0/test_jsonb_load_and_function.out index 271083fbebaa0c..0c9753215c5591 100644 --- a/regression-test/data/jsonb_p0/test_jsonb_load_and_function.out +++ b/regression-test/data/jsonb_p0/test_jsonb_load_and_function.out @@ -7714,11 +7714,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7731,9 +7731,9 @@ 26 \N \N 27 {"k1":"v1","k2":200} \N 28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} \N -29 12524337771678448270 \N -30 -9223372036854775808 \N -31 18446744073709551615 \N +29 12524337771678448270 true +30 -9223372036854775808 true +31 18446744073709551615 true 32 {"":"v1"} \N 33 {"":1,"":"v1"} \N 34 {"":1,"ab":"v1","":"v1","":2} \N @@ -7741,13 +7741,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7770,13 +7770,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7799,13 +7799,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7828,8 +7828,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1.0 +4 false 0.0 5 100 100.0 6 10000 10000.0 7 1000000000 1.0E9 @@ -7888,11 +7888,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7905,9 +7905,9 @@ 26 \N \N 27 {"k1":"v1","k2":200} \N 28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} \N -29 12524337771678448270 \N -30 -9223372036854775808 \N -31 18446744073709551615 \N +29 12524337771678448270 true +30 -9223372036854775808 true +31 18446744073709551615 true 32 {"":"v1"} \N 33 {"":1,"":"v1"} \N 34 {"":1,"ab":"v1","":"v1","":2} \N @@ -7915,13 +7915,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7944,13 +7944,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7973,13 +7973,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -8002,8 +8002,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 diff --git a/regression-test/data/jsonb_p0/test_jsonb_load_unique_key_and_function.out b/regression-test/data/jsonb_p0/test_jsonb_load_unique_key_and_function.out index a9bec25de0904f..c699a010fc885b 100644 --- a/regression-test/data/jsonb_p0/test_jsonb_load_unique_key_and_function.out +++ b/regression-test/data/jsonb_p0/test_jsonb_load_unique_key_and_function.out @@ -5521,11 +5521,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5542,13 +5542,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5565,13 +5565,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5588,13 +5588,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5611,8 +5611,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1.0 +4 false 0.0 5 100 100.0 6 10000 10000.0 7 1000000000 1.0E9 @@ -5659,11 +5659,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5680,13 +5680,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5703,13 +5703,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5726,13 +5726,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5749,8 +5749,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 diff --git a/regression-test/data/nereids_function_p0/scalar_function/J.out b/regression-test/data/nereids_function_p0/scalar_function/J.out index 0994891dc715a7..41606ca51a741b 100644 --- a/regression-test/data/nereids_function_p0/scalar_function/J.out +++ b/regression-test/data/nereids_function_p0/scalar_function/J.out @@ -6914,11 +6914,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -6931,20 +6931,20 @@ 26 \N \N 27 {"k1":"v1","k2":200} \N 28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} \N -29 12524337771678448270 \N -30 -9223372036854775808 \N -31 18446744073709551615 \N +29 12524337771678448270 true +30 -9223372036854775808 true +31 18446744073709551615 true -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -6964,13 +6964,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -6990,13 +6990,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7016,8 +7016,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1.0 +4 false 0.0 5 100 100.0 6 10000 10000.0 7 1000000000 1.0E9 @@ -7070,11 +7070,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7087,20 +7087,20 @@ 26 \N \N 27 {"k1":"v1","k2":200} \N 28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} \N -29 12524337771678448270 \N -30 -9223372036854775808 \N -31 18446744073709551615 \N +29 12524337771678448270 true +30 -9223372036854775808 true +31 18446744073709551615 true -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7120,13 +7120,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7146,13 +7146,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -7172,8 +7172,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 diff --git a/regression-test/data/nereids_p0/json_p0/test_json_load_and_function.out b/regression-test/data/nereids_p0/json_p0/test_json_load_and_function.out index 17a8db24d33ce2..295685a8c050d6 100644 --- a/regression-test/data/nereids_p0/json_p0/test_json_load_and_function.out +++ b/regression-test/data/nereids_p0/json_p0/test_json_load_and_function.out @@ -5713,11 +5713,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5730,9 +5730,9 @@ 26 \N \N 27 {"k1":"v1","k2":200} \N 28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} \N -29 12524337771678448270 \N -30 -9223372036854775808 \N -31 18446744073709551615 \N +29 12524337771678448270 true +30 -9223372036854775808 true +31 18446744073709551615 true 32 {"":"v1"} \N 33 {"":1,"":"v1"} \N 34 {"":1,"ab":"v1","":"v1","":2} \N @@ -5740,13 +5740,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5769,13 +5769,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5798,13 +5798,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5827,8 +5827,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1.0 +4 false 0.0 5 100 100.0 6 10000 10000.0 7 1000000000 1.0E9 @@ -5887,11 +5887,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5904,9 +5904,9 @@ 26 \N \N 27 {"k1":"v1","k2":200} \N 28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} \N -29 12524337771678448270 \N -30 -9223372036854775808 \N -31 18446744073709551615 \N +29 12524337771678448270 true +30 -9223372036854775808 true +31 18446744073709551615 true 32 {"":"v1"} \N 33 {"":1,"":"v1"} \N 34 {"":1,"ab":"v1","":"v1","":2} \N @@ -5914,13 +5914,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5943,13 +5943,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5972,13 +5972,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -6001,8 +6001,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 diff --git a/regression-test/data/nereids_p0/json_p0/test_json_load_unique_key_and_function.out b/regression-test/data/nereids_p0/json_p0/test_json_load_unique_key_and_function.out index 3cb34304af49f3..a0a12b2c2769f5 100644 --- a/regression-test/data/nereids_p0/json_p0/test_json_load_unique_key_and_function.out +++ b/regression-test/data/nereids_p0/json_p0/test_json_load_unique_key_and_function.out @@ -3934,11 +3934,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -3955,13 +3955,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -3978,13 +3978,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4001,13 +4001,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4024,8 +4024,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1.0 +4 false 0.0 5 100 100.0 6 10000 10000.0 7 1000000000 1.0E9 @@ -4072,11 +4072,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4093,13 +4093,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4116,13 +4116,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4139,13 +4139,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -4162,8 +4162,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 diff --git a/regression-test/data/nereids_p0/jsonb_p0/test_jsonb_load_unique_key_and_function.out b/regression-test/data/nereids_p0/jsonb_p0/test_jsonb_load_unique_key_and_function.out index f69d695d455bb2..12e3742583c009 100644 --- a/regression-test/data/nereids_p0/jsonb_p0/test_jsonb_load_unique_key_and_function.out +++ b/regression-test/data/nereids_p0/jsonb_p0/test_jsonb_load_unique_key_and_function.out @@ -5521,11 +5521,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5542,13 +5542,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5565,13 +5565,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5588,13 +5588,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5611,8 +5611,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1.0 +4 false 0.0 5 100 100.0 6 10000 10000.0 7 1000000000 1.0E9 @@ -5659,11 +5659,11 @@ 2 null \N 3 true true 4 false false -5 100 \N -6 10000 \N -7 1000000000 \N -8 1152921504606846976 \N -9 6.18 \N +5 100 true +6 10000 true +7 1000000000 true +8 1152921504606846976 true +9 6.18 true 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5680,13 +5680,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 -13824 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5703,13 +5703,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 0 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5726,13 +5726,13 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 8 1152921504606846976 1152921504606846976 -9 6.18 \N +9 6.18 6 10 "abcd" \N 11 {} \N 12 {"k1":"v31","k2":300} \N @@ -5749,8 +5749,8 @@ -- !select -- 1 \N \N 2 null \N -3 true \N -4 false \N +3 true 1 +4 false 0 5 100 100 6 10000 10000 7 1000000000 1000000000 diff --git a/regression-test/suites/datatype_p0/json/json_cast.groovy b/regression-test/suites/datatype_p0/json/json_cast.groovy index 458c60992d905f..683d9740bdb93a 100644 --- a/regression-test/suites/datatype_p0/json/json_cast.groovy +++ b/regression-test/suites/datatype_p0/json/json_cast.groovy @@ -36,4 +36,18 @@ suite("test_json_type_cast", "p0") { qt_sql16 """select cast("-" as int);""" qt_sql17 """select cast("a" as int);""" qt_sql18 """select cast("/" as int);""" + + qt_sql19 "SELECT CAST(CAST(CAST(1 AS BOOLEAN) AS JSON) as INT)" + qt_sql19 "SELECT CAST(CAST(CAST(0 AS BOOLEAN) AS JSON) as INT)" + qt_sql20 "SELECT CAST(CAST(CAST(1 AS BOOLEAN) AS JSON) as DOUBLE)" + qt_sql20 "SELECT CAST(CAST(CAST(0 AS BOOLEAN) AS JSON) as DOUBLE)" + qt_sql21 "SELECT CAST(CAST(CAST(1 AS BOOLEAN) AS JSON) as BOOLEAN)" + + qt_sql22 "SELECT CAST(CAST(CAST(1024 AS INT) AS JSON) as DOUBLE)" + qt_sql23 "SELECT CAST(CAST(CAST(1024 AS INT) AS JSON) as FLOAT)" + qt_sql24 "SELECT CAST(CAST(CAST(1024.0 AS DOUBLE) AS JSON) as DOUBLE)" + + qt_sql24 "SELECT CAST(CAST(CAST('[1, 2, 3]' AS TEXT) AS JSON) as TEXT)" + qt_sql25 "SELECT CAST(CAST(CAST('[1, 2, 3]' AS TEXT) AS JSON) as TEXT)" + qt_sql26 """SELECT CAST(CAST(CAST('["2020-01-01"]' AS TEXT) AS JSON) as TEXT)""" } \ No newline at end of file