fix and update test

This commit is contained in:
feng lv 2021-06-25 15:01:57 +00:00
parent 07a47b4bd3
commit 61550f91f2
7 changed files with 70 additions and 42 deletions

View File

@ -283,4 +283,3 @@ inline void trim(std::string_view & str, char c = ' ')
trimLeft(str, c);
trimRight(str, c);
}
}

View File

@ -1,25 +1,23 @@
#include <filesystem>
#include <Access/ContextAccess.h>
#include <Core/BackgroundSchedulePool.h>
#include <Interpreters/DatabaseCatalog.h>
#include <Interpreters/Context.h>
#include <Interpreters/loadMetadata.h>
#include <Storages/IStorage.h>
#include <Databases/IDatabase.h>
#include <Databases/DatabaseMemory.h>
#include <Databases/DatabaseOnDisk.h>
#include <Databases/IDatabase.h>
#include <IO/ReadHelpers.h>
#include <Interpreters/Context.h>
#include <Interpreters/DatabaseCatalog.h>
#include <Interpreters/loadMetadata.h>
#include <Parsers/formatAST.h>
#include <Storages/IStorage.h>
#include <Storages/LiveView/TemporaryLiveViewCleaner.h>
#include <Storages/StorageMemory.h>
#include <Poco/DirectoryIterator.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <Common/CurrentMetrics.h>
#include <Common/OptimizedRegularExpression.h>
#include <Common/filesystemHelpers.h>
#include <Common/quoteString.h>
#include <Storages/StorageMemory.h>
#include <Storages/LiveView/TemporaryLiveViewCleaner.h>
#include <Core/BackgroundSchedulePool.h>
#include <Parsers/formatAST.h>
#include <IO/ReadHelpers.h>
#include <Poco/DirectoryIterator.h>
#include <Common/renameat2.h>
#include <Common/CurrentMetrics.h>
#include <common/logger_useful.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <filesystem>
#include <Common/filesystemHelpers.h>
#if !defined(ARCADIA_BUILD)
# include "config_core.h"

View File

@ -1,6 +1,5 @@
#pragma once
#include <Core/Names.h>
#include <Core/UUID.h>
#include <Interpreters/Context_fwd.h>
#include <Interpreters/StorageID.h>

View File

@ -102,12 +102,12 @@ ASTPtr evaluateConstantExpressionForDatabaseName(const ASTPtr & node, ContextPtr
std::tuple<bool, String> evaluateDatabaseNameForMergeEngine(const ASTPtr & node, ContextPtr context)
{
if (const auto * func = node->as<ASTFunction>(); func->name == "REGEXP")
if (const auto * func = node->as<ASTFunction>(); func && func->name == "REGEXP")
{
if (func->children.size() != 1)
if (func->arguments->children.size() != 1)
throw Exception("Arguments for REGEXP in Merge ENGINE should be 1", ErrorCodes::BAD_ARGUMENTS);
auto * literal = func->children[0]->as<ASTLiteral>();
auto * literal = func->arguments->children[0]->as<ASTLiteral>();
if (!literal || literal->value.safeGet<String>().empty())
throw Exception("Argument for REGEXP in Merge ENGINE should be a non empty String Literal", ErrorCodes::BAD_ARGUMENTS);

View File

@ -670,14 +670,13 @@ void registerStorageMerge(StorageFactory & factory)
" - name of source database and regexp for table names.",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
engine_args[0] = evaluateConstantExpressionForDatabaseName(engine_args[0], args.getLocalContext());
engine_args[1] = evaluateConstantExpressionAsLiteral(engine_args[1], args.getLocalContext());
auto [is_regexp, source_database_name_or_regexp] = evaluateDatabaseNameForMergeEngine(engine_args[0], args.getLocalContext());
String source_database_regexp = engine_args[0]->as<ASTLiteral &>().value.safeGet<String>();
engine_args[1] = evaluateConstantExpressionAsLiteral(engine_args[1], args.getLocalContext());
String table_name_regexp = engine_args[1]->as<ASTLiteral &>().value.safeGet<String>();
return StorageMerge::create(
args.table_id, args.columns, args.comment, source_database_regexp, table_name_regexp, args.getContext());
args.table_id, args.columns, args.comment, source_database_name_or_regexp, is_regexp, table_name_regexp, args.getContext());
});
}

