Merge branch 'master' of github.com:ClickHouse/ClickHouse

This commit is contained in:
s-kat 2021-05-28 01:58:03 +03:00
commit 6a433a0efd
6 changed files with 53 additions and 5 deletions

View File

@ -307,26 +307,30 @@ SerializationPtr DataTypeTuple::getSubcolumnSerialization(
SerializationPtr DataTypeTuple::doGetDefaultSerialization() const SerializationPtr DataTypeTuple::doGetDefaultSerialization() const
{ {
SerializationTuple::ElementSerializations serializations(elems.size()); SerializationTuple::ElementSerializations serializations(elems.size());
bool use_explicit_names = have_explicit_names && serialize_names;
for (size_t i = 0; i < elems.size(); ++i) for (size_t i = 0; i < elems.size(); ++i)
{ {
String elem_name = use_explicit_names ? names[i] : toString(i + 1);
auto serialization = elems[i]->getDefaultSerialization(); auto serialization = elems[i]->getDefaultSerialization();
serializations[i] = std::make_shared<SerializationTupleElement>(serialization, names[i]); serializations[i] = std::make_shared<SerializationTupleElement>(serialization, elem_name);
} }
return std::make_shared<SerializationTuple>(std::move(serializations), have_explicit_names); return std::make_shared<SerializationTuple>(std::move(serializations), use_explicit_names);
} }
SerializationPtr DataTypeTuple::getSerialization(const String & column_name, const StreamExistenceCallback & callback) const SerializationPtr DataTypeTuple::getSerialization(const String & column_name, const StreamExistenceCallback & callback) const
{ {
SerializationTuple::ElementSerializations serializations(elems.size()); SerializationTuple::ElementSerializations serializations(elems.size());
bool use_explicit_names = have_explicit_names && serialize_names;
for (size_t i = 0; i < elems.size(); ++i) for (size_t i = 0; i < elems.size(); ++i)
{ {
auto subcolumn_name = Nested::concatenateName(column_name, names[i]); String elem_name = use_explicit_names ? names[i] : toString(i + 1);
auto subcolumn_name = Nested::concatenateName(column_name, elem_name);
auto serializaion = elems[i]->getSerialization(subcolumn_name, callback); auto serializaion = elems[i]->getSerialization(subcolumn_name, callback);
serializations[i] = std::make_shared<SerializationTupleElement>(serializaion, names[i]); serializations[i] = std::make_shared<SerializationTupleElement>(serializaion, elem_name);
} }
return std::make_shared<SerializationTuple>(std::move(serializations), have_explicit_names); return std::make_shared<SerializationTuple>(std::move(serializations), use_explicit_names);
} }
static DataTypePtr create(const ASTPtr & arguments) static DataTypePtr create(const ASTPtr & arguments)

View File

@ -51,6 +51,7 @@ public:
bool supportsSampling() const override { return true; } bool supportsSampling() const override { return true; }
bool supportsFinal() const override { return true; } bool supportsFinal() const override { return true; }
bool supportsPrewhere() const override { return true; } bool supportsPrewhere() const override { return true; }
bool supportsSubcolumns() const override { return true; }
StoragePolicyPtr getStoragePolicy() const override; StoragePolicyPtr getStoragePolicy() const override;
bool isRemote() const override { return true; } bool isRemote() const override { return true; }

View File

@ -0,0 +1,6 @@
0 [('string',0)]
1 [('string',1)]
2 [('string',2)]
0 [('string',0)]
1 [('string',1)]
2 [('string',2)]

View File

@ -0,0 +1,14 @@
DROP TABLE IF EXISTS t_create_as_tuple;
CREATE TABLE t_create_as_tuple ENGINE = MergeTree()
ORDER BY number AS
SELECT number, [('string',number)] AS array FROM numbers(3);
SELECT * FROM t_create_as_tuple ORDER BY number;
DETACH TABLE t_create_as_tuple;
ATTACH TABLE t_create_as_tuple;
SELECT * FROM t_create_as_tuple ORDER BY number;
DROP TABLE t_create_as_tuple;

View File

@ -0,0 +1,2 @@
3 0 bbb ccc
3 0 bbb ccc

View File

@ -0,0 +1,21 @@
DROP TABLE IF EXISTS t_subcolumns_local;
DROP TABLE IF EXISTS t_subcolumns_dist;
CREATE TABLE t_subcolumns_local (arr Array(UInt32), n Nullable(String), t Tuple(s1 String, s2 String))
ENGINE = MergeTree ORDER BY tuple();
CREATE TABLE t_subcolumns_dist AS t_subcolumns_local ENGINE = Distributed(test_cluster_two_shards, currentDatabase(), t_subcolumns_local);
INSERT INTO t_subcolumns_local VALUES ([1, 2, 3], 'aaa', ('bbb', 'ccc'));
SELECT arr.size0, n.null, t.s1, t.s2 FROM t_subcolumns_dist;
DROP TABLE t_subcolumns_local;
-- StripeLog doesn't support subcolumns.
CREATE TABLE t_subcolumns_local (arr Array(UInt32), n Nullable(String), t Tuple(s1 String, s2 String)) ENGINE = StripeLog;
SELECT arr.size0, n.null, t.s1, t.s2 FROM t_subcolumns_dist; -- { serverError 47 }
DROP TABLE t_subcolumns_local;
DROP TABLE t_subcolumns_dist;