mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Additional test
This commit is contained in:
parent
cec3af45e5
commit
0e664807e9
@ -65,20 +65,4 @@ void ASTDictionaryAttributeDeclaration::formatImpl(const FormatSettings & settin
|
||||
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << "IS_OBJECT_ID";
|
||||
}
|
||||
|
||||
//ASTPtr ASTDictionaryAttributesDeclarations::clone() const
|
||||
//{
|
||||
// auto res = std::make_shared<ASTDictionaryAttributesDeclarations>();
|
||||
//
|
||||
// if (attributes)
|
||||
// res->set(res->attributes, attributes->clone());
|
||||
//
|
||||
// return res;
|
||||
//}
|
||||
//
|
||||
//void ASTDictionaryAttributesDeclarations::formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const
|
||||
//{
|
||||
// if (attributes)
|
||||
// attributes->IAST::formatImpl(s, state, frame);
|
||||
//}
|
||||
|
||||
}
|
||||
|
@ -31,17 +31,4 @@ public:
|
||||
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
||||
};
|
||||
|
||||
|
||||
//class ASTDictionaryAttributesDeclarations : public IAST
|
||||
//{
|
||||
//public:
|
||||
// ASTExpressionList * attributes = nullptr;
|
||||
//
|
||||
// String getID(char) const override { return "Dictionary attributes definition"; }
|
||||
//
|
||||
// ASTPtr clone() const override;
|
||||
//
|
||||
// void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override;
|
||||
//};
|
||||
|
||||
}
|
||||
|
@ -77,6 +77,12 @@ bool ParserDictionaryAttributeDeclaration::parseImpl(Pos & pos, ASTPtr & node, E
|
||||
attribute_declaration->children.push_back(std::move(default_value));
|
||||
}
|
||||
|
||||
if (expression)
|
||||
{
|
||||
attribute_declaration->expression = expression;
|
||||
attribute_declaration->children.push_back(std::move(expression));
|
||||
}
|
||||
|
||||
if (hierarchical)
|
||||
attribute_declaration->hierarchical = true;
|
||||
|
||||
|
@ -118,3 +118,51 @@ TEST(ParserCreateDictionary, SimpleDictionary)
|
||||
EXPECT_EQ(attributes_children[1]->as<ASTDictionaryAttributeDeclaration>()->is_object_id, false);
|
||||
EXPECT_EQ(attributes_children[2]->as<ASTDictionaryAttributeDeclaration>()->is_object_id, false);
|
||||
}
|
||||
|
||||
|
||||
TEST(ParserCreateDictionary, AttributesWithMultipleProperties)
|
||||
{
|
||||
String input = " CREATE DICTIONARY dict2"
|
||||
" ("
|
||||
" key_column UInt64 IS_OBJECT_ID,"
|
||||
" second_column UInt8 DEFAULT 1 HIERARCHICAL INJECTIVE,"
|
||||
" third_column UInt8 DEFAULT 2 EXPRESSION rand() % 100 * 77"
|
||||
" )"
|
||||
" PRIMARY KEY key_column"
|
||||
" SOURCE(CLICKHOUSE(HOST 'localhost'))";
|
||||
|
||||
ParserCreateDictionaryQuery parser;
|
||||
ASTPtr ast = parseQuery(parser, input.data(), input.data() + input.size(), "", 0);
|
||||
ASTCreateQuery * create = ast->as<ASTCreateQuery>();
|
||||
EXPECT_EQ(create->table, "dict2");
|
||||
EXPECT_EQ(create->database, "");
|
||||
|
||||
/// test attributes
|
||||
EXPECT_NE(create->dictionary_attributes_list, nullptr);
|
||||
|
||||
auto attributes_children = create->dictionary_attributes_list->children;
|
||||
EXPECT_EQ(attributes_children[0]->as<ASTDictionaryAttributeDeclaration>()->name, "key_column");
|
||||
EXPECT_EQ(attributes_children[1]->as<ASTDictionaryAttributeDeclaration>()->name, "second_column");
|
||||
EXPECT_EQ(attributes_children[2]->as<ASTDictionaryAttributeDeclaration>()->name, "third_column");
|
||||
|
||||
EXPECT_EQ(attributes_children[0]->as<ASTDictionaryAttributeDeclaration>()->default_value, nullptr);
|
||||
EXPECT_EQ(attributes_children[1]->as<ASTDictionaryAttributeDeclaration>()->default_value->as<ASTLiteral>()->value.get<UInt64>(), 1);
|
||||
EXPECT_EQ(attributes_children[2]->as<ASTDictionaryAttributeDeclaration>()->default_value->as<ASTLiteral>()->value.get<UInt64>(), 2);
|
||||
|
||||
EXPECT_EQ(attributes_children[0]->as<ASTDictionaryAttributeDeclaration>()->expression, nullptr);
|
||||
EXPECT_EQ(attributes_children[1]->as<ASTDictionaryAttributeDeclaration>()->expression, nullptr);
|
||||
EXPECT_EQ(serializeAST(*attributes_children[2]->as<ASTDictionaryAttributeDeclaration>()->expression, true), "(rand() % 100) * 77");
|
||||
|
||||
EXPECT_EQ(attributes_children[0]->as<ASTDictionaryAttributeDeclaration>()->hierarchical, false);
|
||||
EXPECT_EQ(attributes_children[1]->as<ASTDictionaryAttributeDeclaration>()->hierarchical, true);
|
||||
EXPECT_EQ(attributes_children[2]->as<ASTDictionaryAttributeDeclaration>()->hierarchical, false);
|
||||
|
||||
EXPECT_EQ(attributes_children[0]->as<ASTDictionaryAttributeDeclaration>()->injective, false);
|
||||
EXPECT_EQ(attributes_children[1]->as<ASTDictionaryAttributeDeclaration>()->injective, true);
|
||||
EXPECT_EQ(attributes_children[2]->as<ASTDictionaryAttributeDeclaration>()->injective, false);
|
||||
|
||||
EXPECT_EQ(attributes_children[0]->as<ASTDictionaryAttributeDeclaration>()->is_object_id, true);
|
||||
EXPECT_EQ(attributes_children[1]->as<ASTDictionaryAttributeDeclaration>()->is_object_id, false);
|
||||
EXPECT_EQ(attributes_children[2]->as<ASTDictionaryAttributeDeclaration>()->is_object_id, false);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user