2012-08-23 18:43:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-09-18 13:28:46 +00:00
|
|
|
#include <DataTypes/DataTypeWithSimpleSerialization.h>
|
2012-08-23 18:43:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-04-17 11:56:55 +00:00
|
|
|
/** Tuple data type.
|
|
|
|
* Used as an intermediate result when evaluating expressions.
|
|
|
|
* Also can be used as a column - the result of the query execution.
|
2017-12-23 04:29:34 +00:00
|
|
|
*
|
|
|
|
* Tuple elements can have names.
|
|
|
|
* If an element is unnamed, it will have automatically assigned name like '1', '2', '3' corresponding to its position.
|
|
|
|
* Manually assigned names must not begin with digit. Names must be unique.
|
|
|
|
*
|
|
|
|
* All tuples with same size and types of elements are equivalent for expressions, regardless to names of elements.
|
2012-08-23 18:43:57 +00:00
|
|
|
*/
|
2018-09-18 13:28:46 +00:00
|
|
|
class DataTypeTuple final : public DataTypeWithSimpleSerialization
|
2012-08-23 18:43:57 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
DataTypes elems;
|
2017-12-23 04:29:34 +00:00
|
|
|
Strings names;
|
|
|
|
bool have_explicit_names;
|
2012-08-23 18:43:57 +00:00
|
|
|
public:
|
2017-10-30 02:18:06 +00:00
|
|
|
static constexpr bool is_parametric = true;
|
2017-12-23 04:29:34 +00:00
|
|
|
|
|
|
|
DataTypeTuple(const DataTypes & elems);
|
|
|
|
DataTypeTuple(const DataTypes & elems, const Strings & names);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-08-31 08:59:21 +00:00
|
|
|
TypeIndex getTypeId() const override { return TypeIndex::Tuple; }
|
2018-12-13 13:41:47 +00:00
|
|
|
std::string doGetName() const override;
|
2017-07-16 03:05:40 +00:00
|
|
|
const char * getFamilyName() const override { return "Tuple"; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-16 03:05:40 +00:00
|
|
|
bool canBeInsideNullable() const override { return false; }
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void serializeBinary(const Field & field, WriteBuffer & ostr) const override;
|
|
|
|
void deserializeBinary(Field & field, ReadBuffer & istr) const override;
|
|
|
|
void serializeBinary(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override;
|
|
|
|
void deserializeBinary(IColumn & column, ReadBuffer & istr) const override;
|
2018-06-05 21:39:01 +00:00
|
|
|
void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
|
2018-09-18 13:28:46 +00:00
|
|
|
void deserializeText(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override;
|
2018-06-08 01:51:55 +00:00
|
|
|
void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
|
2018-06-05 21:39:01 +00:00
|
|
|
void deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override;
|
2018-06-08 01:51:55 +00:00
|
|
|
void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-04-17 11:56:55 +00:00
|
|
|
/// Tuples in CSV format will be serialized as separate columns (that is, losing their nesting in the tuple).
|
2018-06-05 21:39:01 +00:00
|
|
|
void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
|
2018-06-08 01:51:55 +00:00
|
|
|
void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-12-03 02:59:59 +00:00
|
|
|
/** Each sub-column in a tuple is serialized in separate stream.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
2018-06-07 18:14:37 +00:00
|
|
|
void enumerateStreams(const StreamCallback & callback, SubstreamPath & path) const override;
|
|
|
|
|
|
|
|
void serializeBinaryBulkStatePrefix(
|
|
|
|
SerializeBinaryBulkSettings & settings,
|
|
|
|
SerializeBinaryBulkStatePtr & state) const override;
|
|
|
|
|
|
|
|
void serializeBinaryBulkStateSuffix(
|
|
|
|
SerializeBinaryBulkSettings & settings,
|
|
|
|
SerializeBinaryBulkStatePtr & state) const override;
|
|
|
|
|
|
|
|
void deserializeBinaryBulkStatePrefix(
|
|
|
|
DeserializeBinaryBulkSettings & settings,
|
|
|
|
DeserializeBinaryBulkStatePtr & state) const override;
|
2017-12-03 02:59:59 +00:00
|
|
|
|
|
|
|
void serializeBinaryBulkWithMultipleStreams(
|
2018-06-07 18:14:37 +00:00
|
|
|
const IColumn & column,
|
|
|
|
size_t offset,
|
2019-02-19 00:41:24 +00:00
|
|
|
size_t limit,
|
2018-06-07 18:14:37 +00:00
|
|
|
SerializeBinaryBulkSettings & settings,
|
|
|
|
SerializeBinaryBulkStatePtr & state) const override;
|
2018-05-21 16:21:15 +00:00
|
|
|
|
2017-12-03 02:59:59 +00:00
|
|
|
void deserializeBinaryBulkWithMultipleStreams(
|
2018-06-07 18:14:37 +00:00
|
|
|
IColumn & column,
|
2019-02-19 00:41:24 +00:00
|
|
|
size_t limit,
|
2018-06-07 18:14:37 +00:00
|
|
|
DeserializeBinaryBulkSettings & settings,
|
|
|
|
DeserializeBinaryBulkStatePtr & state) const override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-02-26 14:06:05 +00:00
|
|
|
void serializeProtobuf(const IColumn & column, size_t row_num, ProtobufWriter & protobuf, size_t & value_index) const override;
|
2020-03-08 22:38:12 +00:00
|
|
|
void deserializeProtobuf(IColumn & column, ProtobufReader & protobuf, bool allow_add_row, bool & row_added) const override;
|
2019-01-23 19:41:18 +00:00
|
|
|
|
2017-12-14 03:56:56 +00:00
|
|
|
MutableColumnPtr createColumn() const override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
Field getDefault() const override;
|
2017-09-01 21:37:57 +00:00
|
|
|
void insertDefaultInto(IColumn & column) const override;
|
|
|
|
|
2017-12-23 01:05:29 +00:00
|
|
|
bool equals(const IDataType & rhs) const override;
|
|
|
|
|
2017-12-09 06:32:22 +00:00
|
|
|
bool isParametric() const override { return true; }
|
|
|
|
bool haveSubtypes() const override { return !elems.empty(); }
|
2017-12-20 07:36:30 +00:00
|
|
|
bool isComparable() const override;
|
2017-12-09 06:32:22 +00:00
|
|
|
bool textCanContainOnlyValidUTF8() const override;
|
|
|
|
bool haveMaximumSizeOfValue() const override;
|
|
|
|
size_t getMaximumSizeOfValueInMemory() const override;
|
|
|
|
size_t getSizeOfValueInMemory() const override;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const DataTypes & getElements() const { return elems; }
|
2017-12-23 04:29:34 +00:00
|
|
|
const Strings & getElementNames() const { return names; }
|
2017-12-24 09:34:40 +00:00
|
|
|
|
|
|
|
size_t getPositionByName(const String & name) const;
|
2018-09-20 15:24:16 +00:00
|
|
|
|
|
|
|
bool haveExplicitNames() const { return have_explicit_names; }
|
2012-08-23 18:43:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|