-
Notifications
You must be signed in to change notification settings - Fork 10
Support pushdown for re2 extension #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,9 @@ | |
| "runtime": { | ||
| "requires": { | ||
| "PostgreSQL": "13.0.0" | ||
| }, | ||
| "recommends": { | ||
| "re2": "0.1.0" | ||
| } | ||
| } | ||
| }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| SELECT EXISTS(SELECT 1 FROM pg_available_extensions WHERE name = 're2') AS have_re2 \gset | ||
| \if :have_re2 | ||
| CREATE SERVER re2_svr FOREIGN DATA WRAPPER clickhouse_fdw OPTIONS(dbname 're2_test'); | ||
| CREATE USER MAPPING FOR CURRENT_USER SERVER re2_svr; | ||
| SELECT clickhouse_raw_query('DROP DATABASE IF EXISTS re2_test'); | ||
| clickhouse_raw_query | ||
| ---------------------- | ||
|
|
||
| (1 row) | ||
|
|
||
| SELECT clickhouse_raw_query('CREATE DATABASE re2_test'); | ||
| clickhouse_raw_query | ||
| ---------------------- | ||
|
|
||
| (1 row) | ||
|
|
||
| SELECT clickhouse_raw_query($$ | ||
| CREATE TABLE re2_test.t1 ( | ||
| id Int32, | ||
| val String | ||
| ) ENGINE = MergeTree ORDER BY id | ||
| $$); | ||
| clickhouse_raw_query | ||
| ---------------------- | ||
|
|
||
| (1 row) | ||
|
|
||
| SELECT clickhouse_raw_query($$ | ||
| INSERT INTO re2_test.t1 VALUES | ||
| (1, 'POSIX uses BRE and ERE'), | ||
| (2, 're2 uses finite automata'), | ||
| (3, 'PCRE supports backtracking') | ||
| $$); | ||
| clickhouse_raw_query | ||
| ---------------------- | ||
|
|
||
| (1 row) | ||
|
|
||
| CREATE SCHEMA re2_test; | ||
| IMPORT FOREIGN SCHEMA re2_test FROM SERVER re2_svr INTO re2_test; | ||
| SET search_path = re2_test, public; | ||
| CREATE EXTENSION re2; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2match(val, 're2'); | ||
| QUERY PLAN | ||
| ------------------------------------------------------------------------- | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE (match(val, 're2')) | ||
| (3 rows) | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2extract(val, '(re2)') = 're2'; | ||
| QUERY PLAN | ||
| --------------------------------------------------------------------------------------- | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE ((extract(val, '(re2)') = 're2')) | ||
| (3 rows) | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2extractall(val, '[A-Z]+') = ARRAY['POSIX','BRE','ERE']; | ||
| QUERY PLAN | ||
| ----------------------------------------------------------------------------------------------------------- | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE ((extractAll(val, '[A-Z]+') = ['POSIX','BRE','ERE'])) | ||
| (3 rows) | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2regexpextract(val, '(re2)', 1) = 're2'; | ||
| QUERY PLAN | ||
| ------------------------------------------------------------------------------------------------ | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE ((regexpExtract(val, '(re2)', 1) = 're2')) | ||
| (3 rows) | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2extractgroups(val, '(POSIX) uses (BRE)') = ARRAY['POSIX','BRE']; | ||
| QUERY PLAN | ||
| -------------------------------------------------------------------------------------------------------------------- | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE ((extractGroups(val, '(POSIX) uses (BRE)') = ['POSIX','BRE'])) | ||
| (3 rows) | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2replaceregexpone(val, 'POSIX', 're2') = 're2 uses BRE and ERE'; | ||
| QUERY PLAN | ||
| ------------------------------------------------------------------------------------------------------------------------ | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE ((replaceRegexpOne(val, 'POSIX', 're2') = 're2 uses BRE and ERE')) | ||
| (3 rows) | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2replaceregexpall(val, ' ', '-') = 're2-uses-finite-automata'; | ||
| QUERY PLAN | ||
| ---------------------------------------------------------------------------------------------------------------------- | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE ((replaceRegexpAll(val, ' ', '-') = 're2-uses-finite-automata')) | ||
| (3 rows) | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2countmatches(val, 'e') > 0; | ||
| QUERY PLAN | ||
| ------------------------------------------------------------------------------------ | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE ((countMatches(val, 'e') > 0)) | ||
| (3 rows) | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2countmatchescaseinsensitive(val, 'E') > 0; | ||
| QUERY PLAN | ||
| --------------------------------------------------------------------------------------------------- | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE ((countMatchesCaseInsensitive(val, 'E') > 0)) | ||
| (3 rows) | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2multimatchany(val, 'POSIX','PCRE'); | ||
| QUERY PLAN | ||
| -------------------------------------------------------------------------------------------- | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE (multiMatchAny(val, ['POSIX','PCRE'])) | ||
| (3 rows) | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2multimatchanyindex(val, 'POSIX','PCRE') > 0; | ||
| QUERY PLAN | ||
| ------------------------------------------------------------------------------------------------------- | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE ((multiMatchAnyIndex(val, ['POSIX','PCRE']) > 0)) | ||
| (3 rows) | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2multimatchallindices(val, 'POSIX','PCRE') = ARRAY[1]; | ||
| QUERY PLAN | ||
| ----------------------------------------------------------------------------------------------------------- | ||
| Foreign Scan on re2_test.t1 | ||
| Output: id, val | ||
| Remote SQL: SELECT id, val FROM re2_test.t1 WHERE ((multiMatchAllIndices(val, ['POSIX','PCRE']) = [1])) | ||
| (3 rows) | ||
|
|
||
| DROP EXTENSION re2; | ||
| DROP USER MAPPING FOR CURRENT_USER SERVER re2_svr; | ||
| SELECT clickhouse_raw_query('DROP DATABASE re2_test'); | ||
| clickhouse_raw_query | ||
| ---------------------- | ||
|
|
||
| (1 row) | ||
|
|
||
| DROP SERVER re2_svr CASCADE; | ||
| NOTICE: drop cascades to foreign table t1 | ||
| \else | ||
| \echo 'SKIP: re2 extension not available' | ||
| \endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| SELECT EXISTS(SELECT 1 FROM pg_available_extensions WHERE name = 're2') AS have_re2 \gset | ||
| \if :have_re2 | ||
| CREATE SERVER re2_svr FOREIGN DATA WRAPPER clickhouse_fdw OPTIONS(dbname 're2_test'); | ||
| CREATE USER MAPPING FOR CURRENT_USER SERVER re2_svr; | ||
| SELECT clickhouse_raw_query('DROP DATABASE IF EXISTS re2_test'); | ||
| SELECT clickhouse_raw_query('CREATE DATABASE re2_test'); | ||
| SELECT clickhouse_raw_query($$ | ||
| CREATE TABLE re2_test.t1 ( | ||
| id Int32, | ||
| val String | ||
| ) ENGINE = MergeTree ORDER BY id | ||
| $$); | ||
| SELECT clickhouse_raw_query($$ | ||
| INSERT INTO re2_test.t1 VALUES | ||
| (1, 'POSIX uses BRE and ERE'), | ||
| (2, 're2 uses finite automata'), | ||
| (3, 'PCRE supports backtracking') | ||
| $$); | ||
| CREATE SCHEMA re2_test; | ||
| IMPORT FOREIGN SCHEMA re2_test FROM SERVER re2_svr INTO re2_test; | ||
| SET search_path = re2_test, public; | ||
| CREATE EXTENSION re2; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2match(val, 're2'); | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2extract(val, '(re2)') = 're2'; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2extractall(val, '[A-Z]+') = ARRAY['POSIX','BRE','ERE']; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2regexpextract(val, '(re2)', 1) = 're2'; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2extractgroups(val, '(POSIX) uses (BRE)') = ARRAY['POSIX','BRE']; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2replaceregexpone(val, 'POSIX', 're2') = 're2 uses BRE and ERE'; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2replaceregexpall(val, ' ', '-') = 're2-uses-finite-automata'; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2countmatches(val, 'e') > 0; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2countmatchescaseinsensitive(val, 'E') > 0; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2multimatchany(val, 'POSIX','PCRE'); | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2multimatchanyindex(val, 'POSIX','PCRE') > 0; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2multimatchallindices(val, 'POSIX','PCRE') = ARRAY[1]; | ||
| DROP EXTENSION re2; | ||
| DROP USER MAPPING FOR CURRENT_USER SERVER re2_svr; | ||
| SELECT clickhouse_raw_query('DROP DATABASE re2_test'); | ||
| DROP SERVER re2_svr CASCADE; | ||
| \else | ||
| \echo 'SKIP: re2 extension not available' | ||
| SKIP: re2 extension not available | ||
| \endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| SELECT EXISTS(SELECT 1 FROM pg_available_extensions WHERE name = 're2') AS have_re2 \gset | ||
| \if :have_re2 | ||
|
|
||
| CREATE SERVER re2_svr FOREIGN DATA WRAPPER clickhouse_fdw OPTIONS(dbname 're2_test'); | ||
| CREATE USER MAPPING FOR CURRENT_USER SERVER re2_svr; | ||
|
|
||
| SELECT clickhouse_raw_query('DROP DATABASE IF EXISTS re2_test'); | ||
| SELECT clickhouse_raw_query('CREATE DATABASE re2_test'); | ||
| SELECT clickhouse_raw_query($$ | ||
| CREATE TABLE re2_test.t1 ( | ||
| id Int32, | ||
| val String | ||
| ) ENGINE = MergeTree ORDER BY id | ||
| $$); | ||
| SELECT clickhouse_raw_query($$ | ||
| INSERT INTO re2_test.t1 VALUES | ||
| (1, 'POSIX uses BRE and ERE'), | ||
| (2, 're2 uses finite automata'), | ||
| (3, 'PCRE supports backtracking') | ||
| $$); | ||
|
|
||
| CREATE SCHEMA re2_test; | ||
| IMPORT FOREIGN SCHEMA re2_test FROM SERVER re2_svr INTO re2_test; | ||
| SET search_path = re2_test, public; | ||
|
|
||
| CREATE EXTENSION re2; | ||
|
|
||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2match(val, 're2'); | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2extract(val, '(re2)') = 're2'; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2extractall(val, '[A-Z]+') = ARRAY['POSIX','BRE','ERE']; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2regexpextract(val, '(re2)', 1) = 're2'; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2extractgroups(val, '(POSIX) uses (BRE)') = ARRAY['POSIX','BRE']; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2replaceregexpone(val, 'POSIX', 're2') = 're2 uses BRE and ERE'; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2replaceregexpall(val, ' ', '-') = 're2-uses-finite-automata'; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2countmatches(val, 'e') > 0; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2countmatchescaseinsensitive(val, 'E') > 0; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2multimatchany(val, 'POSIX','PCRE'); | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2multimatchanyindex(val, 'POSIX','PCRE') > 0; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t1 WHERE re2multimatchallindices(val, 'POSIX','PCRE') = ARRAY[1]; | ||
|
|
||
| DROP EXTENSION re2; | ||
| DROP USER MAPPING FOR CURRENT_USER SERVER re2_svr; | ||
| SELECT clickhouse_raw_query('DROP DATABASE re2_test'); | ||
| DROP SERVER re2_svr CASCADE; | ||
|
|
||
| \else | ||
| \echo 'SKIP: re2 extension not available' | ||
| \endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.