mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
Fix NOT nULL modifier
This commit is contained in:
parent
7e5de33e93
commit
bee14177cd
@ -287,25 +287,25 @@ ColumnsDescription InterpreterCreateQuery::getColumnsDescription(const ASTExpres
|
||||
const auto & col_decl = ast->as<ASTColumnDeclaration &>();
|
||||
|
||||
DataTypePtr column_type = nullptr;
|
||||
if (col_decl.isNULL && col_decl.isNotNULL)
|
||||
throw Exception{"Cant use NOT NULL and NULL together", ErrorCodes::EMPTY_LIST_OF_COLUMNS_PASSED};
|
||||
if (!col_decl.isNULL && col_decl.isNot)
|
||||
throw Exception{"Cant use NOT without NULL", ErrorCodes::EMPTY_LIST_OF_COLUMNS_PASSED};
|
||||
|
||||
if (col_decl.type)
|
||||
{
|
||||
column_type = DataTypeFactory::instance().get(col_decl.type);
|
||||
|
||||
if (col_decl.isNULL) {
|
||||
if (col_decl.isNot && col_decl.isNULL) {
|
||||
if (column_type->isNullable())
|
||||
throw Exception{"Cant use NOT NULL with Nullable", ErrorCodes::EMPTY_LIST_OF_COLUMNS_PASSED};
|
||||
} else if (col_decl.isNULL && !col_decl.isNot) {
|
||||
if (column_type->isNullable())
|
||||
throw Exception{"Cant use NULL with Nullable", ErrorCodes::EMPTY_LIST_OF_COLUMNS_PASSED};
|
||||
else {
|
||||
column_type = makeNullable(column_type);
|
||||
}
|
||||
} else if (col_decl.isNotNULL) {
|
||||
if (column_type->isNullable())
|
||||
throw Exception{"Cant use NOT NULL with Nullable", ErrorCodes::EMPTY_LIST_OF_COLUMNS_PASSED};
|
||||
}
|
||||
|
||||
if (context.getSettingsRef().data_type_default_nullable && !column_type->isNullable() && !col_decl.isNotNULL)
|
||||
if (context.getSettingsRef().data_type_default_nullable && !column_type->isNullable() && !col_decl.isNot && !col_decl.isNULL)
|
||||
column_type = makeNullable(column_type);
|
||||
|
||||
column_names_and_types.emplace_back(col_decl.name, column_type);
|
||||
|
@ -22,10 +22,10 @@ ASTPtr ASTColumnDeclaration::clone() const
|
||||
res->children.push_back(res->isNULL);
|
||||
}
|
||||
|
||||
if (isNULL)
|
||||
if (isNot)
|
||||
{
|
||||
res->isNotNULL = isNotNULL;
|
||||
res->children.push_back(res->isNotNULL);
|
||||
res->isNot = isNot;
|
||||
res->children.push_back(res->isNot);
|
||||
}
|
||||
|
||||
if (default_expression)
|
||||
@ -71,17 +71,19 @@ void ASTColumnDeclaration::formatImpl(const FormatSettings & settings, FormatSta
|
||||
type->formatImpl(settings, state, frame);
|
||||
}
|
||||
|
||||
if (isNot)
|
||||
{
|
||||
settings.ostr << ' ';
|
||||
isNot->formatImpl(settings, state, frame);
|
||||
}
|
||||
|
||||
if (isNULL)
|
||||
{
|
||||
settings.ostr << ' ';
|
||||
isNULL->formatImpl(settings, state, frame);
|
||||
}
|
||||
|
||||
if (isNotNULL)
|
||||
{
|
||||
settings.ostr << ' ';
|
||||
isNotNULL->formatImpl(settings, state, frame);
|
||||
}
|
||||
|
||||
|
||||
if (default_expression)
|
||||
{
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
String name;
|
||||
ASTPtr type;
|
||||
ASTPtr isNULL;
|
||||
ASTPtr isNotNULL;
|
||||
ASTPtr isNot;
|
||||
String default_specifier;
|
||||
ASTPtr default_expression;
|
||||
ASTPtr comment;
|
||||
|
@ -118,7 +118,7 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
|
||||
ParserIdentifierWithOptionalParameters type_parser;
|
||||
ParserKeyword s_default{"DEFAULT"};
|
||||
ParserKeyword s_null{"NULL"};
|
||||
ParserKeyword s_not_null{"NOT NULL"};
|
||||
ParserKeyword s_not{"NOT"};
|
||||
ParserKeyword s_materialized{"MATERIALIZED"};
|
||||
ParserKeyword s_alias{"ALIAS"};
|
||||
ParserKeyword s_comment{"COMMENT"};
|
||||
@ -129,7 +129,7 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
|
||||
ParserCodec codec_parser;
|
||||
ParserExpression expression_parser;
|
||||
ParserIdentifier null_parser;
|
||||
ParserIdentifier not_null_parser;
|
||||
ParserCompoundIdentifier not_null_parser;
|
||||
|
||||
/// mandatory column name
|
||||
ASTPtr name;
|
||||
@ -142,7 +142,7 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
|
||||
ASTPtr type;
|
||||
String default_specifier;
|
||||
ASTPtr isNull;
|
||||
ASTPtr isNotNull;
|
||||
ASTPtr isNot;
|
||||
ASTPtr default_expression;
|
||||
ASTPtr comment_expression;
|
||||
ASTPtr codec_expression;
|
||||
@ -171,14 +171,19 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
|
||||
if (require_type && !type && !default_expression)
|
||||
return false; /// reject column name without type
|
||||
|
||||
Pos pos_before_null = pos;
|
||||
// Pos pos_before_null = pos;
|
||||
|
||||
if (s_null.check(pos, expected)) {
|
||||
if (!null_parser.parse(pos_before_null, isNull, expected))
|
||||
return false;
|
||||
} else if (s_not_null.check(pos, expected)) {
|
||||
if (!not_null_parser.parse(pos_before_null, isNotNull, expected))
|
||||
if (s_not.check(pos, expected)) {
|
||||
if (s_null.check(pos, expected)) {
|
||||
isNot = std::make_shared<ASTIdentifier>("NOT");
|
||||
isNull = std::make_shared<ASTIdentifier>("NULL");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (s_null.check(pos, expected)) {
|
||||
isNull = std::make_shared<ASTIdentifier>("NULL");
|
||||
}
|
||||
}
|
||||
|
||||
if (s_comment.ignore(pos, expected))
|
||||
@ -215,9 +220,9 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
|
||||
column_declaration->children.push_back(std::move(isNull));
|
||||
}
|
||||
|
||||
if (isNotNull) {
|
||||
column_declaration->isNotNULL = isNotNull;
|
||||
column_declaration->children.push_back(std::move(isNotNull));
|
||||
if (isNot) {
|
||||
column_declaration->isNot = isNot;
|
||||
column_declaration->children.push_back(std::move(isNot));
|
||||
}
|
||||
|
||||
if (default_expression)
|
||||
|
Loading…
Reference in New Issue
Block a user