Merge pull request #16189 from ClickHouse/fix_assertion_table_function_file

Fix assertion in table function file()
This commit is contained in:
tavplubix 2020-10-21 22:38:24 +03:00 committed by GitHub
commit 3c53d47840
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,7 @@ namespace ErrorCodes
extern const int LOGICAL_ERROR; extern const int LOGICAL_ERROR;
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int INCORRECT_FILE_NAME; extern const int INCORRECT_FILE_NAME;
extern const int BAD_ARGUMENTS;
} }
void ITableFunctionFileLike::parseArguments(const ASTPtr & ast_function, const Context & context) void ITableFunctionFileLike::parseArguments(const ASTPtr & ast_function, const Context & context)
@ -46,15 +47,18 @@ void ITableFunctionFileLike::parseArguments(const ASTPtr & ast_function, const C
if (args.size() == 2 && getName() == "file") if (args.size() == 2 && getName() == "file")
{ {
if (format != "Distributed") if (format == "Distributed")
throw Exception("Table function '" + getName() + "' allows 2 arguments only for Distributed format.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); return;
throw Exception("Table function '" + getName() + "' allows 2 arguments only for Distributed format.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
} }
else if (args.size() != 3 && args.size() != 4)
if (args.size() != 3 && args.size() != 4)
throw Exception("Table function '" + getName() + "' requires 3 or 4 arguments: filename, format, structure and compression method (default auto).", throw Exception("Table function '" + getName() + "' requires 3 or 4 arguments: filename, format, structure and compression method (default auto).",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
if (args.size() > 2) structure = args[2]->as<ASTLiteral &>().value.safeGet<String>();
structure = args[2]->as<ASTLiteral &>().value.safeGet<String>(); if (structure.empty())
throw Exception("Table structure is empty", ErrorCodes::BAD_ARGUMENTS);
if (args.size() == 4) if (args.size() == 4)
compression_method = args[3]->as<ASTLiteral &>().value.safeGet<String>(); compression_method = args[3]->as<ASTLiteral &>().value.safeGet<String>();