fix and add test for storage file version

This commit is contained in:
stavrolia 2019-08-09 20:06:29 +03:00
parent 32fad1e961
commit 2f2bf953eb
4 changed files with 48 additions and 3 deletions

View File

@ -5,7 +5,10 @@
namespace DB
{
/* Because of difference between grep-wildcard-syntax and perl-regexp one we need some transformation of string to use RE2 library for matching.
* It couldn't be one pass because of various configurations of braces in filenames (Linux allow almost any symbols in paths).
* So there are some iterations of escaping and replacements to make correct perl-regexp.
*/
std::string makeRegexpPatternFromGlobs(const std::string & initial_str)
{
std::string first_prepare;

View File

@ -63,7 +63,7 @@ std::vector<std::string> LSWithRegexpMatching(const std::string & path_for_ls, c
std::vector<std::string> result;
fs::directory_iterator end;
for (fs::directory_iterator it(path_for_ls); it != end; ++it)
for (fs::directory_iterator it(path_for_ls + for_match.substr(1, end_of_path_without_globs)); it != end; ++it)
{
std::string full_path = it->path().string();
size_t last_slash = full_path.rfind('/');
@ -139,7 +139,7 @@ StorageFile::StorageFile(
if (first_glob != std::string::npos)
{
path_with_globs = true;
matched_paths = LSWithRegexpMatching(db_dir_path, path);
matched_paths = LSWithRegexpMatching("/", path);
for (const auto & cur_path : matched_paths)
checkCreationIsAllowed(context_global, db_dir_path, cur_path, table_fd);
}

View File

@ -0,0 +1,42 @@
import pytest
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance('node')
@pytest.fixture(scope="module")
def start_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_globs(start_cluster):
some_data = "\t555.222\nData\t777.333"
path_to_userfiles = "/var/lib/clickhouse/user_files/"
dirs = ["dir1/", "dir2/"]
for dir in dirs:
node.exec_in_container(['bash', '-c', 'mkdir {}{}'.format(path_to_userfiles, dir)], privileged=True, user='root')
# all directories appeared in files must be listed in dirs
files = ["dir1/file1", "dir1/file2",
"dir2/file1", "dir2/file2", "dir2/file11",
"file1"]
for filename in files:
node.exec_in_container(['bash', '-c', 'echo "{}{}" > {}{}'.format(filename, some_data, path_to_userfiles, filename)], privileged=True, user='root')
test_requests = [("dir1/file*", "4"),
("dir1/file?", "4"),
("dir1/file{0..9}", "4"),
("dir2/file*", "6"),
("dir2/file?", "4"),
("*", "2")]
for pattern, value in test_requests:
assert node.query('''
select count(*) from file('{}', 'TSV', 'text String, number Float64')
'''.format(pattern)) == '{}\n'.format(value)