diff --git a/dbms/include/DB/DataTypes/DataTypeAggregateFunction.h b/dbms/include/DB/DataTypes/DataTypeAggregateFunction.h index 0e7871a66bd..47232f85711 100644 --- a/dbms/include/DB/DataTypes/DataTypeAggregateFunction.h +++ b/dbms/include/DB/DataTypes/DataTypeAggregateFunction.h @@ -54,6 +54,11 @@ public: void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr) const; void deserializeTextQuoted(IColumn & column, ReadBuffer & istr) const; + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override; + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override; + void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; @@ -66,10 +71,6 @@ public: } private: - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, NullValuesByteMap * null_map) const override; - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, NullValuesByteMap * null_map) const override; }; diff --git a/dbms/include/DB/DataTypes/DataTypeArray.h b/dbms/include/DB/DataTypes/DataTypeArray.h index e820ac03dba..b97a4446c37 100644 --- a/dbms/include/DB/DataTypes/DataTypeArray.h +++ b/dbms/include/DB/DataTypes/DataTypeArray.h @@ -62,6 +62,12 @@ public: void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override; + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override; + /** Записать размеры. */ void serializeOffsets(const IColumn & column, WriteBuffer & ostr, size_t offset = 0, size_t limit = 0) const; @@ -83,11 +89,6 @@ public: private: void serializeTextInternal(const IColumn & column, size_t row_num, WriteBuffer & ostr) const; void deserializeTextQuotedInternal(IColumn & column, ReadBuffer & istr) const; - - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, NullValuesByteMap * null_map) const override; - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, NullValuesByteMap * null_map) const override; }; } diff --git a/dbms/include/DB/DataTypes/DataTypeDate.h b/dbms/include/DB/DataTypes/DataTypeDate.h index 836e6ca2ca8..e7c7e2ac30a 100644 --- a/dbms/include/DB/DataTypes/DataTypeDate.h +++ b/dbms/include/DB/DataTypes/DataTypeDate.h @@ -54,60 +54,34 @@ private: static_cast(column).getData().push_back(x); /// Важно делать это в конце - для exception safety. } - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); - else - { - writeChar('"', ostr); - writeDateText(DayNum_t(static_cast(column).getData()[row_num]), ostr); - writeChar('"', ostr); - } + writeChar('"', ostr); + writeDateText(DayNum_t(static_cast(column).getData()[row_num]), ostr); + writeChar('"', ostr); } - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, NullValuesByteMap * null_map) const override + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - { - FieldType default_val = get(getDefault()); - static_cast(column).getData().push_back(default_val); - } - else - { - DayNum_t x; - assertChar('"', istr); - readDateText(x, istr); - assertChar('"', istr); - static_cast(column).getData().push_back(x); - } + DayNum_t x; + assertChar('"', istr); + readDateText(x, istr); + assertChar('"', istr); + static_cast(column).getData().push_back(x); } - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::CSV::name, ostr); - else - { - writeChar('"', ostr); - writeDateText(DayNum_t(static_cast(column).getData()[row_num]), ostr); - writeChar('"', ostr); - } + writeChar('"', ostr); + writeDateText(DayNum_t(static_cast(column).getData()[row_num]), ostr); + writeChar('"', ostr); } - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, NullValuesByteMap * null_map) const override + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - { - FieldType default_val = get(getDefault()); - static_cast(column).getData().push_back(default_val); - } - else - { - LocalDate value; - readCSV(value, istr); - static_cast(column).getData().push_back(value.getDayNum()); - } + LocalDate value; + readCSV(value, istr); + static_cast(column).getData().push_back(value.getDayNum()); } }; diff --git a/dbms/include/DB/DataTypes/DataTypeDateTime.h b/dbms/include/DB/DataTypes/DataTypeDateTime.h index 3af0321d649..b86cbe10f76 100644 --- a/dbms/include/DB/DataTypes/DataTypeDateTime.h +++ b/dbms/include/DB/DataTypes/DataTypeDateTime.h @@ -54,64 +54,34 @@ private: static_cast(column).getData().push_back(x); /// Важно делать это в конце - для exception safety. } - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const override + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); - else - { - writeChar('"', ostr); - serializeText(column, row_num, ostr); - writeChar('"', ostr); - } + writeChar('"', ostr); + serializeText(column, row_num, ostr); + writeChar('"', ostr); } - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, - NullValuesByteMap * null_map) const override + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - { - FieldType default_val = get(getDefault()); - static_cast(column).getData().push_back(default_val); - } - else - { - time_t x; - assertChar('"', istr); - readDateTimeText(x, istr); - assertChar('"', istr); - static_cast(column).getData().push_back(x); - } + time_t x; + assertChar('"', istr); + readDateTimeText(x, istr); + assertChar('"', istr); + static_cast(column).getData().push_back(x); } - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const override + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::CSV::name, ostr); - else - { - writeChar('"', ostr); - serializeText(column, row_num, ostr); - writeChar('"', ostr); - } + writeChar('"', ostr); + serializeText(column, row_num, ostr); + writeChar('"', ostr); } - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, - NullValuesByteMap * null_map) const override + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - { - FieldType default_val = get(getDefault()); - static_cast(column).getData().push_back(default_val); - } - else - { - LocalDateTime value; - readCSV(value, istr); - static_cast(column).getData().push_back(static_cast(value)); - } + LocalDateTime value; + readCSV(value, istr); + static_cast(column).getData().push_back(static_cast(value)); } }; diff --git a/dbms/include/DB/DataTypes/DataTypeEnum.h b/dbms/include/DB/DataTypes/DataTypeEnum.h index 737fd837c89..a7a38510ae4 100644 --- a/dbms/include/DB/DataTypes/DataTypeEnum.h +++ b/dbms/include/DB/DataTypes/DataTypeEnum.h @@ -85,6 +85,11 @@ public: void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void deserializeTextQuoted(IColumn & column, ReadBuffer & istr) const override; + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override; + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override; + void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; @@ -94,13 +99,6 @@ public: ColumnPtr createConstColumn(const size_t size, const Field & field) const override; Field getDefault() const override; - -private: - - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, NullValuesByteMap * null_map) const override; - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, NullValuesByteMap * null_map) const override; }; diff --git a/dbms/include/DB/DataTypes/DataTypeFixedString.h b/dbms/include/DB/DataTypes/DataTypeFixedString.h index c3af894113d..4b1388ef10c 100644 --- a/dbms/include/DB/DataTypes/DataTypeFixedString.h +++ b/dbms/include/DB/DataTypes/DataTypeFixedString.h @@ -49,6 +49,11 @@ public: void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void deserializeTextQuoted(IColumn & column, ReadBuffer & istr) const override; + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override; + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override; + void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; @@ -59,13 +64,6 @@ public: { return String(); } - -private: - - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, NullValuesByteMap * null_map) const override; - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, NullValuesByteMap * null_map) const override; }; } diff --git a/dbms/include/DB/DataTypes/DataTypeNull.h b/dbms/include/DB/DataTypes/DataTypeNull.h index 987272a63aa..a16181c0a25 100644 --- a/dbms/include/DB/DataTypes/DataTypeNull.h +++ b/dbms/include/DB/DataTypes/DataTypeNull.h @@ -22,17 +22,15 @@ public: void deserializeTextEscaped(IColumn & column, ReadBuffer & istr) const override; void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void deserializeTextQuoted(IColumn & column, ReadBuffer & istr) const override; + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override; + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override; void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; ColumnPtr createColumn() const override; ColumnPtr createConstColumn(size_t size, const Field & field) const override; Field getDefault() const override; size_t getSizeOfField() const override; - -private: - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, NullValuesByteMap * null_map) const override; - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, NullValuesByteMap * null_map) const override; }; } diff --git a/dbms/include/DB/DataTypes/DataTypeNullable.h b/dbms/include/DB/DataTypes/DataTypeNullable.h index ecdd903e492..c503454f315 100644 --- a/dbms/include/DB/DataTypes/DataTypeNullable.h +++ b/dbms/include/DB/DataTypes/DataTypeNullable.h @@ -24,6 +24,10 @@ public: void deserializeTextEscaped(IColumn & column, ReadBuffer & istr) const override; void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void deserializeTextQuoted(IColumn & column, ReadBuffer & istr) const override; + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override; + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override; void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; ColumnPtr createColumn() const override; @@ -33,12 +37,6 @@ public: DataTypePtr & getNestedType(); const DataTypePtr & getNestedType() const; -private: - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, NullValuesByteMap * null_map) const override; - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, NullValuesByteMap * null_map) const override; - private: DataTypePtr nested_data_type; }; diff --git a/dbms/include/DB/DataTypes/DataTypeString.h b/dbms/include/DB/DataTypes/DataTypeString.h index 0e781effbb8..34bbb47bf12 100644 --- a/dbms/include/DB/DataTypes/DataTypeString.h +++ b/dbms/include/DB/DataTypes/DataTypeString.h @@ -36,6 +36,11 @@ public: void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void deserializeTextQuoted(IColumn & column, ReadBuffer & istr) const override; + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override; + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override; + void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; @@ -46,13 +51,6 @@ public: { return String(""); } - -private: - - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, NullValuesByteMap * null_map) const override; - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, NullValuesByteMap * null_map) const override; }; } diff --git a/dbms/include/DB/DataTypes/DataTypeTuple.h b/dbms/include/DB/DataTypes/DataTypeTuple.h index ced1eac75df..269675dde27 100644 --- a/dbms/include/DB/DataTypes/DataTypeTuple.h +++ b/dbms/include/DB/DataTypes/DataTypeTuple.h @@ -39,6 +39,13 @@ public: void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void deserializeTextQuoted(IColumn & column, ReadBuffer & istr) const override; + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override; + + /// Кортежи в формате CSV будем сериализовать, как отдельные столбцы (то есть, теряя их вложенность в кортеж). + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override; + void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; @@ -50,12 +57,6 @@ public: private: void deserializeText(IColumn & column, ReadBuffer & istr) const; - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, NullValuesByteMap * null_map) const override; - - /// Кортежи в формате CSV будем сериализовать, как отдельные столбцы (то есть, теряя их вложенность в кортеж). - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const override; - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, NullValuesByteMap * null_map) const override; }; } diff --git a/dbms/include/DB/DataTypes/IDataType.h b/dbms/include/DB/DataTypes/IDataType.h index ebe058ec928..3c63a5e8b69 100644 --- a/dbms/include/DB/DataTypes/IDataType.h +++ b/dbms/include/DB/DataTypes/IDataType.h @@ -86,19 +86,11 @@ public: /** Text serialization for the CSV format. */ - inline void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const PaddedPODArray * null_map = nullptr) const - { - serializeTextCSVImpl(column, row_num, ostr, null_map); - } + virtual void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const = 0; /** delimiter - the delimiter we expect when reading a value that is not double-quoted. */ - inline void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter, - PaddedPODArray * null_map = nullptr) const - { - deserializeTextCSVImpl(column, istr, delimiter, null_map); - } + virtual void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const = 0; /** Text serialization for displaying on a terminal or saving into a text file, and the like. * Without escaping or quoting. @@ -107,17 +99,8 @@ public: /** Text serialization as a literal for using with the JSON format. */ - inline void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const PaddedPODArray * null_map = nullptr) const - { - serializeTextJSONImpl(column, row_num, ostr, null_map); - } - - inline void deserializeTextJSON(IColumn & column, ReadBuffer & istr, - PaddedPODArray * null_map = nullptr) const - { - deserializeTextJSONImpl(column, istr, null_map); - } + virtual void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const = 0; + virtual void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const = 0; /** Text serialization for putting into the XML format. */ @@ -151,11 +134,6 @@ protected: { return (null_map != nullptr) && ((*null_map)[row_num] == 1); } - - virtual void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const = 0; - virtual void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, NullValuesByteMap * null_map) const = 0; - virtual void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const NullValuesByteMap * null_map) const = 0; - virtual void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, NullValuesByteMap * null_map) const = 0; }; diff --git a/dbms/include/DB/DataTypes/IDataTypeDummy.h b/dbms/include/DB/DataTypes/IDataTypeDummy.h index 37ad21af0b8..2f7c0b1db54 100644 --- a/dbms/include/DB/DataTypes/IDataTypeDummy.h +++ b/dbms/include/DB/DataTypes/IDataTypeDummy.h @@ -40,6 +40,11 @@ public: throwNoSerialization(); } + void deserializeBinary(IColumn & column, ReadBuffer & istr, size_t limit, double avg_value_size_hint) const override + { + throwNoSerialization(); + } + void serializeTextEscaped(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override { throwNoSerialization(); @@ -60,7 +65,22 @@ public: throwNoSerialization(); } - void deserializeBinary(IColumn & column, ReadBuffer & istr, size_t limit, double avg_value_size_hint) const override + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override + { + throwNoSerialization(); + } + + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override + { + throwNoSerialization(); + } + + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override + { + throwNoSerialization(); + } + + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override { throwNoSerialization(); } @@ -85,31 +105,6 @@ public: throw Exception("Method getDefault() is not implemented for data type " + getName(), ErrorCodes::NOT_IMPLEMENTED); } -protected: - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const override - { - throwNoSerialization(); - } - - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, - NullValuesByteMap * null_map) const override - { - throwNoSerialization(); - } - - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const override - { - throwNoSerialization(); - } - - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, - NullValuesByteMap * null_map) const override - { - throwNoSerialization(); - } - private: void throwNoSerialization() const { diff --git a/dbms/include/DB/DataTypes/IDataTypeNumber.h b/dbms/include/DB/DataTypes/IDataTypeNumber.h index 9b1fab08e6a..b5b712223e6 100644 --- a/dbms/include/DB/DataTypes/IDataTypeNumber.h +++ b/dbms/include/DB/DataTypes/IDataTypeNumber.h @@ -66,11 +66,9 @@ protected: deserializeText(column, istr); } - inline void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const PaddedPODArray * null_map) const override; + inline void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, - PaddedPODArray * null_map) const override + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override { bool has_quote = false; if (!istr.eof() && *istr.position() == '"') /// Понимаем число как в кавычках, так и без. @@ -88,9 +86,6 @@ protected: assertString(NullSymbol::JSON::suffix, istr); x = valueForJSONNull(); - - if (null_map != nullptr) - null_map->push_back(1); } else { @@ -103,29 +98,16 @@ protected: static_cast(column).getData().push_back(x); } - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const PaddedPODArray * null_map) const override + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::CSV::name, ostr); - else - writeText(static_cast(column).getData()[row_num], ostr); + writeText(static_cast(column).getData()[row_num], ostr); } - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, - PaddedPODArray * null_map) const override + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - { - FieldType default_val = get(getDefault()); - static_cast(column).getData().push_back(default_val); - } - else - { - FieldType x; - readCSV(x, istr); - static_cast(column).getData().push_back(x); - } + FieldType x; + readCSV(x, istr); + static_cast(column).getData().push_back(x); } }; @@ -143,83 +125,53 @@ public: void deserializeTextEscaped(IColumn & column, ReadBuffer & istr) const override {} void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override {} void deserializeTextQuoted(IColumn & column, ReadBuffer & istr) const override {} + void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override {} + void deserializeTextJSON(IColumn & column, ReadBuffer & istr) const override {} + void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override {} + void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const override {} void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override {} - -protected: - void serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const PaddedPODArray * null_map) const override {} - void deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, PaddedPODArray * null_map) const override {} - void serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, const PaddedPODArray * null_map) const override {} - void deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, PaddedPODArray * null_map) const override {} }; template -inline void IDataTypeNumber::serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const PaddedPODArray * null_map) const +inline void IDataTypeNumber::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); - else - writeText(static_cast(column).getData()[row_num], ostr); + writeText(static_cast(column).getData()[row_num], ostr); } template <> -inline void IDataTypeNumber::serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const PaddedPODArray * null_map) const +inline void IDataTypeNumber::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); - else - { - writeChar('"', ostr); - writeText(static_cast(column).getData()[row_num], ostr); - writeChar('"', ostr); - } + writeChar('"', ostr); + writeText(static_cast(column).getData()[row_num], ostr); + writeChar('"', ostr); } template <> -inline void IDataTypeNumber::serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const PaddedPODArray * null_map) const +inline void IDataTypeNumber::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); - else - { - writeChar('"', ostr); - writeText(static_cast(column).getData()[row_num], ostr); - writeChar('"', ostr); - } + writeChar('"', ostr); + writeText(static_cast(column).getData()[row_num], ostr); + writeChar('"', ostr); } template <> -inline void IDataTypeNumber::serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const PaddedPODArray * null_map) const +inline void IDataTypeNumber::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); + auto x = static_cast(column).getData()[row_num]; + if (likely(std::isfinite(x))) + writeText(x, ostr); else - { - auto x = static_cast(column).getData()[row_num]; - if (likely(std::isfinite(x))) - writeText(x, ostr); - else - writeCString(NullSymbol::JSON::name, ostr); - } + writeCString(NullSymbol::JSON::name, ostr); } template <> -inline void IDataTypeNumber::serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const PaddedPODArray * null_map) const +inline void IDataTypeNumber::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); + auto x = static_cast(column).getData()[row_num]; + if (likely(std::isfinite(x))) + writeText(x, ostr); else - { - auto x = static_cast(column).getData()[row_num]; - if (likely(std::isfinite(x))) - writeText(x, ostr); - else - writeCString(NullSymbol::JSON::name, ostr); - } + writeCString(NullSymbol::JSON::name, ostr); } template diff --git a/dbms/src/DataTypes/DataTypeAggregateFunction.cpp b/dbms/src/DataTypes/DataTypeAggregateFunction.cpp index 671d1a8e8ac..d5b11628b91 100644 --- a/dbms/src/DataTypes/DataTypeAggregateFunction.cpp +++ b/dbms/src/DataTypes/DataTypeAggregateFunction.cpp @@ -188,14 +188,12 @@ void DataTypeAggregateFunction::deserializeTextQuoted(IColumn & column, ReadBuff deserializeFromString(function, column, s); } -void DataTypeAggregateFunction::serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeAggregateFunction::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { writeJSONString(serializeToString(function, column, row_num), ostr); } -void DataTypeAggregateFunction::deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, - NullValuesByteMap * null_map) const +void DataTypeAggregateFunction::deserializeTextJSON(IColumn & column, ReadBuffer & istr) const { String s; readJSONString(s, istr); @@ -207,14 +205,12 @@ void DataTypeAggregateFunction::serializeTextXML(const IColumn & column, size_t writeXMLString(serializeToString(function, column, row_num), ostr); } -void DataTypeAggregateFunction::serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeAggregateFunction::serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { writeCSV(serializeToString(function, column, row_num), ostr); } -void DataTypeAggregateFunction::deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, - NullValuesByteMap * null_map) const +void DataTypeAggregateFunction::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const { String s; readCSV(s, istr, delimiter); diff --git a/dbms/src/DataTypes/DataTypeArray.cpp b/dbms/src/DataTypes/DataTypeArray.cpp index c74e87175d8..0870533331f 100644 --- a/dbms/src/DataTypes/DataTypeArray.cpp +++ b/dbms/src/DataTypes/DataTypeArray.cpp @@ -262,13 +262,6 @@ void deserializeTextInternal(IColumn & column, ReadBuffer & istr, Reader && read offsets.push_back((offsets.empty() ? 0 : offsets.back()) + size); } -void insertEmptyArray(IColumn & column) -{ - ColumnArray & column_array = static_cast(column); - ColumnArray::Offsets_t & offsets = column_array.getOffsets(); - offsets.push_back((offsets.empty() ? 0 : offsets.back())); -} - } void DataTypeArray::deserializeTextQuotedInternal(IColumn & column, ReadBuffer & istr) const @@ -306,40 +299,30 @@ void DataTypeArray::deserializeTextQuoted(IColumn & column, ReadBuffer & istr) c } -void DataTypeArray::serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeArray::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); - else + const ColumnArray & column_array = static_cast(column); + const ColumnArray::Offsets_t & offsets = column_array.getOffsets(); + + size_t offset = row_num == 0 ? 0 : offsets[row_num - 1]; + size_t next_offset = offsets[row_num]; + + const IColumn & nested_column = column_array.getData(); + + writeChar('[', ostr); + for (size_t i = offset; i < next_offset; ++i) { - const ColumnArray & column_array = static_cast(column); - const ColumnArray::Offsets_t & offsets = column_array.getOffsets(); - - size_t offset = row_num == 0 ? 0 : offsets[row_num - 1]; - size_t next_offset = offsets[row_num]; - - const IColumn & nested_column = column_array.getData(); - - writeChar('[', ostr); - for (size_t i = offset; i < next_offset; ++i) - { - if (i != offset) - writeChar(',', ostr); - nested->serializeTextJSON(nested_column, i, ostr, null_map); - } - writeChar(']', ostr); + if (i != offset) + writeChar(',', ostr); + nested->serializeTextJSON(nested_column, i, ostr); } + writeChar(']', ostr); } -void DataTypeArray::deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, - NullValuesByteMap * null_map) const +void DataTypeArray::deserializeTextJSON(IColumn & column, ReadBuffer & istr) const { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - insertEmptyArray(column); - else - deserializeTextInternal(column, istr, [&](IColumn & nested_column) { nested->deserializeTextJSON(nested_column, istr); }); + deserializeTextInternal(column, istr, [&](IColumn & nested_column) { nested->deserializeTextJSON(nested_column, istr); }); } @@ -364,36 +347,24 @@ void DataTypeArray::serializeTextXML(const IColumn & column, size_t row_num, Wri } -void DataTypeArray::serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeArray::serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::Quoted::name, ostr); - else + /// Хорошего способа сериализовать массив в CSV нет. Поэтому сериализуем его в строку, а затем полученную строку запишем в CSV. + String s; { - /// Хорошего способа сериализовать массив в CSV нет. Поэтому сериализуем его в строку, а затем полученную строку запишем в CSV. - String s; - { - WriteBufferFromString wb(s); - serializeTextInternal(column, row_num, wb); - } - writeCSV(s, ostr); + WriteBufferFromString wb(s); + serializeTextInternal(column, row_num, wb); } + writeCSV(s, ostr); } -void DataTypeArray::deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, - NullValuesByteMap * null_map) const +void DataTypeArray::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - insertEmptyArray(column); - else - { - String s; - readCSV(s, istr, delimiter); - ReadBufferFromString rb(s); - deserializeTextQuotedInternal(column, rb); - } + String s; + readCSV(s, istr, delimiter); + ReadBufferFromString rb(s); + deserializeTextQuotedInternal(column, rb); } diff --git a/dbms/src/DataTypes/DataTypeEnum.cpp b/dbms/src/DataTypes/DataTypeEnum.cpp index 50098284ff4..57da928119d 100644 --- a/dbms/src/DataTypes/DataTypeEnum.cpp +++ b/dbms/src/DataTypes/DataTypeEnum.cpp @@ -171,13 +171,9 @@ void DataTypeEnum::deserializeTextQuoted(IColumn & column, ReadBuffer & is } template -void DataTypeEnum::serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeEnum::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); - else - writeJSONString(getNameForValue(static_cast(column).getData()[row_num]), ostr); + writeJSONString(getNameForValue(static_cast(column).getData()[row_num]), ostr); } template @@ -187,47 +183,25 @@ void DataTypeEnum::serializeTextXML(const IColumn & column, size_t row_num } template -void DataTypeEnum::deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, - NullValuesByteMap * null_map) const +void DataTypeEnum::deserializeTextJSON(IColumn & column, ReadBuffer & istr) const { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - { - FieldType default_val = get(getDefault()); - static_cast(column).getData().push_back(default_val); - } - else - { - std::string name; - readJSONString(name, istr); - static_cast(column).getData().push_back(getValue(StringRef(name))); - } + std::string name; + readJSONString(name, istr); + static_cast(column).getData().push_back(getValue(StringRef(name))); } template -void DataTypeEnum::serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeEnum::serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::CSV::name, ostr); - else - writeCSVString(getNameForValue(static_cast(column).getData()[row_num]), ostr); + writeCSVString(getNameForValue(static_cast(column).getData()[row_num]), ostr); } template -void DataTypeEnum::deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, - NullValuesByteMap * null_map) const +void DataTypeEnum::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - { - FieldType default_val = get(getDefault()); - static_cast(column).getData().push_back(default_val); - } - else - { - std::string name; - readCSVString(name, istr, delimiter); - static_cast(column).getData().push_back(getValue(StringRef(name))); - } + std::string name; + readCSVString(name, istr, delimiter); + static_cast(column).getData().push_back(getValue(StringRef(name))); } template diff --git a/dbms/src/DataTypes/DataTypeFixedString.cpp b/dbms/src/DataTypes/DataTypeFixedString.cpp index 1ac9c3c7d12..b394cb108a1 100644 --- a/dbms/src/DataTypes/DataTypeFixedString.cpp +++ b/dbms/src/DataTypes/DataTypeFixedString.cpp @@ -141,13 +141,6 @@ static inline void read(const DataTypeFixedString & self, IColumn & column, Read } } -void insertEmptyString(const DataTypeFixedString & self, IColumn & column) -{ - ColumnFixedString::Chars_t & data = typeid_cast(column).getChars(); - size_t prev_size = data.size(); - data.resize_fill(prev_size + self.getN()); -} - } void DataTypeFixedString::deserializeTextEscaped(IColumn & column, ReadBuffer & istr) const @@ -169,26 +162,16 @@ void DataTypeFixedString::deserializeTextQuoted(IColumn & column, ReadBuffer & i } -void DataTypeFixedString::serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeFixedString::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); - else - { - const char * pos = reinterpret_cast(&static_cast(column).getChars()[n * row_num]); - writeJSONString(pos, pos + n, ostr); - } + const char * pos = reinterpret_cast(&static_cast(column).getChars()[n * row_num]); + writeJSONString(pos, pos + n, ostr); } -void DataTypeFixedString::deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, - NullValuesByteMap * null_map) const +void DataTypeFixedString::deserializeTextJSON(IColumn & column, ReadBuffer & istr) const { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - insertEmptyString(*this, column); - else - read(*this, column, [&istr](ColumnFixedString::Chars_t & data) { readJSONStringInto(data, istr); }); + read(*this, column, [&istr](ColumnFixedString::Chars_t & data) { readJSONStringInto(data, istr); }); } @@ -199,26 +182,16 @@ void DataTypeFixedString::serializeTextXML(const IColumn & column, size_t row_nu } -void DataTypeFixedString::serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeFixedString::serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::CSV::name, ostr); - else - { - const char * pos = reinterpret_cast(&static_cast(column).getChars()[n * row_num]); - writeCSVString(pos, pos + n, ostr); - } + const char * pos = reinterpret_cast(&static_cast(column).getChars()[n * row_num]); + writeCSVString(pos, pos + n, ostr); } -void DataTypeFixedString::deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, - NullValuesByteMap * null_map) const +void DataTypeFixedString::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - insertEmptyString(*this, column); - else - read(*this, column, [&istr](ColumnFixedString::Chars_t & data) { readCSVStringInto(data, istr); }); + read(*this, column, [&istr](ColumnFixedString::Chars_t & data) { readCSVStringInto(data, istr); }); } diff --git a/dbms/src/DataTypes/DataTypeNull.cpp b/dbms/src/DataTypes/DataTypeNull.cpp index 0ac288253b5..d789be1872a 100644 --- a/dbms/src/DataTypes/DataTypeNull.cpp +++ b/dbms/src/DataTypes/DataTypeNull.cpp @@ -121,14 +121,12 @@ void DataTypeNull::deserializeTextQuoted(IColumn & column, ReadBuffer & istr) co assertString(NullSymbol::Quoted::name, istr); } -void DataTypeNull::serializeTextCSVImpl(const IColumn & column, size_t row_num, - WriteBuffer & ostr, const NullValuesByteMap * null_map) const +void DataTypeNull::serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { writeCString(NullSymbol::CSV::name, ostr); } -void DataTypeNull::deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, - const char delimiter, NullValuesByteMap * null_map) const +void DataTypeNull::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const { assertString(NullSymbol::CSV::name, istr); } @@ -138,14 +136,12 @@ void DataTypeNull::serializeText(const IColumn & column, size_t row_num, WriteBu writeCString(NullSymbol::Plain::name, ostr); } -void DataTypeNull::serializeTextJSONImpl(const IColumn & column, size_t row_num, - WriteBuffer & ostr, const NullValuesByteMap * null_map) const +void DataTypeNull::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { writeCString(NullSymbol::JSON::name, ostr); } -void DataTypeNull::deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, - NullValuesByteMap * null_map) const +void DataTypeNull::deserializeTextJSON(IColumn & column, ReadBuffer & istr) const { assertString(NullSymbol::JSON::name, istr); } diff --git a/dbms/src/DataTypes/DataTypeNullable.cpp b/dbms/src/DataTypes/DataTypeNullable.cpp index a7d9d260a56..e118c68d715 100644 --- a/dbms/src/DataTypes/DataTypeNullable.cpp +++ b/dbms/src/DataTypes/DataTypeNullable.cpp @@ -142,26 +142,34 @@ void DataTypeNullable::deserializeTextQuoted(IColumn & column, ReadBuffer & istr nested_data_type.get()->deserializeTextQuoted(*(col->getNestedColumn().get()), istr); } -void DataTypeNullable::serializeTextCSVImpl(const IColumn & column, size_t row_num, - WriteBuffer & ostr, const NullValuesByteMap * null_map) const +void DataTypeNullable::serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { const ColumnNullable * col = typeid_cast(&column); if (col == nullptr) throw Exception{"Discrepancy between data type and column type", ErrorCodes::LOGICAL_ERROR}; const ColumnUInt8 & content = static_cast(*(col->getNullValuesByteMap().get())); - nested_data_type.get()->serializeTextCSV(*(col->getNestedColumn().get()), row_num, ostr, &content.getData()); + const auto & null_map = content.getData(); + + if (isNullValue(&null_map, row_num)) + writeCString(NullSymbol::Quoted::name, ostr); + else + nested_data_type.get()->serializeTextCSV(*(col->getNestedColumn().get()), row_num, ostr); } -void DataTypeNullable::deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, - const char delimiter, NullValuesByteMap * null_map) const +void DataTypeNullable::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const { ColumnNullable * col = typeid_cast(&column); if (col == nullptr) throw Exception{"Discrepancy between data type and column type", ErrorCodes::LOGICAL_ERROR}; ColumnUInt8 & content = static_cast(*(col->getNullValuesByteMap().get())); - nested_data_type.get()->deserializeTextCSV(*(col->getNestedColumn().get()), istr, delimiter, &content.getData()); + auto & null_map = content.getData(); + + if (NullSymbol::Deserializer::execute(column, istr, &null_map)) + col->insertDefault(); + else + nested_data_type.get()->deserializeTextCSV(*(col->getNestedColumn().get()), istr, delimiter); } void DataTypeNullable::serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr) const @@ -179,26 +187,34 @@ void DataTypeNullable::serializeText(const IColumn & column, size_t row_num, Wri nested_data_type.get()->serializeText(*(col->getNestedColumn().get()), row_num, ostr); } -void DataTypeNullable::serializeTextJSONImpl(const IColumn & column, size_t row_num, - WriteBuffer & ostr, const NullValuesByteMap * null_map) const +void DataTypeNullable::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { const ColumnNullable * col = typeid_cast(&column); if (col == nullptr) throw Exception{"Discrepancy between data type and column type", ErrorCodes::LOGICAL_ERROR}; const ColumnUInt8 & content = static_cast(*(col->getNullValuesByteMap().get())); - nested_data_type.get()->serializeTextJSON(*(col->getNestedColumn().get()), row_num, ostr, &content.getData()); + const auto & null_map = content.getData(); + + if (isNullValue(&null_map, row_num)) + writeCString(NullSymbol::JSON::name, ostr); + else + nested_data_type.get()->serializeTextJSON(*(col->getNestedColumn().get()), row_num, ostr); } -void DataTypeNullable::deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, - NullValuesByteMap * null_map) const +void DataTypeNullable::deserializeTextJSON(IColumn & column, ReadBuffer & istr) const { ColumnNullable * col = typeid_cast(&column); if (col == nullptr) throw Exception{"Discrepancy between data type and column type", ErrorCodes::LOGICAL_ERROR}; ColumnUInt8 & content = static_cast(*(col->getNullValuesByteMap().get())); - nested_data_type.get()->deserializeTextJSON(*(col->getNestedColumn().get()), istr, &content.getData()); + auto & null_map = content.getData(); + + if (NullSymbol::Deserializer::execute(column, istr, &null_map)) + col->insertDefault(); + else + nested_data_type.get()->deserializeTextJSON(*(col->getNestedColumn().get()), istr); } void DataTypeNullable::serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr) const diff --git a/dbms/src/DataTypes/DataTypeString.cpp b/dbms/src/DataTypes/DataTypeString.cpp index f416927a008..8a0f6199d53 100644 --- a/dbms/src/DataTypes/DataTypeString.cpp +++ b/dbms/src/DataTypes/DataTypeString.cpp @@ -250,16 +250,6 @@ static inline void read(IColumn & column, ReadBuffer & istr, Reader && reader) } } -void insertEmptyString(IColumn & column) -{ - ColumnString & column_string = static_cast(column); - ColumnString::Chars_t & data = column_string.getChars(); - ColumnString::Offsets_t & offsets = column_string.getOffsets(); - - data.push_back(0); - offsets.push_back(data.size()); -} - } void DataTypeString::deserializeTextEscaped(IColumn & column, ReadBuffer & istr) const @@ -280,23 +270,15 @@ void DataTypeString::deserializeTextQuoted(IColumn & column, ReadBuffer & istr) } -void DataTypeString::serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeString::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); - else - writeJSONString(static_cast(column).getDataAt(row_num), ostr); + writeJSONString(static_cast(column).getDataAt(row_num), ostr); } -void DataTypeString::deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, - NullValuesByteMap * null_map) const +void DataTypeString::deserializeTextJSON(IColumn & column, ReadBuffer & istr) const { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - insertEmptyString(column); - else - read(column, istr, [&](ColumnString::Chars_t & data) { readJSONStringInto(data, istr); }); + read(column, istr, [&](ColumnString::Chars_t & data) { readJSONStringInto(data, istr); }); } @@ -306,23 +288,15 @@ void DataTypeString::serializeTextXML(const IColumn & column, size_t row_num, Wr } -void DataTypeString::serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeString::serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::CSV::name, ostr); - else - writeCSVString<>(static_cast(column).getDataAt(row_num), ostr); + writeCSVString<>(static_cast(column).getDataAt(row_num), ostr); } -void DataTypeString::deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, - NullValuesByteMap * null_map) const +void DataTypeString::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const { - if (NullSymbol::Deserializer::execute(column, istr, null_map)) - insertEmptyString(column); - else - read(column, istr, [&](ColumnString::Chars_t & data) { readCSVStringInto(data, istr); }); + read(column, istr, [&](ColumnString::Chars_t & data) { readCSVStringInto(data, istr); }); } diff --git a/dbms/src/DataTypes/DataTypeTuple.cpp b/dbms/src/DataTypes/DataTypeTuple.cpp index 35ff1ece2db..55e52b6be1d 100644 --- a/dbms/src/DataTypes/DataTypeTuple.cpp +++ b/dbms/src/DataTypes/DataTypeTuple.cpp @@ -145,46 +145,36 @@ void DataTypeTuple::deserializeTextQuoted(IColumn & column, ReadBuffer & istr) c deserializeText(column, istr); } -void DataTypeTuple::serializeTextJSONImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeTuple::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::JSON::name, ostr); - else + writeChar('[', ostr); + for (const auto i : ext::range(0, ext::size(elems))) { - writeChar('[', ostr); - for (const auto i : ext::range(0, ext::size(elems))) - { - if (i != 0) - writeChar(',', ostr); - elems[i]->serializeTextJSON(extractElementColumn(column, i), row_num, ostr, null_map); - } - writeChar(']', ostr); + if (i != 0) + writeChar(',', ostr); + elems[i]->serializeTextJSON(extractElementColumn(column, i), row_num, ostr); } + writeChar(']', ostr); } -void DataTypeTuple::deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, - NullValuesByteMap * null_map) const +void DataTypeTuple::deserializeTextJSON(IColumn & column, ReadBuffer & istr) const { - if (!NullSymbol::Deserializer::execute(column, istr, null_map)) + const size_t size = elems.size(); + assertChar('[', istr); + + deserializeSafe(elems, column, istr, [&] { - const size_t size = elems.size(); - assertChar('[', istr); - - deserializeSafe(elems, column, istr, [&] + for (const auto i : ext::range(0, size)) { - for (const auto i : ext::range(0, size)) - { - skipWhitespaceIfAny(istr); - if (i != 0) - assertChar(',', istr); - elems[i]->deserializeTextJSON(extractElementColumn(column, i), istr, null_map); - } - }); + skipWhitespaceIfAny(istr); + if (i != 0) + assertChar(',', istr); + elems[i]->deserializeTextJSON(extractElementColumn(column, i), istr); + } + }); - skipWhitespaceIfAny(istr); - assertChar(']', istr); - } + skipWhitespaceIfAny(istr); + assertChar(']', istr); } void DataTypeTuple::serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr) const @@ -199,42 +189,32 @@ void DataTypeTuple::serializeTextXML(const IColumn & column, size_t row_num, Wri writeCString("", ostr); } -void DataTypeTuple::serializeTextCSVImpl(const IColumn & column, size_t row_num, WriteBuffer & ostr, - const NullValuesByteMap * null_map) const +void DataTypeTuple::serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr) const { - if (isNullValue(null_map, row_num)) - writeCString(NullSymbol::CSV::name, ostr); - else + for (const auto i : ext::range(0, ext::size(elems))) { - for (const auto i : ext::range(0, ext::size(elems))) - { - if (i != 0) - writeChar(',', ostr); - elems[i]->serializeTextCSV(extractElementColumn(column, i), row_num, ostr, null_map); - } + if (i != 0) + writeChar(',', ostr); + elems[i]->serializeTextCSV(extractElementColumn(column, i), row_num, ostr); } } -void DataTypeTuple::deserializeTextCSVImpl(IColumn & column, ReadBuffer & istr, const char delimiter, - NullValuesByteMap * null_map) const +void DataTypeTuple::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const { - if (!NullSymbol::Deserializer::execute(column, istr, null_map)) + deserializeSafe(elems, column, istr, [&] { - deserializeSafe(elems, column, istr, [&] + const size_t size = elems.size(); + for (const auto i : ext::range(0, size)) { - const size_t size = elems.size(); - for (const auto i : ext::range(0, size)) + if (i != 0) { - if (i != 0) - { - skipWhitespaceIfAny(istr); - assertChar(delimiter, istr); - skipWhitespaceIfAny(istr); - } - elems[i]->deserializeTextCSV(extractElementColumn(column, i), istr, delimiter, null_map); + skipWhitespaceIfAny(istr); + assertChar(delimiter, istr); + skipWhitespaceIfAny(istr); } - }); - } + elems[i]->deserializeTextCSV(extractElementColumn(column, i), istr, delimiter); + } + }); } void DataTypeTuple::serializeBinary(const IColumn & column, WriteBuffer & ostr, size_t offset, size_t limit) const