Fix behaviour of globs in filepath with leading zeros

This commit is contained in:
Olga Khvostikova 2020-04-01 18:06:20 +03:00
parent 816eccde11
commit 834e458f26
2 changed files with 10 additions and 1 deletions

View File

@ -4,6 +4,7 @@
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
#include <cassert> #include <cassert>
#include <iomanip>
namespace DB namespace DB
@ -46,10 +47,17 @@ std::string makeRegexpPatternFromGlobs(const std::string & initial_str_with_glob
std::istringstream iss_range(buffer); std::istringstream iss_range(buffer);
iss_range >> range_begin >> point >> point >> range_end; iss_range >> range_begin >> point >> point >> range_end;
assert(iss_range.good()); assert(iss_range.good());
bool leading_zeros = buffer[0] == '0';
size_t num_len = std::to_string(range_end).size();
if (leading_zeros)
oss_for_replacing << std::setfill('0') << std::setw(num_len);
oss_for_replacing << range_begin; oss_for_replacing << range_begin;
for (size_t i = range_begin + 1; i <= range_end; ++i) for (size_t i = range_begin + 1; i <= range_end; ++i)
{ {
oss_for_replacing << '|' << i; oss_for_replacing << '|';
if (leading_zeros)
oss_for_replacing << std::setfill('0') << std::setw(num_len);
oss_for_replacing << i;
} }
} }
else else

View File

@ -64,6 +64,7 @@ def test_linear_structure(start_cluster):
("file?", "10"), ("file?", "10"),
("nothing*", "0"), ("nothing*", "0"),
("file{0..9}{0..9}{0..9}", "10"), ("file{0..9}{0..9}{0..9}", "10"),
("file{000..999}", "10"),
("file???", "10"), ("file???", "10"),
("file*", "20"), ("file*", "20"),
("a_{file,data}", "4"), ("a_{file,data}", "4"),