View File

@ -1,4 +1,4 @@
CREATE TABLE t_merge as 01902_db.t ENGINE=Merge(^01902_db.*, ^t.*)
CREATE TABLE t_merge as 01902_db.t ENGINE=Merge(REGEXP(^01902_db), ^t)
SELECT _database, _table, n FROM 01902_db.t_merge ORDER BY _database, _table, n
01902_db t 0
01902_db t 1
@ -40,7 +40,7 @@ SELECT _database, _table, n FROM 01902_db.t_merge ORDER BY _database, _table, n
01902_db3 t3 7
01902_db3 t3 8
01902_db3 t3 9
SELECT _database, _table, n FROM merge(^db, ^t) ORDER BY _database, _table, n
SELECT _database, _table, n FROM merge(REGEXP(^01902_db), ^t) ORDER BY _database, _table, n
01902_db t 0
01902_db t 1
01902_db t 2
@ -143,7 +143,30 @@ SELECT _database, _table, n FROM 01902_db.t_merge WHERE _table = t1 ORDER BY _da
01902_db1 t1 7
01902_db1 t1 8
01902_db1 t1 9
CREATE TABLE t_merge_1 as 01902_db.t ENGINE=Merge(currentDatabase(), ^t.*)
CREATE TABLE t_merge1 as 01902_db.t ENGINE=Merge(01902_db, ^t$)
SELECT _database, _table, n FROM 01902_db.t_merge1 ORDER BY _database, _table, n
01902_db t 0
01902_db t 1
01902_db t 2
01902_db t 3
01902_db t 4
01902_db t 5
01902_db t 6
01902_db t 7
01902_db t 8
01902_db t 9
SELECT _database, _table, n FROM merge(01902_db, ^t$) ORDER BY _database, _table, n
01902_db t 0
01902_db t 1
01902_db t 2
01902_db t 3
01902_db t 4
01902_db t 5
01902_db t 6
01902_db t 7
01902_db t 8
01902_db t 9
CREATE TABLE t_merge_1 as 01902_db.t ENGINE=Merge(currentDatabase(), ^t)
SELECT _database, _table, n FROM 01902_db.t_merge_1 ORDER BY _database, _table, n
01902_db1 t1 0
01902_db1 t1 1
@ -155,7 +178,7 @@ SELECT _database, _table, n FROM 01902_db.t_merge_1 ORDER BY _database, _table,
01902_db1 t1 7
01902_db1 t1 8
01902_db1 t1 9
SELECT _database, _table, n FROM merge(currentDatabase(), ^t.*) ORDER BY _database, _table, n
SELECT _database, _table, n FROM merge(currentDatabase(), ^t) ORDER BY _database, _table, n
01902_db1 t1 0
01902_db1 t1 1
01902_db1 t1 2

View File

