Skip to content

Commit 3dd998e

Browse files
authored
Merge pull request #210 from 1261385937/master
fix CreateColumnFromAst
2 parents 66e9c54 + 1ec61ff commit 3dd998e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

clickhouse/columns/factory.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,16 @@ static ColumnRef CreateColumnFromAst(const TypeAst& ast, CreateColumnByTypeSetti
137137

138138
case TypeAst::Enum: {
139139
std::vector<Type::EnumItem> enum_items;
140+
//ast.elements.size() minimum is 1.
141+
if ((ast.elements.size() % 2) != 0) {
142+
throw ValidationError(ast.name + " content is not correct");
143+
}
140144

141145
enum_items.reserve(ast.elements.size() / 2);
142146
for (size_t i = 0; i < ast.elements.size(); i += 2) {
143147
enum_items.push_back(
144-
Type::EnumItem{ast.elements[i].value_string,
145-
(int16_t)ast.elements[i + 1].value});
148+
Type::EnumItem{ ast.elements[i].value_string,
149+
(int16_t)ast.elements[i + 1].value });
146150
}
147151

148152
if (ast.code == Type::Enum8) {

ut/types_ut.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ TEST(TypesCase, IsEqual) {
8686
"DateTime64(3, 'UTC')",
8787
"Decimal(9,3)",
8888
"Decimal(18,3)",
89-
"Enum8()",
90-
"Enum16()",
9189
"Enum8('ONE' = 1)",
9290
"Enum8('ONE' = 1, 'TWO' = 2)",
9391
"Enum16('ONE' = 1, 'TWO' = 2, 'THREE' = 3, 'FOUR' = 4)",
@@ -127,3 +125,17 @@ TEST(TypesCase, IsEqual) {
127125
}
128126
}
129127
}
128+
129+
TEST(TypesCase, ErrorEnumContent) {
130+
const std::string type_names[] = {
131+
"Enum8()",
132+
"Enum8('ONE')",
133+
"Enum8('ONE'=1,'TWO')",
134+
"Enum16('TWO'=,'TWO')",
135+
};
136+
137+
for (const auto& type_name : type_names) {
138+
SCOPED_TRACE(type_name);
139+
EXPECT_THROW(clickhouse::CreateColumnByType(type_name)->Type(), ValidationError);
140+
}
141+
}

0 commit comments

Comments
 (0)