mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Merge remote-tracking branch 'upstream/master' into fix3
This commit is contained in:
commit
f3cb0ad7e8
@ -129,8 +129,13 @@ bool JSONEachRowRowInputStream::read(Block & block)
|
||||
|
||||
/// Fill non-visited columns with the default values.
|
||||
for (size_t i = 0; i < columns; ++i)
|
||||
{
|
||||
if (!read_columns[i])
|
||||
block.getByPosition(i).column->insertDefault();
|
||||
{
|
||||
ColumnWithTypeAndName & elem = block.getByPosition(i);
|
||||
elem.type->insertDefaultInto(*elem.column);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -176,8 +176,13 @@ bool TSKVRowInputStream::read(Block & block)
|
||||
|
||||
/// Fill in the not met columns with default values.
|
||||
for (size_t i = 0; i < columns; ++i)
|
||||
{
|
||||
if (!read_columns[i])
|
||||
block.getByPosition(i).column->insertDefault();
|
||||
{
|
||||
ColumnWithTypeAndName & elem = block.getByPosition(i);
|
||||
elem.type->insertDefaultInto(*elem.column);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ void TotalsHavingBlockInputStream::addToTotals(Block & totals, Block & block, co
|
||||
if (init)
|
||||
{
|
||||
ColumnPtr new_column = current.type->createColumn();
|
||||
new_column->insert(current.type->getDefault());
|
||||
current.type->insertDefaultInto(*new_column);
|
||||
totals.insert(ColumnWithTypeAndName(new_column, current.type, current.name));
|
||||
}
|
||||
continue;
|
||||
|
@ -395,6 +395,12 @@ ColumnPtr DataTypeArray::createColumn() const
|
||||
}
|
||||
|
||||
|
||||
Field DataTypeArray::getDefault() const
|
||||
{
|
||||
return Array();
|
||||
}
|
||||
|
||||
|
||||
static DataTypePtr create(const ASTPtr & arguments)
|
||||
{
|
||||
if (arguments->children.size() != 1)
|
||||
|
@ -87,10 +87,7 @@ public:
|
||||
|
||||
ColumnPtr createColumn() const override;
|
||||
|
||||
Field getDefault() const override
|
||||
{
|
||||
return Array();
|
||||
}
|
||||
Field getDefault() const override;
|
||||
|
||||
const DataTypePtr & getNestedType() const { return nested; }
|
||||
const DataTypeTraits::EnrichedDataTypePtr & getEnrichedNestedType() const { return enriched_nested; }
|
||||
|
@ -241,6 +241,12 @@ Field DataTypeEnum<Type>::getDefault() const
|
||||
return typename NearestFieldType<FieldType>::Type(values.front().second);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
void DataTypeEnum<Type>::insertDefaultInto(IColumn & column) const
|
||||
{
|
||||
static_cast<ColumnType &>(column).getData().push_back(values.front().second);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
static void checkOverflow(Int64 value)
|
||||
{
|
||||
|
@ -106,6 +106,7 @@ public:
|
||||
ColumnPtr createColumn() const override { return std::make_shared<ColumnType>(); }
|
||||
|
||||
Field getDefault() const override;
|
||||
void insertDefaultInto(IColumn & column) const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -35,12 +35,12 @@ std::string DataTypeTuple::getName() const
|
||||
|
||||
static inline IColumn & extractElementColumn(IColumn & column, size_t idx)
|
||||
{
|
||||
return *static_cast<ColumnTuple &>(column).getData().getByPosition(idx).column.get();
|
||||
return *static_cast<ColumnTuple &>(column).getData().getByPosition(idx).column;
|
||||
}
|
||||
|
||||
static inline const IColumn & extractElementColumn(const IColumn & column, size_t idx)
|
||||
{
|
||||
return *static_cast<const ColumnTuple &>(column).getData().getByPosition(idx).column.get();
|
||||
return *static_cast<const ColumnTuple &>(column).getData().getByPosition(idx).column;
|
||||
}
|
||||
|
||||
|
||||
@ -68,7 +68,7 @@ void DataTypeTuple::serializeBinary(const IColumn & column, size_t row_num, Writ
|
||||
|
||||
|
||||
template <typename F>
|
||||
static void deserializeSafe(const DataTypes & elems, IColumn & column, ReadBuffer & istr, F && impl)
|
||||
static void addElementSafe(const DataTypes & elems, IColumn & column, F && impl)
|
||||
{
|
||||
/// We use the assumption that tuples of zero size do not exist.
|
||||
size_t old_size = extractElementColumn(column, 0).size();
|
||||
@ -93,7 +93,7 @@ static void deserializeSafe(const DataTypes & elems, IColumn & column, ReadBuffe
|
||||
|
||||
void DataTypeTuple::deserializeBinary(IColumn & column, ReadBuffer & istr) const
|
||||
{
|
||||
deserializeSafe(elems, column, istr, [&]
|
||||
addElementSafe(elems, column, [&]
|
||||
{
|
||||
for (const auto & i : ext::range(0, ext::size(elems)))
|
||||
elems[i]->deserializeBinary(extractElementColumn(column, i), istr);
|
||||
@ -117,7 +117,7 @@ void DataTypeTuple::deserializeText(IColumn & column, ReadBuffer & istr) const
|
||||
const size_t size = elems.size();
|
||||
assertChar('(', istr);
|
||||
|
||||
deserializeSafe(elems, column, istr, [&]
|
||||
addElementSafe(elems, column, [&]
|
||||
{
|
||||
for (const auto i : ext::range(0, size))
|
||||
{
|
||||
@ -169,7 +169,7 @@ void DataTypeTuple::deserializeTextJSON(IColumn & column, ReadBuffer & istr) con
|
||||
const size_t size = elems.size();
|
||||
assertChar('[', istr);
|
||||
|
||||
deserializeSafe(elems, column, istr, [&]
|
||||
addElementSafe(elems, column, [&]
|
||||
{
|
||||
for (const auto i : ext::range(0, size))
|
||||
{
|
||||
@ -208,7 +208,7 @@ void DataTypeTuple::serializeTextCSV(const IColumn & column, size_t row_num, Wri
|
||||
|
||||
void DataTypeTuple::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const
|
||||
{
|
||||
deserializeSafe(elems, column, istr, [&]
|
||||
addElementSafe(elems, column, [&]
|
||||
{
|
||||
const size_t size = elems.size();
|
||||
for (const auto i : ext::range(0, size))
|
||||
@ -256,6 +256,15 @@ Field DataTypeTuple::getDefault() const
|
||||
return Tuple(ext::map<TupleBackend>(elems, [] (const DataTypePtr & elem) { return elem->getDefault(); }));
|
||||
}
|
||||
|
||||
void DataTypeTuple::insertDefaultInto(IColumn & column) const
|
||||
{
|
||||
addElementSafe(elems, column, [&]
|
||||
{
|
||||
for (const auto & i : ext::range(0, ext::size(elems)))
|
||||
elems[i]->insertDefaultInto(extractElementColumn(column, i));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
static DataTypePtr create(const ASTPtr & arguments)
|
||||
{
|
||||
|
@ -53,6 +53,8 @@ public:
|
||||
ColumnPtr createColumn() const override;
|
||||
|
||||
Field getDefault() const override;
|
||||
void insertDefaultInto(IColumn & column) const override;
|
||||
|
||||
const DataTypes & getElements() const { return elems; }
|
||||
};
|
||||
|
||||
|
@ -30,4 +30,9 @@ ColumnPtr IDataType::createConstColumn(size_t size, const Field & field) const
|
||||
return std::make_shared<ColumnConst>(column, size);
|
||||
}
|
||||
|
||||
void IDataType::insertDefaultInto(IColumn & column) const
|
||||
{
|
||||
column.insertDefault();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -149,6 +149,11 @@ public:
|
||||
*/
|
||||
virtual Field getDefault() const = 0;
|
||||
|
||||
/** Directly insert default value into a column. Default implementation use method IColumn::insertDefault.
|
||||
* This should be overriden if data type default value differs from column default value (example: Enum data types).
|
||||
*/
|
||||
virtual void insertDefaultInto(IColumn & column) const;
|
||||
|
||||
/// For fixed-size types, return size of value in bytes. For other data types, return some approximate size just for estimation.
|
||||
virtual size_t getSizeOfField() const
|
||||
{
|
||||
|
@ -63,6 +63,11 @@ public:
|
||||
{
|
||||
throw Exception("Method getDefault() is not implemented for data type " + getName(), ErrorCodes::NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
void insertDefaultInto(IColumn & column) const override
|
||||
{
|
||||
throw Exception("Method insertDefaultInto() is not implemented for data type " + getName(), ErrorCodes::NOT_IMPLEMENTED);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
browser Hello
|
||||
browser Hello
|
||||
browser World 1
|
||||
browser Hello
|
||||
browser World 1
|
||||
browser World 2
|
13
dbms/tests/queries/0_stateless/00499_json_enum_insert.sql
Normal file
13
dbms/tests/queries/0_stateless/00499_json_enum_insert.sql
Normal file
@ -0,0 +1,13 @@
|
||||
DROP TABLE IF EXISTS test.json;
|
||||
CREATE TABLE test.json (x Enum8('browser' = 1, 'mobile' = 2), y String) ENGINE = Memory;
|
||||
|
||||
INSERT INTO test.json (y) VALUES ('Hello');
|
||||
SELECT * FROM test.json ORDER BY y;
|
||||
|
||||
INSERT INTO test.json (y) FORMAT JSONEachRow {"y": "World 1"};
|
||||
SELECT * FROM test.json ORDER BY y;
|
||||
|
||||
INSERT INTO test.json (x, y) FORMAT JSONEachRow {"y": "World 2"};
|
||||
SELECT * FROM test.json ORDER BY y;
|
||||
|
||||
DROP TABLE test.json;
|
Loading…
Reference in New Issue
Block a user