Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions clickhouse/columns/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,17 @@ static ColumnRef CreateTerminalColumn(const TypeAst& ast) {
static ColumnRef CreateColumnFromAst(const TypeAst& ast, CreateColumnByTypeSettings settings) {
switch (ast.meta) {
case TypeAst::Array: {
return std::make_shared<ColumnArray>(
CreateColumnFromAst(GetASTChildElement(ast, 0), settings)
);
if (auto nested = CreateColumnFromAst(GetASTChildElement(ast, 0), settings)) {
return std::make_shared<ColumnArray>(nested);
}
return nullptr;
}

case TypeAst::Nullable: {
return std::make_shared<ColumnNullable>(
CreateColumnFromAst(GetASTChildElement(ast, 0), settings),
std::make_shared<ColumnUInt8>()
);
if (auto nested = CreateColumnFromAst(GetASTChildElement(ast, 0), settings)) {
return std::make_shared<ColumnNullable>(nested, std::make_shared<ColumnUInt8>());
}
return nullptr;
}

case TypeAst::Terminal: {
Expand Down Expand Up @@ -252,12 +253,11 @@ static ColumnRef CreateColumnFromAst(const TypeAst& ast, CreateColumnByTypeSetti
// item and would omit the null item, producing an incorrect nullable
// dictionary.
// 2. It lets us construct the ColumnNullable with an explicit UInt8 null-map.
return std::make_shared<ColumnLowCardinality>(
std::make_shared<ColumnNullable>(
CreateColumnFromAst(GetASTChildElement(nested, 0), settings),
std::make_shared<ColumnUInt8>()
)
);
if (auto inner = CreateColumnFromAst(GetASTChildElement(nested, 0), settings)) {
return std::make_shared<ColumnLowCardinality>(
std::make_shared<ColumnNullable>(inner, std::make_shared<ColumnUInt8>()));
}
throw UnimplementedError("LowCardinality(Nullable(" + GetASTChildElement(nested, 0).name + ")) is not supported");
default: {
// Generic LowCardinality(T): build the inner column and
// wrap it. Works for any fixed-size dictionary type that
Expand Down
29 changes: 29 additions & 0 deletions ut/CreateColumnByType_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ TEST(CreateColumnByType, UnmatchedBrackets) {
ASSERT_EQ(nullptr, CreateColumnByType("Array(LowCardinality(Nullable(FixedString(10000)))"));
}

TEST(CreateColumnByType, UnsupportedNestedType) {
// A wrapper over a type the factory cannot create must not be built around a null nested column.
for (const char* type_name : {
"Nullable(5)",
"Nullable(DateTime64)",
"Array(Nullable(5))",
"Array(Null)",
"Array(DateTime64)",
"Array(5)",
"Array(Time64)",
}) {
EXPECT_EQ(nullptr, CreateColumnByType(type_name)) << type_name;
}

EXPECT_THROW(CreateColumnByType("LowCardinality(Nullable(5))"), UnimplementedError);
EXPECT_THROW(CreateColumnByType("LowCardinality(Nullable(DateTime64))"), UnimplementedError);

for (const char* type_name : {
"Nullable(UInt8)",
"Array(String)",
"LowCardinality(Nullable(String))",
"Array(Nullable(DateTime64(3)))",
}) {
const auto col = CreateColumnByType(type_name);
ASSERT_NE(nullptr, col) << type_name;
EXPECT_EQ(type_name, col->GetType().GetName());
}
}

TEST(CreateColumnByType, LowCardinalityAsWrappedColumn) {
CreateColumnByTypeSettings create_column_settings;
create_column_settings.low_cardinality_as_wrapped_column = true;
Expand Down
Loading