Allow LIKE over binary data

This commit is contained in:
Alexey Milovidov 2023-09-23 04:14:03 +02:00
parent ba6f0431a5
commit 1326bffe60
3 changed files with 58 additions and 0 deletions

View File

@ -496,6 +496,14 @@ OptimizedRegularExpression::OptimizedRegularExpression(const std::string & regex
regexp_options.set_dot_nl(true);
re2 = std::make_unique<re2::RE2>(regexp_, regexp_options);
/// Fallback to latin1 to allow matching binary data.
if (!re2->ok() && re2->error_code() == re2::RE2::ErrorCode::ErrorBadUTF8)
{
regexp_options.set_encoding(re2::RE2::Options::EncodingLatin1);
re2 = std::make_unique<re2::RE2>(regexp_, regexp_options);
}
if (!re2->ok())
{
throw DB::Exception(DB::ErrorCodes::CANNOT_COMPILE_REGEXP,

View File

@ -0,0 +1,24 @@
1
1
1
1
1
0
0
1
1
1
1
1
1
0
0
1
1
1
1
1
1
0
0
1

View File

@ -0,0 +1,26 @@
SELECT 'aяb' LIKE 'a_b';
SELECT 'a\0b' LIKE 'a_b';
SELECT 'a\0b' LIKE 'a\0b';
SELECT 'a\0b' LIKE 'a%\0b';
SELECT 'a\xFFb' LIKE 'a%\xFFb';
SELECT 'a\xFFb' LIKE 'a%\xFF\xFEb';
SELECT 'a\xFFb' LIKE '%a\xFF\xFEb';
SELECT 'a\xFF\xFEb' LIKE '%a\xFF\xFEb';
SELECT materialize('aяb') LIKE 'a_b';
SELECT materialize('a\0b') LIKE 'a_b';
SELECT materialize('a\0b') LIKE 'a\0b';
SELECT materialize('a\0b') LIKE 'a%\0b';
SELECT materialize('a\xFFb') LIKE 'a%\xFFb';
SELECT materialize('a\xFFb') LIKE 'a%\xFF\xFEb';
SELECT materialize('a\xFFb') LIKE '%a\xFF\xFEb';
SELECT materialize('a\xFF\xFEb') LIKE '%a\xFF\xFEb';
SELECT materialize('aяb') LIKE materialize('a_b');
SELECT materialize('a\0b') LIKE materialize('a_b');
SELECT materialize('a\0b') LIKE materialize('a\0b');
SELECT materialize('a\0b') LIKE materialize('a%\0b');
SELECT materialize('a\xFFb') LIKE materialize('a%\xFFb');
SELECT materialize('a\xFFb') LIKE materialize('a%\xFF\xFEb');
SELECT materialize('a\xFFb') LIKE materialize('%a\xFF\xFEb');
SELECT materialize('a\xFF\xFEb') LIKE materialize('%a\xFF\xFEb');