提交 60c1ffc8 编写于 作者: A Alexey Milovidov

Implement supertype for LowCardinality

上级 1f978022
...@@ -161,62 +161,62 @@ DataTypePtr getLeastSupertype(const DataTypes & types) ...@@ -161,62 +161,62 @@ DataTypePtr getLeastSupertype(const DataTypes & types)
} }
} }
/// For Nullable /// For LowCardinality. This is above Nullable, because LowCardinality can contain Nullable but cannot be inside Nullable.
{ {
bool have_nullable = false; bool have_low_cardinality = false;
bool have_not_low_cardinality = false;
DataTypes nested_types; DataTypes nested_types;
nested_types.reserve(types.size()); nested_types.reserve(types.size());
for (const auto & type : types) for (const auto & type : types)
{ {
if (const DataTypeNullable * type_nullable = typeid_cast<const DataTypeNullable *>(type.get())) if (const DataTypeLowCardinality * type_low_cardinality = typeid_cast<const DataTypeLowCardinality *>(type.get()))
{ {
have_nullable = true; have_low_cardinality = true;
nested_types.emplace_back(type_low_cardinality->getDictionaryType());
if (!type_nullable->onlyNull())
nested_types.emplace_back(type_nullable->getNestedType());
} }
else else
{
have_not_low_cardinality = true;
nested_types.emplace_back(type); nested_types.emplace_back(type);
} }
}
if (have_nullable) /// All LowCardinality gives LowCardinality.
/// LowCardinality with high cardinality gives high cardinality.
if (have_low_cardinality)
{ {
return std::make_shared<DataTypeNullable>(getLeastSupertype(nested_types)); if (have_not_low_cardinality)
return getLeastSupertype(nested_types);
else
return std::make_shared<DataTypeLowCardinality>(getLeastSupertype(nested_types));
} }
} }
/// For LowCardinality /// For Nullable
{ {
bool have_low_cardinality = false; bool have_nullable = false;
bool have_not_low_cardinality = false;
DataTypes nested_types; DataTypes nested_types;
nested_types.reserve(types.size()); nested_types.reserve(types.size());
for (const auto & type : types) for (const auto & type : types)
{ {
if (const DataTypeLowCardinality * type_low_cardinality = typeid_cast<const DataTypeLowCardinality *>(type.get())) if (const DataTypeNullable * type_nullable = typeid_cast<const DataTypeNullable *>(type.get()))
{ {
have_low_cardinality = true; have_nullable = true;
nested_types.emplace_back(type_low_cardinality->getDictionaryType());
if (!type_nullable->onlyNull())
nested_types.emplace_back(type_nullable->getNestedType());
} }
else else
{
have_not_low_cardinality = true;
nested_types.emplace_back(type); nested_types.emplace_back(type);
} }
}
/// All LowCardinality gives LowCardinality. if (have_nullable)
/// LowCardinality with high cardinality gives high cardinality.
if (have_low_cardinality)
{ {
if (have_not_low_cardinality) return std::make_shared<DataTypeNullable>(getLeastSupertype(nested_types));
return getLeastSupertype(nested_types);
else
return std::make_shared<DataTypeLowCardinality>(getLeastSupertype(nested_types));
} }
} }
......
hello
hello
String
String
---
---
hello
hello
hello
hello
---
hello
hello
-
hello
hello
-
hello
hello
-
hello
hello
-
hello
hello
-
hello
hello
-
hello
hello
-
hello
hello
-
hello
hello
-
hello
hello
-
hello
hello
-
hello
hello
---
hello
hello
hello
-
hello
hello
hello
-
hello
hello
hello
-
hello
hello
hello
---
hello
hello
hello
hello
---
['abc','def']
['abc','def']
['abc','def']
SELECT 'hello' UNION ALL SELECT toLowCardinality('hello');
SELECT toTypeName(x) FROM (SELECT 'hello' AS x UNION ALL SELECT toLowCardinality('hello'));
SELECT '---';
create temporary table t1(a String);
create temporary table t2(a LowCardinality(String));
select a from t1 union all select a from t2;
SELECT '---';
CREATE TEMPORARY TABLE a (x String);
CREATE TEMPORARY TABLE b (x LowCardinality(String));
CREATE TEMPORARY TABLE c (x Nullable(String));
CREATE TEMPORARY TABLE d (x LowCardinality(Nullable(String)));
INSERT INTO a VALUES ('hello');
INSERT INTO b VALUES ('hello');
INSERT INTO c VALUES ('hello');
INSERT INTO d VALUES ('hello');
SELECT x FROM a;
SELECT x FROM b;
SELECT x FROM c;
SELECT x FROM d;
SELECT '---';
SELECT x FROM a UNION ALL SELECT x FROM b;
SELECT '-';
SELECT x FROM a UNION ALL SELECT x FROM c;
SELECT '-';
SELECT x FROM a UNION ALL SELECT x FROM d;
SELECT '-';
SELECT x FROM b UNION ALL SELECT x FROM a;
SELECT '-';
SELECT x FROM b UNION ALL SELECT x FROM c;
SELECT '-';
SELECT x FROM b UNION ALL SELECT x FROM d;
SELECT '-';
SELECT x FROM c UNION ALL SELECT x FROM a;
SELECT '-';
SELECT x FROM c UNION ALL SELECT x FROM b;
SELECT '-';
SELECT x FROM c UNION ALL SELECT x FROM d;
SELECT '-';
SELECT x FROM d UNION ALL SELECT x FROM a;
SELECT '-';
SELECT x FROM d UNION ALL SELECT x FROM c;
SELECT '-';
SELECT x FROM d UNION ALL SELECT x FROM b;
SELECT '---';
SELECT x FROM b UNION ALL SELECT x FROM c UNION ALL SELECT x FROM d;
SELECT '-';
SELECT x FROM a UNION ALL SELECT x FROM c UNION ALL SELECT x FROM d;
SELECT '-';
SELECT x FROM a UNION ALL SELECT x FROM b UNION ALL SELECT x FROM d;
SELECT '-';
SELECT x FROM a UNION ALL SELECT x FROM b UNION ALL SELECT x FROM c;
SELECT '---';
SELECT x FROM a UNION ALL SELECT x FROM b UNION ALL SELECT x FROM c UNION ALL SELECT x FROM d;
SELECT '---';
SELECT [CAST('abc' AS LowCardinality(String)), CAST('def' AS Nullable(String))];
SELECT [CAST('abc' AS LowCardinality(String)), CAST('def' AS FixedString(3))];
SELECT [CAST('abc' AS LowCardinality(String)), CAST('def' AS LowCardinality(FixedString(3)))];
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册