mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 03:22:14 +00:00
better
This commit is contained in:
parent
229fffcd56
commit
a39a4b1080
@ -618,7 +618,7 @@ void SerializationArray::serializeTextJSONPretty(const IColumn & column, size_t
|
||||
namespace
|
||||
{
|
||||
template <typename ReturnType>
|
||||
ReturnType deserializeTextJSONArrayImpl(IColumn & column, ReadBuffer & istr, const SerializationPtr & nested, const FormatSettings & settings)
|
||||
ReturnType deserializeEmpyStringAsDefaultOrNested(IColumn & column, ReadBuffer & istr, const SerializationPtr & nested, const FormatSettings & settings)
|
||||
{
|
||||
auto deserializer = [&nested](IColumn & column_, ReadBuffer & istr_, auto && deserialize_nested) -> ReturnType
|
||||
{
|
||||
@ -626,21 +626,40 @@ ReturnType deserializeTextJSONArrayImpl(IColumn & column, ReadBuffer & istr, con
|
||||
{
|
||||
return deserialize_nested(nested_column, istr_, nested);
|
||||
};
|
||||
return deserializeTextImpl<ReturnType>(column_, istr_, adapter, false);
|
||||
return deserializeTextImpl<ReturnType>(column_, istr_, std::move(adapter), false);
|
||||
};
|
||||
|
||||
return JSONUtils::deserializeEmpyStringAsDefaultOrNested<ReturnType>(column, istr, settings, deserializer);
|
||||
return JSONUtils::deserializeEmpyStringAsDefaultOrNested<ReturnType>(column, istr, settings, std::move(deserializer));
|
||||
}
|
||||
}
|
||||
|
||||
void SerializationArray::deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const
|
||||
{
|
||||
deserializeTextJSONArrayImpl<void>(column, istr, nested, settings);
|
||||
if (settings.json.empty_as_default)
|
||||
deserializeEmpyStringAsDefaultOrNested<void>(column, istr, nested, settings);
|
||||
else
|
||||
deserializeTextImpl(column, istr,
|
||||
[&settings, &istr, this](IColumn & nested_column)
|
||||
{
|
||||
if (settings.null_as_default && !isColumnNullableOrLowCardinalityNullable(nested_column))
|
||||
SerializationNullable::deserializeNullAsDefaultOrNestedTextJSON(nested_column, istr, settings, nested);
|
||||
else
|
||||
nested->deserializeTextJSON(nested_column, istr, settings);
|
||||
}, false);
|
||||
}
|
||||
|
||||
bool SerializationArray::tryDeserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const
|
||||
{
|
||||
return deserializeTextJSONArrayImpl<bool>(column, istr, nested, settings);
|
||||
if (settings.json.empty_as_default)
|
||||
return deserializeEmpyStringAsDefaultOrNested<bool>(column, istr, nested, settings);
|
||||
|
||||
return deserializeTextImpl<bool>(column, istr,
|
||||
[&settings, &istr, this](IColumn & nested_column)
|
||||
{
|
||||
if (settings.null_as_default && !isColumnNullableOrLowCardinalityNullable(nested_column))
|
||||
return SerializationNullable::tryDeserializeNullAsDefaultOrNestedTextJSON(nested_column, istr, settings, nested);
|
||||
return nested->tryDeserializeTextJSON(nested_column, istr, settings);
|
||||
}, false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -317,7 +317,7 @@ void SerializationMap::serializeTextJSONPretty(const IColumn & column, size_t ro
|
||||
}
|
||||
|
||||
template <typename ReturnType>
|
||||
ReturnType SerializationMap::deserializeTextJSONMapImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const
|
||||
ReturnType SerializationMap::deserializeEmpyStringAsDefaultOrNested(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const
|
||||
{
|
||||
auto deserializer = [this](IColumn & column_, ReadBuffer & istr_, auto && deserialize_nested) -> ReturnType
|
||||
{
|
||||
@ -325,20 +325,39 @@ ReturnType SerializationMap::deserializeTextJSONMapImpl(IColumn & column, ReadBu
|
||||
{
|
||||
return deserialize_nested(nested_column, buf, nested_column_serialization);
|
||||
};
|
||||
return this->deserializeTextImpl<ReturnType>(column_, istr_, adapter);
|
||||
return this->deserializeTextImpl<ReturnType>(column_, istr_, std::move(adapter));
|
||||
};
|
||||
|
||||
return JSONUtils::deserializeEmpyStringAsDefaultOrNested<ReturnType>(column, istr, settings, deserializer);
|
||||
return JSONUtils::deserializeEmpyStringAsDefaultOrNested<ReturnType>(column, istr, settings, std::move(deserializer));
|
||||
}
|
||||
|
||||
void SerializationMap::deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const
|
||||
{
|
||||
deserializeTextJSONMapImpl<void>(column, istr, settings);
|
||||
if (settings.json.empty_as_default)
|
||||
deserializeEmpyStringAsDefaultOrNested<void>(column, istr, settings);
|
||||
else
|
||||
deserializeTextImpl(column, istr,
|
||||
[&settings](ReadBuffer & buf, const SerializationPtr & subcolumn_serialization, IColumn & subcolumn)
|
||||
{
|
||||
if (settings.null_as_default && !isColumnNullableOrLowCardinalityNullable(subcolumn))
|
||||
SerializationNullable::deserializeNullAsDefaultOrNestedTextJSON(subcolumn, buf, settings, subcolumn_serialization);
|
||||
else
|
||||
subcolumn_serialization->deserializeTextJSON(subcolumn, buf, settings);
|
||||
});
|
||||
}
|
||||
|
||||
bool SerializationMap::tryDeserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const
|
||||
{
|
||||
return deserializeTextJSONMapImpl<bool>(column, istr, settings);
|
||||
if (settings.json.empty_as_default)
|
||||
return deserializeEmpyStringAsDefaultOrNested<bool>(column, istr, settings);
|
||||
|
||||
return deserializeTextImpl<bool>(column, istr,
|
||||
[&settings](ReadBuffer & buf, const SerializationPtr & subcolumn_serialization, IColumn & subcolumn)
|
||||
{
|
||||
if (settings.null_as_default && !isColumnNullableOrLowCardinalityNullable(subcolumn))
|
||||
return SerializationNullable::tryDeserializeNullAsDefaultOrNestedTextJSON(subcolumn, buf, settings, subcolumn_serialization);
|
||||
return subcolumn_serialization->tryDeserializeTextJSON(subcolumn, buf, settings);
|
||||
});
|
||||
}
|
||||
|
||||
void SerializationMap::serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const
|
||||
|
@ -76,7 +76,7 @@ private:
|
||||
ReturnType deserializeTextImpl(IColumn & column, ReadBuffer & istr, Reader && reader) const;
|
||||
|
||||
template <typename ReturnType>
|
||||
ReturnType deserializeTextJSONMapImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const;
|
||||
ReturnType deserializeEmpyStringAsDefaultOrNested(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ void SerializationTuple::serializeTextJSONPretty(const IColumn & column, size_t
|
||||
}
|
||||
|
||||
template <typename ReturnType>
|
||||
ReturnType SerializationTuple::deserializeTextJSONTupleImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings, auto && deserialize_element) const
|
||||
ReturnType SerializationTuple::deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings, auto && deserialize_element) const
|
||||
{
|
||||
static constexpr auto throw_exception = std::is_same_v<ReturnType, void>;
|
||||
|
||||
@ -490,29 +490,48 @@ ReturnType SerializationTuple::deserializeTextJSONTupleImpl(IColumn & column, Re
|
||||
}
|
||||
|
||||
template <typename ReturnType>
|
||||
ReturnType SerializationTuple::deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const
|
||||
ReturnType SerializationTuple::deserializeEmpyStringAsDefaultOrNested(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const
|
||||
{
|
||||
auto deserializer = [&settings, this](IColumn & column_, ReadBuffer & istr_, auto && deserialize_nested) -> ReturnType
|
||||
{
|
||||
auto adapter = [&deserialize_nested, &istr_, this](IColumn & nested_column, size_t element_pos) -> ReturnType
|
||||
{
|
||||
return deserialize_nested(nested_column, istr_, this->elems[element_pos]);
|
||||
return deserialize_nested(nested_column, istr_, elems[element_pos]);
|
||||
};
|
||||
|
||||
return this->deserializeTextJSONTupleImpl<ReturnType>(column_, istr_, settings, adapter);
|
||||
return deserializeTextJSONImpl<ReturnType>(column_, istr_, settings, std::move(adapter));
|
||||
};
|
||||
|
||||
return JSONUtils::deserializeEmpyStringAsDefaultOrNested<ReturnType>(column, istr, settings, deserializer);
|
||||
return JSONUtils::deserializeEmpyStringAsDefaultOrNested<ReturnType>(column, istr, settings, std::move(deserializer));
|
||||
}
|
||||
|
||||
void SerializationTuple::deserializeTextJSON(DB::IColumn & column, DB::ReadBuffer & istr, const DB::FormatSettings & settings) const
|
||||
{
|
||||
deserializeTextJSONImpl(column, istr, settings);
|
||||
if (settings.json.empty_as_default)
|
||||
deserializeEmpyStringAsDefaultOrNested(column, istr, settings);
|
||||
else
|
||||
deserializeTextJSONImpl<void>(column, istr, settings,
|
||||
[&settings, &istr, this](IColumn & nested_column, size_t element_pos) -> void
|
||||
{
|
||||
if (settings.null_as_default && !isColumnNullableOrLowCardinalityNullable(nested_column))
|
||||
SerializationNullable::deserializeNullAsDefaultOrNestedTextJSON(nested_column, istr, settings, elems[element_pos]);
|
||||
else
|
||||
elems[element_pos]->deserializeTextJSON(nested_column, istr, settings);
|
||||
});
|
||||
}
|
||||
|
||||
bool SerializationTuple::tryDeserializeTextJSON(DB::IColumn & column, DB::ReadBuffer & istr, const DB::FormatSettings & settings) const
|
||||
{
|
||||
return deserializeTextJSONImpl<bool>(column, istr, settings);
|
||||
if (settings.json.empty_as_default)
|
||||
return deserializeEmpyStringAsDefaultOrNested<bool>(column, istr, settings);
|
||||
|
||||
return deserializeTextJSONImpl<bool>(column, istr, settings,
|
||||
[&settings, &istr, this](IColumn & nested_column, size_t element_pos) -> bool
|
||||
{
|
||||
if (settings.null_as_default && !isColumnNullableOrLowCardinalityNullable(nested_column))
|
||||
return SerializationNullable::tryDeserializeNullAsDefaultOrNestedTextJSON(nested_column, istr, settings, elems[element_pos]);
|
||||
return elems[element_pos]->tryDeserializeTextJSON(nested_column, istr, settings);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -82,10 +82,10 @@ private:
|
||||
ReturnType deserializeTextImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings, bool whole) const;
|
||||
|
||||
template <typename ReturnType>
|
||||
ReturnType deserializeTextJSONTupleImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings, auto && deserialize_element) const;
|
||||
ReturnType deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings, auto && deserialize_element) const;
|
||||
|
||||
template <typename ReturnType = void>
|
||||
ReturnType deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const;
|
||||
ReturnType deserializeEmpyStringAsDefaultOrNested(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const;
|
||||
|
||||
template <typename ReturnType = void>
|
||||
ReturnType deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const;
|
||||
|
@ -181,9 +181,9 @@ namespace JSONUtils
|
||||
}
|
||||
};
|
||||
|
||||
auto deserialize_nested = [&settings, &do_deserialize_nested, &deserialize_nested_impl](IColumn & nested_column, ReadBuffer & buf, const SerializationPtr & nested_column_serialization) -> ReturnType
|
||||
auto deserialize_nested = [&do_deserialize_nested, &deserialize_nested_impl](IColumn & nested_column, ReadBuffer & buf, const SerializationPtr & nested_column_serialization) -> ReturnType
|
||||
{
|
||||
if (!settings.json.empty_as_default || buf.eof() || *buf.position() != EMPTY_STRING[0])
|
||||
if (buf.eof() || *buf.position() != EMPTY_STRING[0])
|
||||
return deserialize_nested_impl(nested_column, buf, nested_column_serialization);
|
||||
|
||||
if (buf.available() >= EMPTY_STRING_LENGTH)
|
||||
|
Loading…
Reference in New Issue
Block a user