mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Fix error
This commit is contained in:
parent
e1a24c9dd6
commit
bc11463896
@ -46,60 +46,6 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
/// Wrapper to allow mixed lists of nested and normal types.
|
||||
/// Parameters are either:
|
||||
/// - Nested table elements;
|
||||
/// - Enum element in form of 'a' = 1;
|
||||
/// - literal;
|
||||
/// - Dynamic type arguments;
|
||||
/// - another data type (or identifier);
|
||||
class ParserDataTypeArgument : public IParserBase
|
||||
{
|
||||
public:
|
||||
explicit ParserDataTypeArgument(std::string_view type_name_) : type_name(type_name_)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
const char * getName() const override { return "data type argument"; }
|
||||
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
||||
{
|
||||
if (type_name == "Dynamic")
|
||||
{
|
||||
DynamicArgumentsParser parser;
|
||||
return parser.parse(pos, node, expected);
|
||||
}
|
||||
else if (type_name == "Nested")
|
||||
{
|
||||
ParserNestedTable nested_parser;
|
||||
return nested_parser.parse(pos, node, expected);
|
||||
}
|
||||
else if (type_name == "AggregateFunction" || type_name == "SimpleAggregateFunction")
|
||||
{
|
||||
ParserFunction function_parser;
|
||||
ParserIdentifier identifier_parser;
|
||||
ParserAllCollectionsOfLiterals literal_parser(false);
|
||||
return function_parser.parse(pos, node, expected)
|
||||
|| literal_parser.parse(pos, node, expected)
|
||||
|| identifier_parser.parse(pos, node, expected);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParserDataType data_type_parser;
|
||||
ParserAllCollectionsOfLiterals literal_parser(false);
|
||||
|
||||
const char * operators[] = {"=", "equals", nullptr};
|
||||
ParserLeftAssociativeBinaryOperatorList enum_parser(operators, std::make_unique<ParserLiteral>());
|
||||
|
||||
return enum_parser.parse(pos, node, expected)
|
||||
|| literal_parser.parse(pos, node, expected)
|
||||
|| data_type_parser.parse(pos, node, expected);
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view type_name;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
bool ParserDataType::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
||||
@ -221,11 +167,91 @@ bool ParserDataType::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
||||
++pos;
|
||||
|
||||
/// Parse optional parameters
|
||||
ParserList args_parser(std::make_unique<ParserDataTypeArgument>(type_name), std::make_unique<ParserToken>(TokenType::Comma));
|
||||
ASTPtr expr_list_args;
|
||||
ASTPtr expr_list_args = std::make_shared<ASTExpressionList>();
|
||||
|
||||
/// Allow mixed lists of nested and normal types.
|
||||
/// Parameters are either:
|
||||
/// - Nested table elements;
|
||||
/// - Enum element in form of 'a' = 1;
|
||||
/// - literal;
|
||||
/// - Dynamic type arguments;
|
||||
/// - another data type (or identifier);
|
||||
|
||||
size_t arg_num = 0;
|
||||
bool have_version_of_aggregate_function = false;
|
||||
while (true)
|
||||
{
|
||||
if (arg_num > 0)
|
||||
{
|
||||
if (pos->type == TokenType::Comma)
|
||||
++pos;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
ASTPtr arg;
|
||||
if (type_name == "Dynamic")
|
||||
{
|
||||
DynamicArgumentsParser parser;
|
||||
parser.parse(pos, arg, expected);
|
||||
}
|
||||
else if (type_name == "Nested")
|
||||
{
|
||||
ParserNestedTable nested_parser;
|
||||
nested_parser.parse(pos, arg, expected);
|
||||
}
|
||||
else if (type_name == "AggregateFunction" || type_name == "SimpleAggregateFunction")
|
||||
{
|
||||
/// This is less trivial.
|
||||
/// The first optional argument for AggregateFunction is a numeric literal, defining the version.
|
||||
/// The next argument is the function name, optionally with parameters.
|
||||
/// Subsequent arguments are data types.
|
||||
|
||||
if (arg_num == 0 && type_name == "AggregateFunction")
|
||||
{
|
||||
ParserUnsignedInteger version_parser;
|
||||
if (version_parser.parse(pos, arg, expected))
|
||||
{
|
||||
have_version_of_aggregate_function = true;
|
||||
expr_list_args->children.emplace_back(std::move(arg));
|
||||
++arg_num;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (arg_num == (have_version_of_aggregate_function ? 1 : 0))
|
||||
{
|
||||
ParserFunction function_parser;
|
||||
ParserIdentifier identifier_parser;
|
||||
function_parser.parse(pos, arg, expected)
|
||||
|| identifier_parser.parse(pos, arg, expected);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParserDataType data_type_parser;
|
||||
data_type_parser.parse(pos, arg, expected);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParserDataType data_type_parser;
|
||||
ParserAllCollectionsOfLiterals literal_parser(false);
|
||||
|
||||
const char * operators[] = {"=", "equals", nullptr};
|
||||
ParserLeftAssociativeBinaryOperatorList enum_parser(operators, std::make_unique<ParserLiteral>());
|
||||
|
||||
enum_parser.parse(pos, arg, expected)
|
||||
|| literal_parser.parse(pos, arg, expected)
|
||||
|| data_type_parser.parse(pos, arg, expected);
|
||||
}
|
||||
|
||||
if (!arg)
|
||||
break;
|
||||
|
||||
expr_list_args->children.emplace_back(std::move(arg));
|
||||
++arg_num;
|
||||
}
|
||||
|
||||
if (!args_parser.parse(pos, expr_list_args, expected))
|
||||
return false;
|
||||
if (pos->type == TokenType::Comma)
|
||||
// ignore trailing comma inside Nested structures like Tuple(Int, Tuple(Int, String),)
|
||||
++pos;
|
||||
|
Loading…
Reference in New Issue
Block a user