Пример #1
0
StoragePtr TableFunctionMerge::execute(const ASTPtr & ast_function, const Context & context) const
{
    ASTs & args_func = typeid_cast<ASTFunction &>(*ast_function).children;

    if (args_func.size() != 1)
        throw Exception("Table function 'merge' requires exactly 2 arguments"
            " - name of source database and regexp for table names.",
            ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);

    ASTs & args = typeid_cast<ASTExpressionList &>(*args_func.at(0)).children;

    if (args.size() != 2)
        throw Exception("Table function 'merge' requires exactly 2 arguments"
            " - name of source database and regexp for table names.",
            ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);

    args[0] = evaluateConstantExpressionOrIdentidierAsLiteral(args[0], context);
    args[1] = evaluateConstantExpressionAsLiteral(args[1], context);

    String source_database = static_cast<const ASTLiteral &>(*args[0]).value.safeGet<String>();
    String table_name_regexp = static_cast<const ASTLiteral &>(*args[1]).value.safeGet<String>();

    auto res = StorageMerge::create(
        getName(),
        std::make_shared<NamesAndTypesList>(chooseColumns(source_database, table_name_regexp, context)),
        source_database,
        table_name_regexp,
        context);
    res->startup();
    return res;
}
Пример #2
0
StoragePtr TableFunctionMerge::execute(ASTPtr ast_function, Context & context) const
{
	ASTs & args_func = typeid_cast<ASTFunction &>(*ast_function).children;

	if (args_func.size() != 1)
		throw Exception("Storage Merge requires exactly 2 parameters"
			" - name of source database and regexp for table names.",
			ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);

	ASTs & args = typeid_cast<ASTExpressionList &>(*args_func.at(0)).children;

	if (args.size() != 2)
		throw Exception("Storage Merge requires exactly 2 parameters"
			" - name of source database and regexp for table names.",
			ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);

	String source_database 		= reinterpretAsIdentifier(args[0], context).name;
	String table_name_regexp	= safeGet<const String &>(typeid_cast<ASTLiteral &>(*args[1]).value);

	/// В InterpreterSelectQuery будет создан ExpressionAnalzyer, который при обработке запроса наткнется на этот Identifier.
	/// Нам необходимо его пометить как имя базы данных, поскольку по умолчанию стоит значение column
	typeid_cast<ASTIdentifier &>(*args[0]).kind = ASTIdentifier::Database;

	return StorageMerge::create(
		getName(),
		std::make_shared<NamesAndTypesList>(chooseColumns(source_database, table_name_regexp, context)),
		source_database,
		table_name_regexp,
		context);
}