be/src/util/jsonb_document_cast.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "core/data_type/primitive_type.h" |
19 | | #include "core/types.h" |
20 | | #include "exprs/function/cast/cast_base.h" |
21 | | #include "exprs/function/cast/cast_to_basic_number_common.h" |
22 | | #include "exprs/function/cast/cast_to_boolean.h" |
23 | | #include "exprs/function/cast/cast_to_decimal.h" |
24 | | #include "util/jsonb_document.h" |
25 | | #include "util/jsonb_utils.h" |
26 | | namespace doris { |
27 | | |
28 | | struct JsonbCast { |
29 | 64 | static Status report_error(const JsonbValue* jsonb_value, PrimitiveType to_type) { |
30 | 64 | return Status::InvalidArgument("Cannot cast from jsonb value type {} to doris type {}", |
31 | 64 | JsonbToJson {}.to_json_string(jsonb_value), |
32 | 64 | type_to_string(to_type)); |
33 | 64 | } |
34 | | |
35 | | static bool cast_from_json_to_boolean(const JsonbValue* jsonb_value, UInt8& to, |
36 | 656 | CastParameters& params) { |
37 | 656 | switch (jsonb_value->type) { |
38 | 33 | case JsonbType::T_True: |
39 | 65 | case JsonbType::T_False: { |
40 | 65 | return CastToBool::from_number((UInt8)jsonb_value->isTrue(), to, params); |
41 | 33 | } |
42 | 58 | case JsonbType::T_Int8: { |
43 | 58 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); |
44 | 58 | return CastToBool::from_number(val, to, params); |
45 | 33 | } |
46 | 50 | case JsonbType::T_Int16: { |
47 | 50 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); |
48 | 50 | return CastToBool::from_number(val, to, params); |
49 | 33 | } |
50 | 26 | case JsonbType::T_Int32: { |
51 | 26 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); |
52 | 26 | return CastToBool::from_number(val, to, params); |
53 | 33 | } |
54 | 41 | case JsonbType::T_Int64: { |
55 | 41 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); |
56 | 41 | return CastToBool::from_number(val, to, params); |
57 | 33 | } |
58 | 31 | case JsonbType::T_Int128: { |
59 | 31 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); |
60 | 31 | return CastToBool::from_number(val, to, params); |
61 | 33 | } |
62 | 51 | case JsonbType::T_Double: { |
63 | 51 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); |
64 | 51 | return CastToBool::from_number(val, to, params); |
65 | 33 | } |
66 | 1 | case JsonbType::T_Float: { |
67 | 1 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); |
68 | 1 | return CastToBool::from_number(val, to, params); |
69 | 33 | } |
70 | 2 | case JsonbType::T_Decimal32: { |
71 | 2 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); |
72 | 2 | UInt32 precision = jsonb_value->unpack<JsonbDecimal32>()->precision; |
73 | 2 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; |
74 | 2 | return CastToBool::from_decimal(Decimal32 {val}, to, precision, scale, params); |
75 | 33 | } |
76 | 1 | case JsonbType::T_Decimal64: { |
77 | 1 | auto val = jsonb_value->unpack<JsonbDecimal64>()->val(); |
78 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal64>()->precision; |
79 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal64>()->scale; |
80 | 1 | return CastToBool::from_decimal(Decimal64 {val}, to, precision, scale, params); |
81 | 33 | } |
82 | 1 | case JsonbType::T_Decimal128: { |
83 | 1 | auto val = jsonb_value->unpack<JsonbDecimal128>()->val(); |
84 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal128>()->precision; |
85 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal128>()->scale; |
86 | 1 | return CastToBool::from_decimal(Decimal128V3 {val}, to, precision, scale, params); |
87 | 33 | } |
88 | 1 | case JsonbType::T_Decimal256: { |
89 | 1 | auto val = jsonb_value->unpack<JsonbDecimal256>()->val(); |
90 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal256>()->precision; |
91 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal256>()->scale; |
92 | 1 | return CastToBool::from_decimal(Decimal256 {val}, to, precision, scale, params); |
93 | 33 | } |
94 | 74 | case JsonbType::T_String: { |
95 | 74 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); |
96 | 74 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; |
97 | 74 | return CastToBool::from_string(str_ref, to, params); |
98 | 33 | } |
99 | 254 | default: { |
100 | 254 | return false; |
101 | 33 | } |
102 | 656 | } |
103 | 656 | } |
104 | | |
105 | | template <typename T> |
106 | | static bool cast_from_json_to_int(const JsonbValue* jsonb_value, T& to, |
107 | 101k | CastParameters& params) { |
108 | 101k | switch (jsonb_value->type) { |
109 | 94 | case JsonbType::T_True: |
110 | 188 | case JsonbType::T_False: { |
111 | 188 | auto val = (UInt8)jsonb_value->isTrue(); |
112 | 188 | return CastToInt::from_bool(val, to, params); |
113 | 94 | } |
114 | 324 | case JsonbType::T_Int8: { |
115 | 324 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); |
116 | 324 | return CastToInt::from_int(val, to, params); |
117 | 94 | } |
118 | 144 | case JsonbType::T_Int16: { |
119 | 144 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); |
120 | 144 | return CastToInt::from_int(val, to, params); |
121 | 94 | } |
122 | 92 | case JsonbType::T_Int32: { |
123 | 92 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); |
124 | 92 | return CastToInt::from_int(val, to, params); |
125 | 94 | } |
126 | 99.3k | case JsonbType::T_Int64: { |
127 | 99.3k | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); |
128 | 99.3k | return CastToInt::from_int(val, to, params); |
129 | 94 | } |
130 | 102 | case JsonbType::T_Int128: { |
131 | 102 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); |
132 | 102 | return CastToInt::from_int(val, to, params); |
133 | 94 | } |
134 | 191 | case JsonbType::T_Double: { |
135 | 191 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); |
136 | 191 | return CastToInt::from_float(val, to, params); |
137 | 94 | } |
138 | 1 | case JsonbType::T_Float: { |
139 | 1 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); |
140 | 1 | return CastToInt::from_float(val, to, params); |
141 | 94 | } |
142 | 2 | case JsonbType::T_Decimal32: { |
143 | 2 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); |
144 | 2 | UInt32 precision = jsonb_value->unpack<JsonbDecimal32>()->precision; |
145 | 2 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; |
146 | 2 | return CastToInt::from_decimal(Decimal32 {val}, precision, scale, to, params); |
147 | 94 | } |
148 | 1 | case JsonbType::T_Decimal64: { |
149 | 1 | auto val = jsonb_value->unpack<JsonbDecimal64>()->val(); |
150 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal64>()->precision; |
151 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal64>()->scale; |
152 | 1 | return CastToInt::from_decimal(Decimal64 {val}, precision, scale, to, params); |
153 | 94 | } |
154 | 1 | case JsonbType::T_Decimal128: { |
155 | 1 | auto val = jsonb_value->unpack<JsonbDecimal128>()->val(); |
156 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal128>()->precision; |
157 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal128>()->scale; |
158 | 1 | return CastToInt::from_decimal(Decimal128V3 {val}, precision, scale, to, params); |
159 | 94 | } |
160 | 1 | case JsonbType::T_Decimal256: { |
161 | 1 | auto val = jsonb_value->unpack<JsonbDecimal256>()->val(); |
162 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal256>()->precision; |
163 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal256>()->scale; |
164 | 1 | return CastToInt::from_decimal(Decimal256 {val}, precision, scale, to, params); |
165 | 94 | } |
166 | 537 | case JsonbType::T_String: { |
167 | 537 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); |
168 | 537 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; |
169 | 537 | return std::visit( |
170 | 537 | [&](auto is_strict_mode) { |
171 | 537 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); |
172 | 537 | }, _ZZN5doris9JsonbCast21cast_from_json_to_intIaEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb0EEEEDaS5_ Line | Count | Source | 170 | 101 | [&](auto is_strict_mode) { | 171 | 101 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 101 | }, |
Unexecuted instantiation: _ZZN5doris9JsonbCast21cast_from_json_to_intIaEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb1EEEEDaS5_ _ZZN5doris9JsonbCast21cast_from_json_to_intIsEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb0EEEEDaS5_ Line | Count | Source | 170 | 11 | [&](auto is_strict_mode) { | 171 | 11 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 11 | }, |
Unexecuted instantiation: _ZZN5doris9JsonbCast21cast_from_json_to_intIsEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb1EEEEDaS5_ _ZZN5doris9JsonbCast21cast_from_json_to_intIiEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb0EEEEDaS5_ Line | Count | Source | 170 | 298 | [&](auto is_strict_mode) { | 171 | 298 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 298 | }, |
_ZZN5doris9JsonbCast21cast_from_json_to_intIiEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb1EEEEDaS5_ Line | Count | Source | 170 | 2 | [&](auto is_strict_mode) { | 171 | 2 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 2 | }, |
_ZZN5doris9JsonbCast21cast_from_json_to_intIlEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb0EEEEDaS5_ Line | Count | Source | 170 | 81 | [&](auto is_strict_mode) { | 171 | 81 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 81 | }, |
Unexecuted instantiation: _ZZN5doris9JsonbCast21cast_from_json_to_intIlEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb1EEEEDaS5_ _ZZN5doris9JsonbCast21cast_from_json_to_intInEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb0EEEEDaS5_ Line | Count | Source | 170 | 44 | [&](auto is_strict_mode) { | 171 | 44 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 44 | }, |
Unexecuted instantiation: _ZZN5doris9JsonbCast21cast_from_json_to_intInEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb1EEEEDaS5_ |
173 | 537 | make_bool_variant(params.is_strict)); |
174 | 94 | } |
175 | 771 | default: { |
176 | 771 | return false; |
177 | 94 | } |
178 | 101k | } |
179 | 101k | } _ZN5doris9JsonbCast21cast_from_json_to_intIaEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 107 | 1.30k | CastParameters& params) { | 108 | 1.30k | switch (jsonb_value->type) { | 109 | 4 | case JsonbType::T_True: | 110 | 8 | case JsonbType::T_False: { | 111 | 8 | auto val = (UInt8)jsonb_value->isTrue(); | 112 | 8 | return CastToInt::from_bool(val, to, params); | 113 | 4 | } | 114 | 4 | case JsonbType::T_Int8: { | 115 | 4 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 116 | 4 | return CastToInt::from_int(val, to, params); | 117 | 4 | } | 118 | 3 | case JsonbType::T_Int16: { | 119 | 3 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 120 | 3 | return CastToInt::from_int(val, to, params); | 121 | 4 | } | 122 | 4 | case JsonbType::T_Int32: { | 123 | 4 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 124 | 4 | return CastToInt::from_int(val, to, params); | 125 | 4 | } | 126 | 1.17k | case JsonbType::T_Int64: { | 127 | 1.17k | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 128 | 1.17k | return CastToInt::from_int(val, to, params); | 129 | 4 | } | 130 | 2 | case JsonbType::T_Int128: { | 131 | 2 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 132 | 2 | return CastToInt::from_int(val, to, params); | 133 | 4 | } | 134 | 1 | case JsonbType::T_Double: { | 135 | 1 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); | 136 | 1 | return CastToInt::from_float(val, to, params); | 137 | 4 | } | 138 | 0 | case JsonbType::T_Float: { | 139 | 0 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); | 140 | 0 | return CastToInt::from_float(val, to, params); | 141 | 4 | } | 142 | 0 | case JsonbType::T_Decimal32: { | 143 | 0 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); | 144 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal32>()->precision; | 145 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; | 146 | 0 | return CastToInt::from_decimal(Decimal32 {val}, precision, scale, to, params); | 147 | 4 | } | 148 | 0 | case JsonbType::T_Decimal64: { | 149 | 0 | auto val = jsonb_value->unpack<JsonbDecimal64>()->val(); | 150 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal64>()->precision; | 151 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal64>()->scale; | 152 | 0 | return CastToInt::from_decimal(Decimal64 {val}, precision, scale, to, params); | 153 | 4 | } | 154 | 0 | case JsonbType::T_Decimal128: { | 155 | 0 | auto val = jsonb_value->unpack<JsonbDecimal128>()->val(); | 156 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal128>()->precision; | 157 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal128>()->scale; | 158 | 0 | return CastToInt::from_decimal(Decimal128V3 {val}, precision, scale, to, params); | 159 | 4 | } | 160 | 0 | case JsonbType::T_Decimal256: { | 161 | 0 | auto val = jsonb_value->unpack<JsonbDecimal256>()->val(); | 162 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal256>()->precision; | 163 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal256>()->scale; | 164 | 0 | return CastToInt::from_decimal(Decimal256 {val}, precision, scale, to, params); | 165 | 4 | } | 166 | 101 | case JsonbType::T_String: { | 167 | 101 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 168 | 101 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 169 | 101 | return std::visit( | 170 | 101 | [&](auto is_strict_mode) { | 171 | 101 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 101 | }, | 173 | 101 | make_bool_variant(params.is_strict)); | 174 | 4 | } | 175 | 10 | default: { | 176 | 10 | return false; | 177 | 4 | } | 178 | 1.30k | } | 179 | 1.30k | } |
_ZN5doris9JsonbCast21cast_from_json_to_intIsEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 107 | 245 | CastParameters& params) { | 108 | 245 | switch (jsonb_value->type) { | 109 | 13 | case JsonbType::T_True: | 110 | 26 | case JsonbType::T_False: { | 111 | 26 | auto val = (UInt8)jsonb_value->isTrue(); | 112 | 26 | return CastToInt::from_bool(val, to, params); | 113 | 13 | } | 114 | 13 | case JsonbType::T_Int8: { | 115 | 13 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 116 | 13 | return CastToInt::from_int(val, to, params); | 117 | 13 | } | 118 | 14 | case JsonbType::T_Int16: { | 119 | 14 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 120 | 14 | return CastToInt::from_int(val, to, params); | 121 | 13 | } | 122 | 14 | case JsonbType::T_Int32: { | 123 | 14 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 124 | 14 | return CastToInt::from_int(val, to, params); | 125 | 13 | } | 126 | 20 | case JsonbType::T_Int64: { | 127 | 20 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 128 | 20 | return CastToInt::from_int(val, to, params); | 129 | 13 | } | 130 | 14 | case JsonbType::T_Int128: { | 131 | 14 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 132 | 14 | return CastToInt::from_int(val, to, params); | 133 | 13 | } | 134 | 11 | case JsonbType::T_Double: { | 135 | 11 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); | 136 | 11 | return CastToInt::from_float(val, to, params); | 137 | 13 | } | 138 | 0 | case JsonbType::T_Float: { | 139 | 0 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); | 140 | 0 | return CastToInt::from_float(val, to, params); | 141 | 13 | } | 142 | 0 | case JsonbType::T_Decimal32: { | 143 | 0 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); | 144 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal32>()->precision; | 145 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; | 146 | 0 | return CastToInt::from_decimal(Decimal32 {val}, precision, scale, to, params); | 147 | 13 | } | 148 | 0 | case JsonbType::T_Decimal64: { | 149 | 0 | auto val = jsonb_value->unpack<JsonbDecimal64>()->val(); | 150 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal64>()->precision; | 151 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal64>()->scale; | 152 | 0 | return CastToInt::from_decimal(Decimal64 {val}, precision, scale, to, params); | 153 | 13 | } | 154 | 0 | case JsonbType::T_Decimal128: { | 155 | 0 | auto val = jsonb_value->unpack<JsonbDecimal128>()->val(); | 156 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal128>()->precision; | 157 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal128>()->scale; | 158 | 0 | return CastToInt::from_decimal(Decimal128V3 {val}, precision, scale, to, params); | 159 | 13 | } | 160 | 0 | case JsonbType::T_Decimal256: { | 161 | 0 | auto val = jsonb_value->unpack<JsonbDecimal256>()->val(); | 162 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal256>()->precision; | 163 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal256>()->scale; | 164 | 0 | return CastToInt::from_decimal(Decimal256 {val}, precision, scale, to, params); | 165 | 13 | } | 166 | 11 | case JsonbType::T_String: { | 167 | 11 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 168 | 11 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 169 | 11 | return std::visit( | 170 | 11 | [&](auto is_strict_mode) { | 171 | 11 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 11 | }, | 173 | 11 | make_bool_variant(params.is_strict)); | 174 | 13 | } | 175 | 122 | default: { | 176 | 122 | return false; | 177 | 13 | } | 178 | 245 | } | 179 | 245 | } |
_ZN5doris9JsonbCast21cast_from_json_to_intIiEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 107 | 98.0k | CastParameters& params) { | 108 | 98.0k | switch (jsonb_value->type) { | 109 | 32 | case JsonbType::T_True: | 110 | 64 | case JsonbType::T_False: { | 111 | 64 | auto val = (UInt8)jsonb_value->isTrue(); | 112 | 64 | return CastToInt::from_bool(val, to, params); | 113 | 32 | } | 114 | 117 | case JsonbType::T_Int8: { | 115 | 117 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 116 | 117 | return CastToInt::from_int(val, to, params); | 117 | 32 | } | 118 | 52 | case JsonbType::T_Int16: { | 119 | 52 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 120 | 52 | return CastToInt::from_int(val, to, params); | 121 | 32 | } | 122 | 37 | case JsonbType::T_Int32: { | 123 | 37 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 124 | 37 | return CastToInt::from_int(val, to, params); | 125 | 32 | } | 126 | 97.0k | case JsonbType::T_Int64: { | 127 | 97.0k | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 128 | 97.0k | return CastToInt::from_int(val, to, params); | 129 | 32 | } | 130 | 30 | case JsonbType::T_Int128: { | 131 | 30 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 132 | 30 | return CastToInt::from_int(val, to, params); | 133 | 32 | } | 134 | 86 | case JsonbType::T_Double: { | 135 | 86 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); | 136 | 86 | return CastToInt::from_float(val, to, params); | 137 | 32 | } | 138 | 1 | case JsonbType::T_Float: { | 139 | 1 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); | 140 | 1 | return CastToInt::from_float(val, to, params); | 141 | 32 | } | 142 | 2 | case JsonbType::T_Decimal32: { | 143 | 2 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); | 144 | 2 | UInt32 precision = jsonb_value->unpack<JsonbDecimal32>()->precision; | 145 | 2 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; | 146 | 2 | return CastToInt::from_decimal(Decimal32 {val}, precision, scale, to, params); | 147 | 32 | } | 148 | 0 | case JsonbType::T_Decimal64: { | 149 | 0 | auto val = jsonb_value->unpack<JsonbDecimal64>()->val(); | 150 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal64>()->precision; | 151 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal64>()->scale; | 152 | 0 | return CastToInt::from_decimal(Decimal64 {val}, precision, scale, to, params); | 153 | 32 | } | 154 | 0 | case JsonbType::T_Decimal128: { | 155 | 0 | auto val = jsonb_value->unpack<JsonbDecimal128>()->val(); | 156 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal128>()->precision; | 157 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal128>()->scale; | 158 | 0 | return CastToInt::from_decimal(Decimal128V3 {val}, precision, scale, to, params); | 159 | 32 | } | 160 | 0 | case JsonbType::T_Decimal256: { | 161 | 0 | auto val = jsonb_value->unpack<JsonbDecimal256>()->val(); | 162 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal256>()->precision; | 163 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal256>()->scale; | 164 | 0 | return CastToInt::from_decimal(Decimal256 {val}, precision, scale, to, params); | 165 | 32 | } | 166 | 300 | case JsonbType::T_String: { | 167 | 300 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 168 | 300 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 169 | 300 | return std::visit( | 170 | 300 | [&](auto is_strict_mode) { | 171 | 300 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 300 | }, | 173 | 300 | make_bool_variant(params.is_strict)); | 174 | 32 | } | 175 | 291 | default: { | 176 | 291 | return false; | 177 | 32 | } | 178 | 98.0k | } | 179 | 98.0k | } |
_ZN5doris9JsonbCast21cast_from_json_to_intIlEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 107 | 1.79k | CastParameters& params) { | 108 | 1.79k | switch (jsonb_value->type) { | 109 | 31 | case JsonbType::T_True: | 110 | 62 | case JsonbType::T_False: { | 111 | 62 | auto val = (UInt8)jsonb_value->isTrue(); | 112 | 62 | return CastToInt::from_bool(val, to, params); | 113 | 31 | } | 114 | 160 | case JsonbType::T_Int8: { | 115 | 160 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 116 | 160 | return CastToInt::from_int(val, to, params); | 117 | 31 | } | 118 | 49 | case JsonbType::T_Int16: { | 119 | 49 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 120 | 49 | return CastToInt::from_int(val, to, params); | 121 | 31 | } | 122 | 27 | case JsonbType::T_Int32: { | 123 | 27 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 124 | 27 | return CastToInt::from_int(val, to, params); | 125 | 31 | } | 126 | 1.07k | case JsonbType::T_Int64: { | 127 | 1.07k | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 128 | 1.07k | return CastToInt::from_int(val, to, params); | 129 | 31 | } | 130 | 37 | case JsonbType::T_Int128: { | 131 | 37 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 132 | 37 | return CastToInt::from_int(val, to, params); | 133 | 31 | } | 134 | 61 | case JsonbType::T_Double: { | 135 | 61 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); | 136 | 61 | return CastToInt::from_float(val, to, params); | 137 | 31 | } | 138 | 0 | case JsonbType::T_Float: { | 139 | 0 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); | 140 | 0 | return CastToInt::from_float(val, to, params); | 141 | 31 | } | 142 | 0 | case JsonbType::T_Decimal32: { | 143 | 0 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); | 144 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal32>()->precision; | 145 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; | 146 | 0 | return CastToInt::from_decimal(Decimal32 {val}, precision, scale, to, params); | 147 | 31 | } | 148 | 1 | case JsonbType::T_Decimal64: { | 149 | 1 | auto val = jsonb_value->unpack<JsonbDecimal64>()->val(); | 150 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal64>()->precision; | 151 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal64>()->scale; | 152 | 1 | return CastToInt::from_decimal(Decimal64 {val}, precision, scale, to, params); | 153 | 31 | } | 154 | 0 | case JsonbType::T_Decimal128: { | 155 | 0 | auto val = jsonb_value->unpack<JsonbDecimal128>()->val(); | 156 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal128>()->precision; | 157 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal128>()->scale; | 158 | 0 | return CastToInt::from_decimal(Decimal128V3 {val}, precision, scale, to, params); | 159 | 31 | } | 160 | 0 | case JsonbType::T_Decimal256: { | 161 | 0 | auto val = jsonb_value->unpack<JsonbDecimal256>()->val(); | 162 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal256>()->precision; | 163 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal256>()->scale; | 164 | 0 | return CastToInt::from_decimal(Decimal256 {val}, precision, scale, to, params); | 165 | 31 | } | 166 | 81 | case JsonbType::T_String: { | 167 | 81 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 168 | 81 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 169 | 81 | return std::visit( | 170 | 81 | [&](auto is_strict_mode) { | 171 | 81 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 81 | }, | 173 | 81 | make_bool_variant(params.is_strict)); | 174 | 31 | } | 175 | 251 | default: { | 176 | 251 | return false; | 177 | 31 | } | 178 | 1.79k | } | 179 | 1.79k | } |
_ZN5doris9JsonbCast21cast_from_json_to_intInEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 107 | 306 | CastParameters& params) { | 108 | 306 | switch (jsonb_value->type) { | 109 | 14 | case JsonbType::T_True: | 110 | 28 | case JsonbType::T_False: { | 111 | 28 | auto val = (UInt8)jsonb_value->isTrue(); | 112 | 28 | return CastToInt::from_bool(val, to, params); | 113 | 14 | } | 114 | 30 | case JsonbType::T_Int8: { | 115 | 30 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 116 | 30 | return CastToInt::from_int(val, to, params); | 117 | 14 | } | 118 | 26 | case JsonbType::T_Int16: { | 119 | 26 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 120 | 26 | return CastToInt::from_int(val, to, params); | 121 | 14 | } | 122 | 10 | case JsonbType::T_Int32: { | 123 | 10 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 124 | 10 | return CastToInt::from_int(val, to, params); | 125 | 14 | } | 126 | 18 | case JsonbType::T_Int64: { | 127 | 18 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 128 | 18 | return CastToInt::from_int(val, to, params); | 129 | 14 | } | 130 | 19 | case JsonbType::T_Int128: { | 131 | 19 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 132 | 19 | return CastToInt::from_int(val, to, params); | 133 | 14 | } | 134 | 32 | case JsonbType::T_Double: { | 135 | 32 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); | 136 | 32 | return CastToInt::from_float(val, to, params); | 137 | 14 | } | 138 | 0 | case JsonbType::T_Float: { | 139 | 0 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); | 140 | 0 | return CastToInt::from_float(val, to, params); | 141 | 14 | } | 142 | 0 | case JsonbType::T_Decimal32: { | 143 | 0 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); | 144 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal32>()->precision; | 145 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; | 146 | 0 | return CastToInt::from_decimal(Decimal32 {val}, precision, scale, to, params); | 147 | 14 | } | 148 | 0 | case JsonbType::T_Decimal64: { | 149 | 0 | auto val = jsonb_value->unpack<JsonbDecimal64>()->val(); | 150 | 0 | UInt32 precision = jsonb_value->unpack<JsonbDecimal64>()->precision; | 151 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal64>()->scale; | 152 | 0 | return CastToInt::from_decimal(Decimal64 {val}, precision, scale, to, params); | 153 | 14 | } | 154 | 1 | case JsonbType::T_Decimal128: { | 155 | 1 | auto val = jsonb_value->unpack<JsonbDecimal128>()->val(); | 156 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal128>()->precision; | 157 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal128>()->scale; | 158 | 1 | return CastToInt::from_decimal(Decimal128V3 {val}, precision, scale, to, params); | 159 | 14 | } | 160 | 1 | case JsonbType::T_Decimal256: { | 161 | 1 | auto val = jsonb_value->unpack<JsonbDecimal256>()->val(); | 162 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal256>()->precision; | 163 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal256>()->scale; | 164 | 1 | return CastToInt::from_decimal(Decimal256 {val}, precision, scale, to, params); | 165 | 14 | } | 166 | 44 | case JsonbType::T_String: { | 167 | 44 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 168 | 44 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 169 | 44 | return std::visit( | 170 | 44 | [&](auto is_strict_mode) { | 171 | 44 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 44 | }, | 173 | 44 | make_bool_variant(params.is_strict)); | 174 | 14 | } | 175 | 97 | default: { | 176 | 97 | return false; | 177 | 14 | } | 178 | 306 | } | 179 | 306 | } |
|
180 | | |
181 | | template <typename T> |
182 | | static bool cast_from_json_to_float(const JsonbValue* jsonb_value, T& to, |
183 | 1.05k | CastParameters& params) { |
184 | 1.05k | switch (jsonb_value->type) { |
185 | 35 | case JsonbType::T_True: |
186 | 70 | case JsonbType::T_False: { |
187 | 70 | auto val = (UInt8)jsonb_value->isTrue(); |
188 | 70 | return CastToFloat::from_bool(val, to, params); |
189 | 35 | } |
190 | 118 | case JsonbType::T_Int8: { |
191 | 118 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); |
192 | 118 | return CastToFloat::from_int(val, to, params); |
193 | 35 | } |
194 | 127 | case JsonbType::T_Int16: { |
195 | 127 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); |
196 | 127 | return CastToFloat::from_int(val, to, params); |
197 | 35 | } |
198 | 34 | case JsonbType::T_Int32: { |
199 | 34 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); |
200 | 34 | return CastToFloat::from_int(val, to, params); |
201 | 35 | } |
202 | 47 | case JsonbType::T_Int64: { |
203 | 47 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); |
204 | 47 | return CastToFloat::from_int(val, to, params); |
205 | 35 | } |
206 | 33 | case JsonbType::T_Int128: { |
207 | 33 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); |
208 | 33 | return CastToFloat::from_int(val, to, params); |
209 | 35 | } |
210 | 289 | case JsonbType::T_Double: { |
211 | 289 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); |
212 | 289 | return CastToFloat::from_float(val, to, params); |
213 | 35 | } |
214 | 2 | case JsonbType::T_Float: { |
215 | 2 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); |
216 | 2 | return CastToFloat::from_float(val, to, params); |
217 | 35 | } |
218 | 2 | case JsonbType::T_Decimal32: { |
219 | 2 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); |
220 | 2 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; |
221 | 2 | return CastToFloat::from_decimal(Decimal32 {val}, scale, to, params); |
222 | 35 | } |
223 | 1 | case JsonbType::T_Decimal64: { |
224 | 1 | auto val = jsonb_value->unpack<JsonbDecimal64>()->val(); |
225 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal64>()->scale; |
226 | 1 | return CastToFloat::from_decimal(Decimal64 {val}, scale, to, params); |
227 | 35 | } |
228 | 2 | case JsonbType::T_Decimal128: { |
229 | 2 | auto val = jsonb_value->unpack<JsonbDecimal128>()->val(); |
230 | 2 | UInt32 scale = jsonb_value->unpack<JsonbDecimal128>()->scale; |
231 | 2 | return CastToFloat::from_decimal(Decimal128V3 {val}, scale, to, params); |
232 | 35 | } |
233 | 1 | case JsonbType::T_Decimal256: { |
234 | 1 | auto val = jsonb_value->unpack<JsonbDecimal256>()->val(); |
235 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal256>()->scale; |
236 | 1 | return CastToFloat::from_decimal(Decimal256 {val}, scale, to, params); |
237 | 35 | } |
238 | 75 | case JsonbType::T_String: { |
239 | 75 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); |
240 | 75 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; |
241 | 75 | return CastToFloat::from_string(str_ref, to, params); |
242 | 35 | } |
243 | 254 | default: { |
244 | 254 | return false; |
245 | 35 | } |
246 | 1.05k | } |
247 | 1.05k | } _ZN5doris9JsonbCast23cast_from_json_to_floatIfEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 183 | 32 | CastParameters& params) { | 184 | 32 | switch (jsonb_value->type) { | 185 | 3 | case JsonbType::T_True: | 186 | 6 | case JsonbType::T_False: { | 187 | 6 | auto val = (UInt8)jsonb_value->isTrue(); | 188 | 6 | return CastToFloat::from_bool(val, to, params); | 189 | 3 | } | 190 | 3 | case JsonbType::T_Int8: { | 191 | 3 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 192 | 3 | return CastToFloat::from_int(val, to, params); | 193 | 3 | } | 194 | 3 | case JsonbType::T_Int16: { | 195 | 3 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 196 | 3 | return CastToFloat::from_int(val, to, params); | 197 | 3 | } | 198 | 4 | case JsonbType::T_Int32: { | 199 | 4 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 200 | 4 | return CastToFloat::from_int(val, to, params); | 201 | 3 | } | 202 | 3 | case JsonbType::T_Int64: { | 203 | 3 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 204 | 3 | return CastToFloat::from_int(val, to, params); | 205 | 3 | } | 206 | 3 | case JsonbType::T_Int128: { | 207 | 3 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 208 | 3 | return CastToFloat::from_int(val, to, params); | 209 | 3 | } | 210 | 1 | case JsonbType::T_Double: { | 211 | 1 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); | 212 | 1 | return CastToFloat::from_float(val, to, params); | 213 | 3 | } | 214 | 2 | case JsonbType::T_Float: { | 215 | 2 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); | 216 | 2 | return CastToFloat::from_float(val, to, params); | 217 | 3 | } | 218 | 1 | case JsonbType::T_Decimal32: { | 219 | 1 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); | 220 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; | 221 | 1 | return CastToFloat::from_decimal(Decimal32 {val}, scale, to, params); | 222 | 3 | } | 223 | 1 | case JsonbType::T_Decimal64: { | 224 | 1 | auto val = jsonb_value->unpack<JsonbDecimal64>()->val(); | 225 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal64>()->scale; | 226 | 1 | return CastToFloat::from_decimal(Decimal64 {val}, scale, to, params); | 227 | 3 | } | 228 | 1 | case JsonbType::T_Decimal128: { | 229 | 1 | auto val = jsonb_value->unpack<JsonbDecimal128>()->val(); | 230 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal128>()->scale; | 231 | 1 | return CastToFloat::from_decimal(Decimal128V3 {val}, scale, to, params); | 232 | 3 | } | 233 | 1 | case JsonbType::T_Decimal256: { | 234 | 1 | auto val = jsonb_value->unpack<JsonbDecimal256>()->val(); | 235 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal256>()->scale; | 236 | 1 | return CastToFloat::from_decimal(Decimal256 {val}, scale, to, params); | 237 | 3 | } | 238 | 0 | case JsonbType::T_String: { | 239 | 0 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 240 | 0 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 241 | 0 | return CastToFloat::from_string(str_ref, to, params); | 242 | 3 | } | 243 | 3 | default: { | 244 | 3 | return false; | 245 | 3 | } | 246 | 32 | } | 247 | 32 | } |
_ZN5doris9JsonbCast23cast_from_json_to_floatIdEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 183 | 1.02k | CastParameters& params) { | 184 | 1.02k | switch (jsonb_value->type) { | 185 | 32 | case JsonbType::T_True: | 186 | 64 | case JsonbType::T_False: { | 187 | 64 | auto val = (UInt8)jsonb_value->isTrue(); | 188 | 64 | return CastToFloat::from_bool(val, to, params); | 189 | 32 | } | 190 | 115 | case JsonbType::T_Int8: { | 191 | 115 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 192 | 115 | return CastToFloat::from_int(val, to, params); | 193 | 32 | } | 194 | 124 | case JsonbType::T_Int16: { | 195 | 124 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 196 | 124 | return CastToFloat::from_int(val, to, params); | 197 | 32 | } | 198 | 30 | case JsonbType::T_Int32: { | 199 | 30 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 200 | 30 | return CastToFloat::from_int(val, to, params); | 201 | 32 | } | 202 | 44 | case JsonbType::T_Int64: { | 203 | 44 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 204 | 44 | return CastToFloat::from_int(val, to, params); | 205 | 32 | } | 206 | 30 | case JsonbType::T_Int128: { | 207 | 30 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 208 | 30 | return CastToFloat::from_int(val, to, params); | 209 | 32 | } | 210 | 288 | case JsonbType::T_Double: { | 211 | 288 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); | 212 | 288 | return CastToFloat::from_float(val, to, params); | 213 | 32 | } | 214 | 0 | case JsonbType::T_Float: { | 215 | 0 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); | 216 | 0 | return CastToFloat::from_float(val, to, params); | 217 | 32 | } | 218 | 1 | case JsonbType::T_Decimal32: { | 219 | 1 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); | 220 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; | 221 | 1 | return CastToFloat::from_decimal(Decimal32 {val}, scale, to, params); | 222 | 32 | } | 223 | 0 | case JsonbType::T_Decimal64: { | 224 | 0 | auto val = jsonb_value->unpack<JsonbDecimal64>()->val(); | 225 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal64>()->scale; | 226 | 0 | return CastToFloat::from_decimal(Decimal64 {val}, scale, to, params); | 227 | 32 | } | 228 | 1 | case JsonbType::T_Decimal128: { | 229 | 1 | auto val = jsonb_value->unpack<JsonbDecimal128>()->val(); | 230 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal128>()->scale; | 231 | 1 | return CastToFloat::from_decimal(Decimal128V3 {val}, scale, to, params); | 232 | 32 | } | 233 | 0 | case JsonbType::T_Decimal256: { | 234 | 0 | auto val = jsonb_value->unpack<JsonbDecimal256>()->val(); | 235 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal256>()->scale; | 236 | 0 | return CastToFloat::from_decimal(Decimal256 {val}, scale, to, params); | 237 | 32 | } | 238 | 75 | case JsonbType::T_String: { | 239 | 75 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 240 | 75 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 241 | 75 | return CastToFloat::from_string(str_ref, to, params); | 242 | 32 | } | 243 | 251 | default: { | 244 | 251 | return false; | 245 | 32 | } | 246 | 1.02k | } | 247 | 1.02k | } |
|
248 | | |
249 | | template <typename T> |
250 | | static bool cast_from_json_to_decimal(const JsonbValue* jsonb_value, T& to, UInt32 to_precision, |
251 | 30 | UInt32 to_scale, CastParameters& params) { |
252 | 30 | switch (jsonb_value->type) { |
253 | 3 | case JsonbType::T_True: |
254 | 6 | case JsonbType::T_False: { |
255 | 6 | UInt8 val = jsonb_value->isTrue(); |
256 | 6 | return CastToDecimal::from_bool(val, to, to_precision, to_scale, params); |
257 | 3 | } |
258 | 3 | case JsonbType::T_Int8: { |
259 | 3 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); |
260 | 3 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); |
261 | 3 | } |
262 | 3 | case JsonbType::T_Int16: { |
263 | 3 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); |
264 | 3 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); |
265 | 3 | } |
266 | 3 | case JsonbType::T_Int32: { |
267 | 3 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); |
268 | 3 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); |
269 | 3 | } |
270 | 3 | case JsonbType::T_Int64: { |
271 | 3 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); |
272 | 3 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); |
273 | 3 | } |
274 | 2 | case JsonbType::T_Int128: { |
275 | 2 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); |
276 | 2 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); |
277 | 3 | } |
278 | 1 | case JsonbType::T_Double: { |
279 | 1 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); |
280 | 1 | return CastToDecimal::from_float(val, to, to_precision, to_scale, params); |
281 | 3 | } |
282 | 1 | case JsonbType::T_Float: { |
283 | 1 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); |
284 | 1 | return CastToDecimal::from_float(val, to, to_precision, to_scale, params); |
285 | 3 | } |
286 | 1 | case JsonbType::T_Decimal32: { |
287 | 1 | auto val = Decimal32 {jsonb_value->unpack<JsonbDecimal32>()->val()}; |
288 | 1 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal32>()->precision; |
289 | 1 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal32>()->scale; |
290 | 1 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, |
291 | 1 | to_scale, params); |
292 | 3 | } |
293 | 1 | case JsonbType::T_Decimal64: { |
294 | 1 | auto val = Decimal64 {jsonb_value->unpack<JsonbDecimal64>()->val()}; |
295 | 1 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal64>()->precision; |
296 | 1 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal64>()->scale; |
297 | 1 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, |
298 | 1 | to_scale, params); |
299 | 3 | } |
300 | 2 | case JsonbType::T_Decimal128: { |
301 | 2 | auto val = Decimal128V3 {jsonb_value->unpack<JsonbDecimal128>()->val()}; |
302 | 2 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal128>()->precision; |
303 | 2 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal128>()->scale; |
304 | 2 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, |
305 | 2 | to_scale, params); |
306 | 3 | } |
307 | 1 | case JsonbType::T_Decimal256: { |
308 | 1 | auto val = Decimal256 {jsonb_value->unpack<JsonbDecimal256>()->val()}; |
309 | 1 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal256>()->precision; |
310 | 1 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal256>()->scale; |
311 | 1 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, |
312 | 1 | to_scale, params); |
313 | 3 | } |
314 | 0 | case JsonbType::T_String: { |
315 | 0 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); |
316 | 0 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; |
317 | 0 | return CastToDecimal::from_string(str_ref, to, to_precision, to_scale, params); |
318 | 3 | } |
319 | 3 | default: { |
320 | 3 | return false; |
321 | 3 | } |
322 | 30 | } |
323 | 30 | } _ZN5doris9JsonbCast25cast_from_json_to_decimalINS_7DecimalIiEEEEbPKNS_10JsonbValueERT_jjRNS_14CastParametersE Line | Count | Source | 251 | 13 | UInt32 to_scale, CastParameters& params) { | 252 | 13 | switch (jsonb_value->type) { | 253 | 1 | case JsonbType::T_True: | 254 | 2 | case JsonbType::T_False: { | 255 | 2 | UInt8 val = jsonb_value->isTrue(); | 256 | 2 | return CastToDecimal::from_bool(val, to, to_precision, to_scale, params); | 257 | 1 | } | 258 | 1 | case JsonbType::T_Int8: { | 259 | 1 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 260 | 1 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 261 | 1 | } | 262 | 1 | case JsonbType::T_Int16: { | 263 | 1 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 264 | 1 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 265 | 1 | } | 266 | 1 | case JsonbType::T_Int32: { | 267 | 1 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 268 | 1 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 269 | 1 | } | 270 | 1 | case JsonbType::T_Int64: { | 271 | 1 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 272 | 1 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 273 | 1 | } | 274 | 1 | case JsonbType::T_Int128: { | 275 | 1 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 276 | 1 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 277 | 1 | } | 278 | 1 | case JsonbType::T_Double: { | 279 | 1 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); | 280 | 1 | return CastToDecimal::from_float(val, to, to_precision, to_scale, params); | 281 | 1 | } | 282 | 1 | case JsonbType::T_Float: { | 283 | 1 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); | 284 | 1 | return CastToDecimal::from_float(val, to, to_precision, to_scale, params); | 285 | 1 | } | 286 | 1 | case JsonbType::T_Decimal32: { | 287 | 1 | auto val = Decimal32 {jsonb_value->unpack<JsonbDecimal32>()->val()}; | 288 | 1 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal32>()->precision; | 289 | 1 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal32>()->scale; | 290 | 1 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, | 291 | 1 | to_scale, params); | 292 | 1 | } | 293 | 1 | case JsonbType::T_Decimal64: { | 294 | 1 | auto val = Decimal64 {jsonb_value->unpack<JsonbDecimal64>()->val()}; | 295 | 1 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal64>()->precision; | 296 | 1 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal64>()->scale; | 297 | 1 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, | 298 | 1 | to_scale, params); | 299 | 1 | } | 300 | 1 | case JsonbType::T_Decimal128: { | 301 | 1 | auto val = Decimal128V3 {jsonb_value->unpack<JsonbDecimal128>()->val()}; | 302 | 1 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal128>()->precision; | 303 | 1 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal128>()->scale; | 304 | 1 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, | 305 | 1 | to_scale, params); | 306 | 1 | } | 307 | 1 | case JsonbType::T_Decimal256: { | 308 | 1 | auto val = Decimal256 {jsonb_value->unpack<JsonbDecimal256>()->val()}; | 309 | 1 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal256>()->precision; | 310 | 1 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal256>()->scale; | 311 | 1 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, | 312 | 1 | to_scale, params); | 313 | 1 | } | 314 | 0 | case JsonbType::T_String: { | 315 | 0 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 316 | 0 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 317 | 0 | return CastToDecimal::from_string(str_ref, to, to_precision, to_scale, params); | 318 | 1 | } | 319 | 0 | default: { | 320 | 0 | return false; | 321 | 1 | } | 322 | 13 | } | 323 | 13 | } |
Unexecuted instantiation: _ZN5doris9JsonbCast25cast_from_json_to_decimalINS_7DecimalIlEEEEbPKNS_10JsonbValueERT_jjRNS_14CastParametersE _ZN5doris9JsonbCast25cast_from_json_to_decimalINS_12Decimal128V3EEEbPKNS_10JsonbValueERT_jjRNS_14CastParametersE Line | Count | Source | 251 | 17 | UInt32 to_scale, CastParameters& params) { | 252 | 17 | switch (jsonb_value->type) { | 253 | 2 | case JsonbType::T_True: | 254 | 4 | case JsonbType::T_False: { | 255 | 4 | UInt8 val = jsonb_value->isTrue(); | 256 | 4 | return CastToDecimal::from_bool(val, to, to_precision, to_scale, params); | 257 | 2 | } | 258 | 2 | case JsonbType::T_Int8: { | 259 | 2 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 260 | 2 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 261 | 2 | } | 262 | 2 | case JsonbType::T_Int16: { | 263 | 2 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 264 | 2 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 265 | 2 | } | 266 | 2 | case JsonbType::T_Int32: { | 267 | 2 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 268 | 2 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 269 | 2 | } | 270 | 2 | case JsonbType::T_Int64: { | 271 | 2 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 272 | 2 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 273 | 2 | } | 274 | 1 | case JsonbType::T_Int128: { | 275 | 1 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 276 | 1 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 277 | 2 | } | 278 | 0 | case JsonbType::T_Double: { | 279 | 0 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); | 280 | 0 | return CastToDecimal::from_float(val, to, to_precision, to_scale, params); | 281 | 2 | } | 282 | 0 | case JsonbType::T_Float: { | 283 | 0 | auto val = jsonb_value->unpack<JsonbFloatVal>()->val(); | 284 | 0 | return CastToDecimal::from_float(val, to, to_precision, to_scale, params); | 285 | 2 | } | 286 | 0 | case JsonbType::T_Decimal32: { | 287 | 0 | auto val = Decimal32 {jsonb_value->unpack<JsonbDecimal32>()->val()}; | 288 | 0 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal32>()->precision; | 289 | 0 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal32>()->scale; | 290 | 0 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, | 291 | 0 | to_scale, params); | 292 | 2 | } | 293 | 0 | case JsonbType::T_Decimal64: { | 294 | 0 | auto val = Decimal64 {jsonb_value->unpack<JsonbDecimal64>()->val()}; | 295 | 0 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal64>()->precision; | 296 | 0 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal64>()->scale; | 297 | 0 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, | 298 | 0 | to_scale, params); | 299 | 2 | } | 300 | 1 | case JsonbType::T_Decimal128: { | 301 | 1 | auto val = Decimal128V3 {jsonb_value->unpack<JsonbDecimal128>()->val()}; | 302 | 1 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal128>()->precision; | 303 | 1 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal128>()->scale; | 304 | 1 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, | 305 | 1 | to_scale, params); | 306 | 2 | } | 307 | 0 | case JsonbType::T_Decimal256: { | 308 | 0 | auto val = Decimal256 {jsonb_value->unpack<JsonbDecimal256>()->val()}; | 309 | 0 | UInt32 from_precision = jsonb_value->unpack<JsonbDecimal256>()->precision; | 310 | 0 | UInt32 from_scale = jsonb_value->unpack<JsonbDecimal256>()->scale; | 311 | 0 | return CastToDecimal::from_decimalv3(val, from_precision, from_scale, to, to_precision, | 312 | 0 | to_scale, params); | 313 | 2 | } | 314 | 0 | case JsonbType::T_String: { | 315 | 0 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 316 | 0 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 317 | 0 | return CastToDecimal::from_string(str_ref, to, to_precision, to_scale, params); | 318 | 2 | } | 319 | 3 | default: { | 320 | 3 | return false; | 321 | 2 | } | 322 | 17 | } | 323 | 17 | } |
Unexecuted instantiation: _ZN5doris9JsonbCast25cast_from_json_to_decimalINS_7DecimalIN4wide7integerILm256EiEEEEEEbPKNS_10JsonbValueERT_jjRNS_14CastParametersE |
324 | | }; |
325 | | } // namespace doris |