@ -18,14 +18,14 @@ INSERT INTO 01902_db1.t1 SELECT * FROM numbers(10);
INSERT INTO 01902_db2.t2 SELECT * FROM numbers(10);
INSERT INTO 01902_db3.t3 SELECT * FROM numbers(10);
SELECT 'CREATE TABLE t_merge as 01902_db.t ENGINE=Merge(^01902_db.*, ^t.*)';
CREATE TABLE 01902_db.t_merge as 01902_db.t ENGINE=Merge('^01902_db.*', '^t.*');
SELECT 'CREATE TABLE t_merge as 01902_db.t ENGINE=Merge(REGEXP(^01902_db), ^t)';
CREATE TABLE 01902_db.t_merge as 01902_db.t ENGINE=Merge(REGEXP('^01902_db'), '^t');
SELECT 'SELECT _database, _table, n FROM 01902_db.t_merge ORDER BY _database, _table, n';
SELECT _database, _table, n FROM 01902_db.t_merge ORDER BY _database, _table, n;
SELECT 'SELECT _database, _table, n FROM merge(^db, ^t) ORDER BY _database, _table, n';
SELECT _database, _table, n FROM merge('^01902_db.*', '^t.*') ORDER BY _database, _table, n;
SELECT 'SELECT _database, _table, n FROM merge(REGEXP(^01902_db), ^t) ORDER BY _database, _table, n';
SELECT _database, _table, n FROM merge(REGEXP('^01902_db'), '^t') ORDER BY _database, _table, n;
SELECT 'SELECT _database, _table, n FROM 01902_db.t_merge WHERE _database = 01902_db1 ORDER BY _database, _table, n';
SELECT _database, _table, n FROM 01902_db.t_merge WHERE _database = '01902_db1' ORDER BY _database, _table, n;
@ -33,18 +33,28 @@ SELECT _database, _table, n FROM 01902_db.t_merge WHERE _database = '01902_db1'
SELECT 'SELECT _database, _table, n FROM 01902_db.t_merge WHERE _table = t1 ORDER BY _database, _table, n';
SELECT _database, _table, n FROM 01902_db.t_merge WHERE _table = 't1' ORDER BY _database, _table, n;
-- not regexp
SELECT 'CREATE TABLE t_merge1 as 01902_db.t ENGINE=Merge(01902_db, ^t$)';
CREATE TABLE 01902_db.t_merge1 as 01902_db.t ENGINE=Merge('01902_db', '^t$');
SELECT 'SELECT _database, _table, n FROM 01902_db.t_merge1 ORDER BY _database, _table, n';
SELECT _database, _table, n FROM 01902_db.t_merge1 ORDER BY _database, _table, n;
SELECT 'SELECT _database, _table, n FROM merge(01902_db, ^t$) ORDER BY _database, _table, n';
SELECT _database, _table, n FROM merge('01902_db', '^t$') ORDER BY _database, _table, n;
USE 01902_db1;
SELECT 'CREATE TABLE t_merge_1 as 01902_db.t ENGINE=Merge(currentDatabase(), ^t.*)';
CREATE TABLE 01902_db.t_merge_1 as 01902_db.t ENGINE=Merge(currentDatabase(), '^t.*');
SELECT 'CREATE TABLE t_merge_1 as 01902_db.t ENGINE=Merge(currentDatabase(), ^t)';
CREATE TABLE 01902_db.t_merge_1 as 01902_db.t ENGINE=Merge(currentDatabase(), '^t');
SELECT 'SELECT _database, _table, n FROM 01902_db.t_merge_1 ORDER BY _database, _table, n';
SELECT _database, _table, n FROM 01902_db.t_merge_1 ORDER BY _database, _table, n;
SELECT 'SELECT _database, _table, n FROM merge(currentDatabase(), ^t.*) ORDER BY _database, _table, n';
SELECT _database, _table, n FROM merge(currentDatabase(), '^t.*') ORDER BY _database, _table, n;
SELECT 'SELECT _database, _table, n FROM merge(currentDatabase(), ^t) ORDER BY _database, _table, n';
SELECT _database, _table, n FROM merge(currentDatabase(), '^t') ORDER BY _database, _table, n;
DROP DATABASE 01902_db;
DROP DATABASE 01902_db1;
DROP DATABASE 01902_db2;
DROP DATABASE 01902_db3;
-- DROP DATABASE 01902_db;
-- DROP DATABASE 01902_db1;
-- DROP DATABASE 01902_db2;
-- DROP DATABASE 01902_db3;