From 62a0ee8255ffc3404b2a1865a509646a629a8ed4 Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Tue, 20 Oct 2020 15:29:46 +0300 Subject: [PATCH] fix assertion in table function file() --- src/TableFunctions/ITableFunctionFileLike.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/TableFunctions/ITableFunctionFileLike.cpp b/src/TableFunctions/ITableFunctionFileLike.cpp index f876da02fd1..1349c166474 100644 --- a/src/TableFunctions/ITableFunctionFileLike.cpp +++ b/src/TableFunctions/ITableFunctionFileLike.cpp @@ -23,6 +23,7 @@ namespace ErrorCodes extern const int LOGICAL_ERROR; extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; extern const int INCORRECT_FILE_NAME; + extern const int BAD_ARGUMENTS; } 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 (format != "Distributed") - throw Exception("Table function '" + getName() + "' allows 2 arguments only for Distributed format.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); + if (format == "Distributed") + 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).", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); - if (args.size() > 2) - structure = args[2]->as().value.safeGet(); + structure = args[2]->as().value.safeGet(); + if (structure.empty()) + throw Exception("Table structure is empty", ErrorCodes::BAD_ARGUMENTS); if (args.size() == 4) compression_method = args[3]->as().value.safeGet();