Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ All notable changes to this project will be documented in this file. It uses the
and PostgreSQL multidimensional arrays inserted into ClickHouse
`Array(Array(...))` columns preserve their nesting. Thanks to Philip Dubé
for the PR ([#233]).
* Added pushdown for [re2 extension] functions introduced in pg_re2 0.3:
`re2extractallgroupshorizontal`, `re2extractallgroupsvertical`,
`re2regexpquotemeta`, and `re2splitbyregexp`. Thanks to Philip Dubé for
the PR ([#232]).

[v0.3.1]: https://github.com/ClickHouse/pg_clickhouse/compare/v0.3.0...v0.3.1
[#232]: https://github.com/ClickHouse/pg_clickhouse/pull/232
"ClickHouse/pg_clickhouse#232 pushdown for new functions in pg_re2 0.3"
[#233]: https://github.com/ClickHouse/pg_clickhouse/pull/233
"ClickHouse/pg_clickhouse#233 Support multidimensional arrays"

Expand Down
4 changes: 4 additions & 0 deletions src/custom_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,17 @@ static char *re2_func_map[][2] = {
{"countmatches", "countMatches"},
{"countmatchescaseinsensitive", "countMatchesCaseInsensitive"},
{"extractall", "extractAll"},
{"extractallgroupshorizontal", "extractAllGroupsHorizontal"},
{"extractallgroupsvertical", "extractAllGroupsVertical"},
{"extractgroups", "extractGroups"},
{"multimatchallindices", "multiMatchAllIndices"},
{"multimatchany", "multiMatchAny"},
{"multimatchanyindex", "multiMatchAnyIndex"},
{"regexpextract", "regexpExtract"},
{"regexpquotemeta", "regexpQuoteMeta"},
{"replaceregexpall", "replaceRegexpAll"},
{"replaceregexpone", "replaceRegexpOne"},
{"splitbyregexp", "splitByRegexp"},
{NULL, NULL},
};

Expand Down
81 changes: 81 additions & 0 deletions test/expected/re2_functions.out
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,87 @@ SELECT * FROM t1 WHERE re2multimatchallindices(val, VARIADIC ARRAY['POSIX','PCRE
1 | POSIX uses BRE and ERE
(1 row)

EXPLAIN (VERBOSE, COSTS OFF)
SELECT id FROM t1 WHERE re2regexpquotemeta(val || '.') = val || '\.';
QUERY PLAN
---------------------------------------------------------------------------------------------------
Foreign Scan on re2_test.t1
Output: id
Remote SQL: SELECT id FROM re2_test.t1 WHERE ((regexpQuoteMeta((val || '.')) = (val || '\\.')))
(3 rows)

SELECT id FROM t1 WHERE re2regexpquotemeta(val || '.') = val || '\.';
id
----
1
2
3
(3 rows)

EXPLAIN (VERBOSE, COSTS OFF)
SELECT id FROM t1 WHERE re2splitbyregexp(' ', val) = ARRAY['re2','uses','finite','automata'];
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Foreign Scan on re2_test.t1
Output: id
Remote SQL: SELECT id FROM re2_test.t1 WHERE ((splitByRegexp(' ', val, 0) = ['re2','uses','finite','automata']))
(3 rows)

SELECT id FROM t1 WHERE re2splitbyregexp(' ', val) = ARRAY['re2','uses','finite','automata'];
id
----
2
(1 row)

EXPLAIN (VERBOSE, COSTS OFF)
SELECT id FROM t1 WHERE re2splitbyregexp(' ', val, 2) = ARRAY['re2','uses'];
QUERY PLAN
------------------------------------------------------------------------------------------------
Foreign Scan on re2_test.t1
Output: id
Remote SQL: SELECT id FROM re2_test.t1 WHERE ((splitByRegexp(' ', val, 2) = ['re2','uses']))
(3 rows)

SELECT id FROM t1 WHERE re2splitbyregexp(' ', val, 2) = ARRAY['re2','uses'];
id
----
2
(1 row)

EXPLAIN (VERBOSE, COSTS OFF)
SELECT id FROM t1 WHERE array_length(re2extractallgroupsvertical(val, '(\w+) (\w+)'), 1) > 0;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------
Foreign Scan on re2_test.t1
Output: id
Remote SQL: SELECT id FROM re2_test.t1 WHERE ((length(extractAllGroupsVertical(val, '(\\w+) (\\w+)')) > 0))
(3 rows)

SELECT id FROM t1 WHERE array_length(re2extractallgroupsvertical(val, '(\w+) (\w+)'), 1) > 0;
id
----
1
2
3
(3 rows)

EXPLAIN (VERBOSE, COSTS OFF)
SELECT id FROM t1 WHERE array_length(re2extractallgroupshorizontal(val, '(\w+) (\w+)'), 1) = 2;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------
Foreign Scan on re2_test.t1
Output: id
Remote SQL: SELECT id FROM re2_test.t1 WHERE ((length(extractAllGroupsHorizontal(val, '(\\w+) (\\w+)')) = 2))
(3 rows)

SELECT id FROM t1 WHERE array_length(re2extractallgroupshorizontal(val, '(\w+) (\w+)'), 1) = 2;
id
----
1
2
3
(3 rows)

DROP EXTENSION re2;
DROP USER MAPPING FOR CURRENT_USER SERVER re2_svr;
SELECT clickhouse_raw_query('DROP DATABASE re2_test');
Expand Down
20 changes: 20 additions & 0 deletions test/sql/re2_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ EXPLAIN (VERBOSE, COSTS OFF)
SELECT * FROM t1 WHERE re2multimatchallindices(val, VARIADIC ARRAY['POSIX','PCRE']) = ARRAY[1];
SELECT * FROM t1 WHERE re2multimatchallindices(val, VARIADIC ARRAY['POSIX','PCRE']) = ARRAY[1];

EXPLAIN (VERBOSE, COSTS OFF)
SELECT id FROM t1 WHERE re2regexpquotemeta(val || '.') = val || '\.';
SELECT id FROM t1 WHERE re2regexpquotemeta(val || '.') = val || '\.';

EXPLAIN (VERBOSE, COSTS OFF)
SELECT id FROM t1 WHERE re2splitbyregexp(' ', val) = ARRAY['re2','uses','finite','automata'];
SELECT id FROM t1 WHERE re2splitbyregexp(' ', val) = ARRAY['re2','uses','finite','automata'];

EXPLAIN (VERBOSE, COSTS OFF)
SELECT id FROM t1 WHERE re2splitbyregexp(' ', val, 2) = ARRAY['re2','uses'];
SELECT id FROM t1 WHERE re2splitbyregexp(' ', val, 2) = ARRAY['re2','uses'];

EXPLAIN (VERBOSE, COSTS OFF)
SELECT id FROM t1 WHERE array_length(re2extractallgroupsvertical(val, '(\w+) (\w+)'), 1) > 0;
SELECT id FROM t1 WHERE array_length(re2extractallgroupsvertical(val, '(\w+) (\w+)'), 1) > 0;

EXPLAIN (VERBOSE, COSTS OFF)
SELECT id FROM t1 WHERE array_length(re2extractallgroupshorizontal(val, '(\w+) (\w+)'), 1) = 2;
SELECT id FROM t1 WHERE array_length(re2extractallgroupshorizontal(val, '(\w+) (\w+)'), 1) = 2;

DROP EXTENSION re2;
DROP USER MAPPING FOR CURRENT_USER SERVER re2_svr;
SELECT clickhouse_raw_query('DROP DATABASE re2_test');
Expand Down
Loading