@@ -131,7 +131,7 @@ void jsonElementToString(const typename JSONParser::Element & element, WriteBuff
131131
132132template <typename JSONParser, typename NumberType>
133133bool tryGetNumericValueFromJSONElement (
134- NumberType & value, const typename JSONParser::Element & element, bool convert_bool_to_integer , bool allow_type_conversion, String & error)
134+ NumberType & value, const typename JSONParser::Element & element, bool convert_bool_to_number , bool allow_type_conversion, String & error)
135135{
136136 switch (element.type ())
137137 {
@@ -164,13 +164,10 @@ bool tryGetNumericValueFromJSONElement(
164164 }
165165 break ;
166166 case ElementType::BOOL:
167- if constexpr (is_integer<NumberType> )
167+ if (convert_bool_to_number && allow_type_conversion )
168168 {
169- if (convert_bool_to_integer && allow_type_conversion)
170- {
171- value = static_cast <NumberType>(element.getBool ());
172- break ;
173- }
169+ value = static_cast <NumberType>(element.getBool ());
170+ break ;
174171 }
175172 error = fmt::format (" cannot convert bool value to {}" , TypeName<NumberType>);
176173 return false ;
@@ -262,7 +259,7 @@ class NumericNode : public JSONExtractTreeNode<JSONParser>
262259 }
263260
264261 NumberType value;
265- if (!tryGetNumericValueFromJSONElement<JSONParser, NumberType>(value, element, insert_settings. convert_bool_to_integer || is_bool_type , insert_settings.allow_type_conversion , error))
262+ if (!tryGetNumericValueFromJSONElement<JSONParser, NumberType>(value, element, /* convert_bool_to_number= */ true , insert_settings.allow_type_conversion , error))
266263 {
267264 if (error.empty ())
268265 error = fmt::format (" cannot read {} value from JSON element: {}" , TypeName<NumberType>, jsonElementToString<JSONParser>(element, format_settings));
@@ -319,7 +316,7 @@ class LowCardinalityNumericNode : public NumericNode<JSONParser, NumberType>
319316 }
320317
321318 NumberType value;
322- if (!tryGetNumericValueFromJSONElement<JSONParser, NumberType>(value, element, insert_settings. convert_bool_to_integer || this -> is_bool_type , insert_settings.allow_type_conversion , error))
319+ if (!tryGetNumericValueFromJSONElement<JSONParser, NumberType>(value, element, /* convert_bool_to_number= */ true , insert_settings.allow_type_conversion , error))
323320 {
324321 if (error.empty ())
325322 error = fmt::format (" cannot read {} value from JSON element: {}" , TypeName<NumberType>, jsonElementToString<JSONParser>(element, format_settings));
@@ -2218,13 +2215,13 @@ template std::unique_ptr<JSONExtractTreeNode<SimdJSONParser>> buildJSONExtractTr
22182215#if USE_RAPIDJSON
22192216template void jsonElementToString<RapidJSONParser>(const RapidJSONParser::Element & element, WriteBuffer & buf, const FormatSettings & format_settings);
22202217template std::unique_ptr<JSONExtractTreeNode<RapidJSONParser>> buildJSONExtractTree<RapidJSONParser>(const DataTypePtr & type, const char * source_for_exception_message);
2221- template bool tryGetNumericValueFromJSONElement<RapidJSONParser, Float64>(Float64 & value, const RapidJSONParser::Element & element, bool convert_bool_to_integer , bool allow_type_conversion, String & error);
2218+ template bool tryGetNumericValueFromJSONElement<RapidJSONParser, Float64>(Float64 & value, const RapidJSONParser::Element & element, bool convert_bool_to_number , bool allow_type_conversion, String & error);
22222219#else
22232220template void jsonElementToString<DummyJSONParser>(const DummyJSONParser::Element & element, WriteBuffer & buf, const FormatSettings & format_settings);
22242221template std::unique_ptr<JSONExtractTreeNode<DummyJSONParser>> buildJSONExtractTree<DummyJSONParser>(const DataTypePtr & type, const char * source_for_exception_message);
2225- template bool tryGetNumericValueFromJSONElement<DummyJSONParser, Float64>(Float64 & value, const DummyJSONParser::Element & element, bool convert_bool_to_integer , bool allow_type_conversion, String & error);
2226- template bool tryGetNumericValueFromJSONElement<DummyJSONParser, Int64>(Int64 & value, const DummyJSONParser::Element & element, bool convert_bool_to_integer , bool allow_type_conversion, String & error);
2227- template bool tryGetNumericValueFromJSONElement<DummyJSONParser, UInt64>(UInt64 & value, const DummyJSONParser::Element & element, bool convert_bool_to_integer , bool allow_type_conversion, String & error);
2222+ template bool tryGetNumericValueFromJSONElement<DummyJSONParser, Float64>(Float64 & value, const DummyJSONParser::Element & element, bool convert_bool_to_number , bool allow_type_conversion, String & error);
2223+ template bool tryGetNumericValueFromJSONElement<DummyJSONParser, Int64>(Int64 & value, const DummyJSONParser::Element & element, bool convert_bool_to_number , bool allow_type_conversion, String & error);
2224+ template bool tryGetNumericValueFromJSONElement<DummyJSONParser, UInt64>(UInt64 & value, const DummyJSONParser::Element & element, bool convert_bool_to_number , bool allow_type_conversion, String & error);
22282225#endif
22292226
22302227}
0 commit comments