Merge pull request #23036 from Enmk/fix_extractAllGroupsHorizontal_max_matches

Fixed erroneus failure of extractAllGroupsHorizontal on large columns
This commit is contained in:
alexey-milovidov 2021-04-14 15:57:19 +03:00 committed by GitHub
commit 496c2e45d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -172,11 +172,12 @@ public:
for (size_t group = 1; group <= groups_count; ++group) for (size_t group = 1; group <= groups_count; ++group)
all_matches.push_back(matched_groups[group]); all_matches.push_back(matched_groups[group]);
/// Additional limit to fail fast on supposedly incorrect usage. /// Additional limit to fail fast on supposedly incorrect usage, arbitrary value.
static constexpr size_t MAX_GROUPS_PER_ROW = 1000000; static constexpr size_t MAX_MATCHES_PER_ROW = 1000;
if (matches_per_row > MAX_MATCHES_PER_ROW)
if (all_matches.size() > MAX_GROUPS_PER_ROW) throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE,
throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Too large array size in the result of function {}", getName()); "Too many matches per row (> {}) in the result of function {}",
MAX_MATCHES_PER_ROW, getName());
pos = matched_groups[0].data() + std::max<size_t>(1, matched_groups[0].size()); pos = matched_groups[0].data() + std::max<size_t>(1, matched_groups[0].size());

View File

@ -1 +1,2 @@
SELECT repeat('abcdefghijklmnopqrstuvwxyz', number * 100) AS haystack, extractAllGroupsHorizontal(haystack, '(\\w)') AS matches FROM numbers(1023); -- { serverError 128 } SELECT repeat('abcdefghijklmnopqrstuvwxyz', number * 100) AS haystack, extractAllGroupsHorizontal(haystack, '(\\w)') AS matches FROM numbers(1023); -- { serverError 128 }
SELECT count(extractAllGroupsHorizontal(materialize('a'), '(a)')) FROM numbers(1000000) FORMAT Null; -- shouldn't fail