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 | 0 | static Status report_error(const JsonbValue* jsonb_value, PrimitiveType to_type) { |
30 | 0 | return Status::InvalidArgument("Cannot cast from jsonb value type {} to doris type {}", |
31 | 0 | JsonbToJson {}.to_json_string(jsonb_value), |
32 | 0 | type_to_string(to_type)); |
33 | 0 | } |
34 | | |
35 | | static bool cast_from_json_to_boolean(const JsonbValue* jsonb_value, UInt8& to, |
36 | 28 | CastParameters& params) { |
37 | 28 | switch (jsonb_value->type) { |
38 | 2 | case JsonbType::T_True: |
39 | 4 | case JsonbType::T_False: { |
40 | 4 | return CastToBool::from_number((UInt8)jsonb_value->isTrue(), to, params); |
41 | 2 | } |
42 | 2 | case JsonbType::T_Int8: { |
43 | 2 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); |
44 | 2 | return CastToBool::from_number(val, to, params); |
45 | 2 | } |
46 | 2 | case JsonbType::T_Int16: { |
47 | 2 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); |
48 | 2 | return CastToBool::from_number(val, to, params); |
49 | 2 | } |
50 | 2 | case JsonbType::T_Int32: { |
51 | 2 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); |
52 | 2 | return CastToBool::from_number(val, to, params); |
53 | 2 | } |
54 | 2 | case JsonbType::T_Int64: { |
55 | 2 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); |
56 | 2 | return CastToBool::from_number(val, to, params); |
57 | 2 | } |
58 | 1 | case JsonbType::T_Int128: { |
59 | 1 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); |
60 | 1 | return CastToBool::from_number(val, to, params); |
61 | 2 | } |
62 | 2 | case JsonbType::T_Double: { |
63 | 2 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); |
64 | 2 | return CastToBool::from_number(val, to, params); |
65 | 2 | } |
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 | 2 | } |
70 | 1 | case JsonbType::T_Decimal32: { |
71 | 1 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); |
72 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal32>()->precision; |
73 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; |
74 | 1 | return CastToBool::from_decimal(Decimal32 {val}, to, precision, scale, params); |
75 | 2 | } |
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 | 2 | } |
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 | 2 | } |
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 | 2 | } |
94 | 1 | case JsonbType::T_String: { |
95 | 1 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); |
96 | 1 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; |
97 | 1 | return CastToBool::from_string(str_ref, to, params); |
98 | 2 | } |
99 | 7 | default: { |
100 | 7 | return false; |
101 | 2 | } |
102 | 28 | } |
103 | 28 | } |
104 | | |
105 | | template <typename T> |
106 | | static bool cast_from_json_to_int(const JsonbValue* jsonb_value, T& to, |
107 | 83 | CastParameters& params) { |
108 | 83 | switch (jsonb_value->type) { |
109 | 5 | case JsonbType::T_True: |
110 | 10 | case JsonbType::T_False: { |
111 | 10 | auto val = (UInt8)jsonb_value->isTrue(); |
112 | 10 | return CastToInt::from_bool(val, to, params); |
113 | 5 | } |
114 | 5 | case JsonbType::T_Int8: { |
115 | 5 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); |
116 | 5 | return CastToInt::from_int(val, to, params); |
117 | 5 | } |
118 | 5 | case JsonbType::T_Int16: { |
119 | 5 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); |
120 | 5 | return CastToInt::from_int(val, to, params); |
121 | 5 | } |
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 | 5 | } |
126 | 6 | case JsonbType::T_Int64: { |
127 | 6 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); |
128 | 6 | return CastToInt::from_int(val, to, params); |
129 | 5 | } |
130 | 1 | case JsonbType::T_Int128: { |
131 | 1 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); |
132 | 1 | return CastToInt::from_int(val, to, params); |
133 | 5 | } |
134 | 5 | case JsonbType::T_Double: { |
135 | 5 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); |
136 | 5 | return CastToInt::from_float(val, to, params); |
137 | 5 | } |
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 | 5 | } |
142 | 1 | case JsonbType::T_Decimal32: { |
143 | 1 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); |
144 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal32>()->precision; |
145 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; |
146 | 1 | return CastToInt::from_decimal(Decimal32 {val}, precision, scale, to, params); |
147 | 5 | } |
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 | 5 | } |
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 | 5 | } |
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 | 5 | } |
166 | 4 | case JsonbType::T_String: { |
167 | 4 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); |
168 | 4 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; |
169 | 4 | return std::visit( |
170 | 4 | [&](auto is_strict_mode) { |
171 | 4 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); |
172 | 4 | }, _ZZN5doris9JsonbCast21cast_from_json_to_intIaEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb0EEEEDaS5_ Line | Count | Source | 170 | 1 | [&](auto is_strict_mode) { | 171 | 1 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 1 | }, |
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 | 1 | [&](auto is_strict_mode) { | 171 | 1 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 1 | }, |
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 | 1 | [&](auto is_strict_mode) { | 171 | 1 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 1 | }, |
Unexecuted instantiation: _ZZN5doris9JsonbCast21cast_from_json_to_intIiEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb1EEEEDaS5_ _ZZN5doris9JsonbCast21cast_from_json_to_intIlEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb0EEEEDaS5_ Line | Count | Source | 170 | 1 | [&](auto is_strict_mode) { | 171 | 1 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 1 | }, |
Unexecuted instantiation: _ZZN5doris9JsonbCast21cast_from_json_to_intIlEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb1EEEEDaS5_ Unexecuted instantiation: _ZZN5doris9JsonbCast21cast_from_json_to_intInEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb0EEEEDaS5_ Unexecuted instantiation: _ZZN5doris9JsonbCast21cast_from_json_to_intInEEbPKNS_10JsonbValueERT_RNS_14CastParametersEENKUlS5_E_clISt17integral_constantIbLb1EEEEDaS5_ |
173 | 4 | make_bool_variant(params.is_strict)); |
174 | 5 | } |
175 | 28 | default: { |
176 | 28 | return false; |
177 | 5 | } |
178 | 83 | } |
179 | 83 | } _ZN5doris9JsonbCast21cast_from_json_to_intIaEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 107 | 18 | CastParameters& params) { | 108 | 18 | switch (jsonb_value->type) { | 109 | 2 | case JsonbType::T_True: | 110 | 4 | case JsonbType::T_False: { | 111 | 4 | auto val = (UInt8)jsonb_value->isTrue(); | 112 | 4 | return CastToInt::from_bool(val, to, params); | 113 | 2 | } | 114 | 2 | case JsonbType::T_Int8: { | 115 | 2 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 116 | 2 | return CastToInt::from_int(val, to, params); | 117 | 2 | } | 118 | 1 | case JsonbType::T_Int16: { | 119 | 1 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 120 | 1 | return CastToInt::from_int(val, to, params); | 121 | 2 | } | 122 | 1 | case JsonbType::T_Int32: { | 123 | 1 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 124 | 1 | return CastToInt::from_int(val, to, params); | 125 | 2 | } | 126 | 1 | case JsonbType::T_Int64: { | 127 | 1 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 128 | 1 | return CastToInt::from_int(val, to, params); | 129 | 2 | } | 130 | 0 | case JsonbType::T_Int128: { | 131 | 0 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 132 | 0 | return CastToInt::from_int(val, to, params); | 133 | 2 | } | 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 | 2 | } | 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 | 2 | } | 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 | 2 | } | 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 | 2 | } | 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 | 2 | } | 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 | 2 | } | 166 | 1 | case JsonbType::T_String: { | 167 | 1 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 168 | 1 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 169 | 1 | return std::visit( | 170 | 1 | [&](auto is_strict_mode) { | 171 | 1 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 1 | }, | 173 | 1 | make_bool_variant(params.is_strict)); | 174 | 2 | } | 175 | 7 | default: { | 176 | 7 | return false; | 177 | 2 | } | 178 | 18 | } | 179 | 18 | } |
_ZN5doris9JsonbCast21cast_from_json_to_intIsEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 107 | 16 | CastParameters& params) { | 108 | 16 | switch (jsonb_value->type) { | 109 | 1 | case JsonbType::T_True: | 110 | 2 | case JsonbType::T_False: { | 111 | 2 | auto val = (UInt8)jsonb_value->isTrue(); | 112 | 2 | return CastToInt::from_bool(val, to, params); | 113 | 1 | } | 114 | 1 | case JsonbType::T_Int8: { | 115 | 1 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 116 | 1 | return CastToInt::from_int(val, to, params); | 117 | 1 | } | 118 | 2 | case JsonbType::T_Int16: { | 119 | 2 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 120 | 2 | return CastToInt::from_int(val, to, params); | 121 | 1 | } | 122 | 1 | case JsonbType::T_Int32: { | 123 | 1 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 124 | 1 | return CastToInt::from_int(val, to, params); | 125 | 1 | } | 126 | 1 | case JsonbType::T_Int64: { | 127 | 1 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 128 | 1 | return CastToInt::from_int(val, to, params); | 129 | 1 | } | 130 | 0 | case JsonbType::T_Int128: { | 131 | 0 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 132 | 0 | return CastToInt::from_int(val, to, params); | 133 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 166 | 1 | case JsonbType::T_String: { | 167 | 1 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 168 | 1 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 169 | 1 | return std::visit( | 170 | 1 | [&](auto is_strict_mode) { | 171 | 1 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 1 | }, | 173 | 1 | make_bool_variant(params.is_strict)); | 174 | 1 | } | 175 | 7 | default: { | 176 | 7 | return false; | 177 | 1 | } | 178 | 16 | } | 179 | 16 | } |
_ZN5doris9JsonbCast21cast_from_json_to_intIiEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 107 | 27 | CastParameters& params) { | 108 | 27 | switch (jsonb_value->type) { | 109 | 1 | case JsonbType::T_True: | 110 | 2 | case JsonbType::T_False: { | 111 | 2 | auto val = (UInt8)jsonb_value->isTrue(); | 112 | 2 | return CastToInt::from_bool(val, to, params); | 113 | 1 | } | 114 | 1 | case JsonbType::T_Int8: { | 115 | 1 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 116 | 1 | return CastToInt::from_int(val, to, params); | 117 | 1 | } | 118 | 1 | case JsonbType::T_Int16: { | 119 | 1 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 120 | 1 | return CastToInt::from_int(val, to, params); | 121 | 1 | } | 122 | 11 | case JsonbType::T_Int32: { | 123 | 11 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 124 | 11 | return CastToInt::from_int(val, to, params); | 125 | 1 | } | 126 | 1 | case JsonbType::T_Int64: { | 127 | 1 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 128 | 1 | return CastToInt::from_int(val, to, params); | 129 | 1 | } | 130 | 0 | case JsonbType::T_Int128: { | 131 | 0 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 132 | 0 | return CastToInt::from_int(val, to, params); | 133 | 1 | } | 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 | 1 | } | 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 | 1 | } | 142 | 1 | case JsonbType::T_Decimal32: { | 143 | 1 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); | 144 | 1 | UInt32 precision = jsonb_value->unpack<JsonbDecimal32>()->precision; | 145 | 1 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; | 146 | 1 | return CastToInt::from_decimal(Decimal32 {val}, precision, scale, to, params); | 147 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 166 | 1 | case JsonbType::T_String: { | 167 | 1 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 168 | 1 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 169 | 1 | return std::visit( | 170 | 1 | [&](auto is_strict_mode) { | 171 | 1 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 1 | }, | 173 | 1 | make_bool_variant(params.is_strict)); | 174 | 1 | } | 175 | 7 | default: { | 176 | 7 | return false; | 177 | 1 | } | 178 | 27 | } | 179 | 27 | } |
_ZN5doris9JsonbCast21cast_from_json_to_intIlEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 107 | 19 | CastParameters& params) { | 108 | 19 | switch (jsonb_value->type) { | 109 | 1 | case JsonbType::T_True: | 110 | 2 | case JsonbType::T_False: { | 111 | 2 | auto val = (UInt8)jsonb_value->isTrue(); | 112 | 2 | return CastToInt::from_bool(val, to, params); | 113 | 1 | } | 114 | 1 | case JsonbType::T_Int8: { | 115 | 1 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 116 | 1 | return CastToInt::from_int(val, to, params); | 117 | 1 | } | 118 | 1 | case JsonbType::T_Int16: { | 119 | 1 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 120 | 1 | return CastToInt::from_int(val, to, params); | 121 | 1 | } | 122 | 1 | case JsonbType::T_Int32: { | 123 | 1 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 124 | 1 | return CastToInt::from_int(val, to, params); | 125 | 1 | } | 126 | 3 | case JsonbType::T_Int64: { | 127 | 3 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 128 | 3 | return CastToInt::from_int(val, to, params); | 129 | 1 | } | 130 | 0 | case JsonbType::T_Int128: { | 131 | 0 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 132 | 0 | return CastToInt::from_int(val, to, params); | 133 | 1 | } | 134 | 2 | case JsonbType::T_Double: { | 135 | 2 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); | 136 | 2 | return CastToInt::from_float(val, to, params); | 137 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 166 | 1 | case JsonbType::T_String: { | 167 | 1 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 168 | 1 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 169 | 1 | return std::visit( | 170 | 1 | [&](auto is_strict_mode) { | 171 | 1 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 1 | }, | 173 | 1 | make_bool_variant(params.is_strict)); | 174 | 1 | } | 175 | 7 | default: { | 176 | 7 | return false; | 177 | 1 | } | 178 | 19 | } | 179 | 19 | } |
_ZN5doris9JsonbCast21cast_from_json_to_intInEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 107 | 3 | CastParameters& params) { | 108 | 3 | switch (jsonb_value->type) { | 109 | 0 | case JsonbType::T_True: | 110 | 0 | case JsonbType::T_False: { | 111 | 0 | auto val = (UInt8)jsonb_value->isTrue(); | 112 | 0 | return CastToInt::from_bool(val, to, params); | 113 | 0 | } | 114 | 0 | case JsonbType::T_Int8: { | 115 | 0 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 116 | 0 | return CastToInt::from_int(val, to, params); | 117 | 0 | } | 118 | 0 | case JsonbType::T_Int16: { | 119 | 0 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 120 | 0 | return CastToInt::from_int(val, to, params); | 121 | 0 | } | 122 | 0 | case JsonbType::T_Int32: { | 123 | 0 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 124 | 0 | return CastToInt::from_int(val, to, params); | 125 | 0 | } | 126 | 0 | case JsonbType::T_Int64: { | 127 | 0 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 128 | 0 | return CastToInt::from_int(val, to, params); | 129 | 0 | } | 130 | 1 | case JsonbType::T_Int128: { | 131 | 1 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 132 | 1 | return CastToInt::from_int(val, to, params); | 133 | 0 | } | 134 | 0 | case JsonbType::T_Double: { | 135 | 0 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); | 136 | 0 | return CastToInt::from_float(val, to, params); | 137 | 0 | } | 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 | 0 | } | 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 | 0 | } | 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 | 0 | } | 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 | 0 | } | 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 | 0 | } | 166 | 0 | case JsonbType::T_String: { | 167 | 0 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 168 | 0 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 169 | 0 | return std::visit( | 170 | 0 | [&](auto is_strict_mode) { | 171 | 0 | return CastToInt::from_string<is_strict_mode>(str_ref, to, params); | 172 | 0 | }, | 173 | 0 | make_bool_variant(params.is_strict)); | 174 | 0 | } | 175 | 0 | default: { | 176 | 0 | return false; | 177 | 0 | } | 178 | 3 | } | 179 | 3 | } |
|
180 | | |
181 | | template <typename T> |
182 | | static bool cast_from_json_to_float(const JsonbValue* jsonb_value, T& to, |
183 | 29 | CastParameters& params) { |
184 | 29 | switch (jsonb_value->type) { |
185 | 2 | case JsonbType::T_True: |
186 | 4 | case JsonbType::T_False: { |
187 | 4 | auto val = (UInt8)jsonb_value->isTrue(); |
188 | 4 | return CastToFloat::from_bool(val, to, params); |
189 | 2 | } |
190 | 2 | case JsonbType::T_Int8: { |
191 | 2 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); |
192 | 2 | return CastToFloat::from_int(val, to, params); |
193 | 2 | } |
194 | 2 | case JsonbType::T_Int16: { |
195 | 2 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); |
196 | 2 | return CastToFloat::from_int(val, to, params); |
197 | 2 | } |
198 | 2 | case JsonbType::T_Int32: { |
199 | 2 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); |
200 | 2 | return CastToFloat::from_int(val, to, params); |
201 | 2 | } |
202 | 2 | case JsonbType::T_Int64: { |
203 | 2 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); |
204 | 2 | return CastToFloat::from_int(val, to, params); |
205 | 2 | } |
206 | 1 | case JsonbType::T_Int128: { |
207 | 1 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); |
208 | 1 | return CastToFloat::from_int(val, to, params); |
209 | 2 | } |
210 | 2 | case JsonbType::T_Double: { |
211 | 2 | auto val = jsonb_value->unpack<JsonbDoubleVal>()->val(); |
212 | 2 | return CastToFloat::from_float(val, to, params); |
213 | 2 | } |
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 | 2 | } |
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 | 2 | } |
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 | 2 | } |
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 | 2 | } |
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 | 2 | } |
238 | 1 | case JsonbType::T_String: { |
239 | 1 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); |
240 | 1 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; |
241 | 1 | return CastToFloat::from_string(str_ref, to, params); |
242 | 2 | } |
243 | 7 | default: { |
244 | 7 | return false; |
245 | 2 | } |
246 | 29 | } |
247 | 29 | } _ZN5doris9JsonbCast23cast_from_json_to_floatIfEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 183 | 14 | CastParameters& params) { | 184 | 14 | switch (jsonb_value->type) { | 185 | 1 | case JsonbType::T_True: | 186 | 2 | case JsonbType::T_False: { | 187 | 2 | auto val = (UInt8)jsonb_value->isTrue(); | 188 | 2 | return CastToFloat::from_bool(val, to, params); | 189 | 1 | } | 190 | 1 | case JsonbType::T_Int8: { | 191 | 1 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 192 | 1 | return CastToFloat::from_int(val, to, params); | 193 | 1 | } | 194 | 1 | case JsonbType::T_Int16: { | 195 | 1 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 196 | 1 | return CastToFloat::from_int(val, to, params); | 197 | 1 | } | 198 | 1 | case JsonbType::T_Int32: { | 199 | 1 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 200 | 1 | return CastToFloat::from_int(val, to, params); | 201 | 1 | } | 202 | 1 | case JsonbType::T_Int64: { | 203 | 1 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 204 | 1 | return CastToFloat::from_int(val, to, params); | 205 | 1 | } | 206 | 1 | case JsonbType::T_Int128: { | 207 | 1 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 208 | 1 | return CastToFloat::from_int(val, to, params); | 209 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 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 | 1 | } | 243 | 0 | default: { | 244 | 0 | return false; | 245 | 1 | } | 246 | 14 | } | 247 | 14 | } |
_ZN5doris9JsonbCast23cast_from_json_to_floatIdEEbPKNS_10JsonbValueERT_RNS_14CastParametersE Line | Count | Source | 183 | 15 | CastParameters& params) { | 184 | 15 | switch (jsonb_value->type) { | 185 | 1 | case JsonbType::T_True: | 186 | 2 | case JsonbType::T_False: { | 187 | 2 | auto val = (UInt8)jsonb_value->isTrue(); | 188 | 2 | return CastToFloat::from_bool(val, to, params); | 189 | 1 | } | 190 | 1 | case JsonbType::T_Int8: { | 191 | 1 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 192 | 1 | return CastToFloat::from_int(val, to, params); | 193 | 1 | } | 194 | 1 | case JsonbType::T_Int16: { | 195 | 1 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 196 | 1 | return CastToFloat::from_int(val, to, params); | 197 | 1 | } | 198 | 1 | case JsonbType::T_Int32: { | 199 | 1 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 200 | 1 | return CastToFloat::from_int(val, to, params); | 201 | 1 | } | 202 | 1 | case JsonbType::T_Int64: { | 203 | 1 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 204 | 1 | return CastToFloat::from_int(val, to, params); | 205 | 1 | } | 206 | 0 | case JsonbType::T_Int128: { | 207 | 0 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 208 | 0 | return CastToFloat::from_int(val, to, params); | 209 | 1 | } | 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 | 1 | } | 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 | 1 | } | 218 | 0 | case JsonbType::T_Decimal32: { | 219 | 0 | auto val = jsonb_value->unpack<JsonbDecimal32>()->val(); | 220 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal32>()->scale; | 221 | 0 | return CastToFloat::from_decimal(Decimal32 {val}, scale, to, params); | 222 | 1 | } | 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 | 1 | } | 228 | 0 | case JsonbType::T_Decimal128: { | 229 | 0 | auto val = jsonb_value->unpack<JsonbDecimal128>()->val(); | 230 | 0 | UInt32 scale = jsonb_value->unpack<JsonbDecimal128>()->scale; | 231 | 0 | return CastToFloat::from_decimal(Decimal128V3 {val}, scale, to, params); | 232 | 1 | } | 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 | 1 | } | 238 | 1 | case JsonbType::T_String: { | 239 | 1 | const auto* blob = jsonb_value->unpack<JsonbBinaryVal>(); | 240 | 1 | StringRef str_ref {blob->getBlob(), blob->getBlobLen()}; | 241 | 1 | return CastToFloat::from_string(str_ref, to, params); | 242 | 1 | } | 243 | 7 | default: { | 244 | 7 | return false; | 245 | 1 | } | 246 | 15 | } | 247 | 15 | } |
|
248 | | |
249 | | template <typename T> |
250 | | static bool cast_from_json_to_decimal(const JsonbValue* jsonb_value, T& to, UInt32 to_precision, |
251 | 14 | UInt32 to_scale, CastParameters& params) { |
252 | 14 | 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 | 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 | 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 | 14 | } |
323 | 14 | } _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 | 1 | UInt32 to_scale, CastParameters& params) { | 252 | 1 | switch (jsonb_value->type) { | 253 | 0 | case JsonbType::T_True: | 254 | 0 | case JsonbType::T_False: { | 255 | 0 | UInt8 val = jsonb_value->isTrue(); | 256 | 0 | return CastToDecimal::from_bool(val, to, to_precision, to_scale, params); | 257 | 0 | } | 258 | 0 | case JsonbType::T_Int8: { | 259 | 0 | auto val = jsonb_value->unpack<JsonbInt8Val>()->val(); | 260 | 0 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 261 | 0 | } | 262 | 0 | case JsonbType::T_Int16: { | 263 | 0 | auto val = jsonb_value->unpack<JsonbInt16Val>()->val(); | 264 | 0 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 265 | 0 | } | 266 | 0 | case JsonbType::T_Int32: { | 267 | 0 | auto val = jsonb_value->unpack<JsonbInt32Val>()->val(); | 268 | 0 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 269 | 0 | } | 270 | 0 | case JsonbType::T_Int64: { | 271 | 0 | auto val = jsonb_value->unpack<JsonbInt64Val>()->val(); | 272 | 0 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 273 | 0 | } | 274 | 0 | case JsonbType::T_Int128: { | 275 | 0 | auto val = jsonb_value->unpack<JsonbInt128Val>()->val(); | 276 | 0 | return CastToDecimal::from_int(val, to, to_precision, to_scale, params); | 277 | 0 | } | 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 | 0 | } | 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 | 0 | } | 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 | 0 | } | 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 | 0 | } | 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 | 0 | } | 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 | 0 | } | 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 | 0 | } | 319 | 0 | default: { | 320 | 0 | return false; | 321 | 0 | } | 322 | 1 | } | 323 | 1 | } |
Unexecuted instantiation: _ZN5doris9JsonbCast25cast_from_json_to_decimalINS_7DecimalIN4wide7integerILm256EiEEEEEEbPKNS_10JsonbValueERT_jjRNS_14CastParametersE |
324 | | }; |
325 | | } // namespace doris |