@@ -92,7 +92,8 @@ template <typename NameParser>
9292class IParserColumnDeclaration : public IParserBase
9393{
9494public:
95- explicit IParserColumnDeclaration (bool require_type_ = true ) : require_type(require_type_)
95+ explicit IParserColumnDeclaration (bool require_type_ = true , bool allow_null_modifiers_ = false )
96+ : require_type(require_type_), allow_null_modifiers(allow_null_modifiers_)
9697 {
9798 }
9899
@@ -104,6 +105,7 @@ class IParserColumnDeclaration : public IParserBase
104105 bool parseImpl (Pos & pos, ASTPtr & node, Expected & expected) override ;
105106
106107 bool require_type = true ;
108+ bool allow_null_modifiers = false ;
107109};
108110
109111using ParserColumnDeclaration = IParserColumnDeclaration<ParserIdentifier>;
@@ -126,8 +128,6 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
126128 ParserStringLiteral string_literal_parser;
127129 ParserCodec codec_parser;
128130 ParserExpression expression_parser;
129- ParserIdentifier null_parser;
130- ParserCompoundIdentifier not_null_parser;
131131
132132 // / mandatory column name
133133 ASTPtr name;
@@ -139,8 +139,7 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
139139 */
140140 ASTPtr type;
141141 String default_specifier;
142- ASTPtr is_null;
143- ASTPtr is_not;
142+ std::optional<bool > null_modifier;
144143 ASTPtr default_expression;
145144 ASTPtr comment_expression;
146145 ASTPtr codec_expression;
@@ -169,19 +168,17 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
169168 if (require_type && !type && !default_expression)
170169 return false ; // / reject column name without type
171170
172- // Pos pos_before_null = pos;
173-
174- if (s_not.check (pos, expected))
175- if (s_null.check (pos, expected))
171+ if (type && allow_null_modifiers)
172+ {
173+ if (s_not.ignore (pos, expected))
176174 {
177- is_not = std::make_shared<ASTIdentifier>(" NOT" );
178- is_null = std::make_shared<ASTIdentifier>(" NULL" );
175+ if (!s_null.ignore (pos, expected))
176+ return false ;
177+ null_modifier.emplace (false );
179178 }
180- else
181- return false ;
182- else
183- if (s_null.check (pos, expected))
184- is_null = std::make_shared<ASTIdentifier>(" NULL" );
179+ else if (s_null.ignore (pos, expected))
180+ null_modifier.emplace (true );
181+ }
185182
186183 if (s_comment.ignore (pos, expected))
187184 {
@@ -212,17 +209,7 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
212209 column_declaration->children .push_back (std::move (type));
213210 }
214211
215- if (is_null)
216- {
217- column_declaration->is_null = is_null;
218- column_declaration->children .push_back (std::move (is_null));
219- }
220-
221- if (is_not)
222- {
223- column_declaration->is_not = is_not;
224- column_declaration->children .push_back (std::move (is_not));
225- }
212+ column_declaration->null_modifier = null_modifier;
226213
227214 if (default_expression)
228215 {
0 commit comments