#include #include #include #include #include #include #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int LOGICAL_ERROR; extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; } StoragePtr ITableFunctionFileLike::executeImpl(const ASTPtr & ast_function, const Context & context, const std::string & table_name) const { /// Parse args ASTs & args_func = ast_function->children; if (args_func.size() != 1) throw Exception("Table function '" + getName() + "' must have arguments.", ErrorCodes::LOGICAL_ERROR); ASTs & args = args_func.at(0)->children; if (args.size() < 2) throw Exception("Table function '" + getName() + "' requires at least 2 arguments", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); for (auto & arg : args) arg = evaluateConstantExpressionOrIdentifierAsLiteral(arg, context); std::string filename = args[0]->as().value.safeGet(); std::string format = args[1]->as().value.safeGet(); 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); } else 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); ColumnsDescription columns; std::string compression_method = "auto"; if (args.size() > 2) { auto structure = args[2]->as().value.safeGet(); columns = parseColumnsListFromString(structure, context); } if (args.size() == 4) compression_method = args[3]->as().value.safeGet(); context.checkAccess(getRequiredAccessType()); /// Create table StoragePtr storage = getStorage(filename, format, columns, const_cast(context), table_name, compression_method); storage->startup(); return storage; } }