提交 46644aaa 编写于 作者: A Alexey Milovidov

Preparations, part 5: table functions are using const Context for execution [#CLICKHOUSE-31].

上级 2b20eca0
......@@ -32,7 +32,7 @@ public:
virtual std::string getName() const = 0;
/// Create storage according to the query
virtual StoragePtr execute(ASTPtr ast_function, Context & context) const = 0;
virtual StoragePtr execute(ASTPtr ast_function, const Context & context) const = 0;
virtual ~ITableFunction() {};
};
......
......@@ -25,9 +25,9 @@ TableFunctionPtr TableFunctionFactory::get(
if (context.getSettings().limits.readonly == 1) /** For example, for readonly = 2 - allowed. */
throw Exception("Table functions are forbidden in readonly mode", ErrorCodes::READONLY);
if (name == "merge") return std::make_shared<TableFunctionMerge>();
else if (name == "remote") return std::make_shared<TableFunctionRemote>();
else if (name == "shardByHash") return std::make_shared<TableFunctionShardByHash>();
if (name == "merge") return std::make_shared<TableFunctionMerge>();
else if (name == "remote") return std::make_shared<TableFunctionRemote>();
else if (name == "shardByHash") return std::make_shared<TableFunctionShardByHash>();
else
throw Exception("Unknown table function " + name, ErrorCodes::UNKNOWN_FUNCTION);
}
......
......@@ -53,7 +53,7 @@ static NamesAndTypesList chooseColumns(const String & source_database, const Str
}
StoragePtr TableFunctionMerge::execute(ASTPtr ast_function, Context & context) const
StoragePtr TableFunctionMerge::execute(ASTPtr ast_function, const Context & context) const
{
ASTs & args_func = typeid_cast<ASTFunction &>(*ast_function).children;
......
......@@ -6,8 +6,7 @@
namespace DB
{
/*
* merge (db_name, tables_regexp) - creates a temporary StorageMerge.
/* merge (db_name, tables_regexp) - creates a temporary StorageMerge.
* The structure of the table is taken from the first table that came up, suitable for regexp.
* If there is no such table, an exception is thrown.
*/
......@@ -15,7 +14,7 @@ class TableFunctionMerge: public ITableFunction
{
public:
std::string getName() const override { return "merge"; }
StoragePtr execute(ASTPtr ast_function, Context & context) const override;
StoragePtr execute(ASTPtr ast_function, const Context & context) const override;
};
......
......@@ -146,7 +146,8 @@ static std::vector<String> parseDescription(const String & description, size_t l
}
buffer.push_back(cur);
}
} else if (have_splitter) /// If there is a current delimiter inside, then generate a set of resulting rows
}
else if (have_splitter) /// If there is a current delimiter inside, then generate a set of resulting rows
buffer = parseDescription(description, i + 1, m, separator, max_addresses);
else /// Otherwise just copy, spawn will occur when you call with the correct delimiter
buffer.push_back(description.substr(i, m - i + 1));
......@@ -168,15 +169,17 @@ static std::vector<String> parseDescription(const String & description, size_t l
append(cur, buffer, max_addresses);
}
}
res.insert(res.end(), cur.begin(), cur.end());
if (res.size() > max_addresses)
throw Exception("Storage Distributed, first argument generates too many result addresses",
ErrorCodes::BAD_ARGUMENTS);
ErrorCodes::BAD_ARGUMENTS);
return res;
}
StoragePtr TableFunctionRemote::execute(ASTPtr ast_function, Context & context) const
StoragePtr TableFunctionRemote::execute(ASTPtr ast_function, const Context & context) const
{
ASTs & args_func = typeid_cast<ASTFunction &>(*ast_function).children;
......
......@@ -6,8 +6,7 @@
namespace DB
{
/*
* remote ('address', db, table) - creates a temporary StorageDistributed.
/* remote ('address', db, table) - creates a temporary StorageDistributed.
* To get the table structure, a DESC TABLE request is made to the remote server.
* For example
* SELECT count() FROM remote('example01-01-1', merge, hits) - go to `example01-01-1`, in the merge database, the hits table.
......@@ -17,7 +16,7 @@ class TableFunctionRemote : public ITableFunction
{
public:
std::string getName() const override { return "remote"; }
StoragePtr execute(ASTPtr ast_function, Context & context) const override;
StoragePtr execute(ASTPtr ast_function, const Context & context) const override;
};
}
......@@ -20,7 +20,7 @@ namespace ErrorCodes
extern const int BAD_ARGUMENTS;
}
StoragePtr TableFunctionShardByHash::execute(ASTPtr ast_function, Context & context) const
StoragePtr TableFunctionShardByHash::execute(ASTPtr ast_function, const Context & context) const
{
ASTs & args_func = typeid_cast<ASTFunction &>(*ast_function).children;
......
......@@ -15,7 +15,7 @@ class TableFunctionShardByHash : public ITableFunction
{
public:
std::string getName() const override { return "shardByHash"; }
StoragePtr execute(ASTPtr ast_function, Context & context) const override;
StoragePtr execute(ASTPtr ast_function, const Context & context) const override;
};
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册