Skip to content

Commit 1abba3a

Browse files
committed
pushdown for new functions in pg_re2 0.3
1 parent a84662a commit 1abba3a

3 files changed

Lines changed: 102 additions & 0 deletions

File tree

src/custom_types.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,17 @@ static char *re2_func_map[][2] = {
310310
{"countmatches", "countMatches"},
311311
{"countmatchescaseinsensitive", "countMatchesCaseInsensitive"},
312312
{"extractall", "extractAll"},
313+
{"extractallgroupshorizontal", "extractAllGroupsHorizontal"},
314+
{"extractallgroupsvertical", "extractAllGroupsVertical"},
313315
{"extractgroups", "extractGroups"},
314316
{"multimatchallindices", "multiMatchAllIndices"},
315317
{"multimatchany", "multiMatchAny"},
316318
{"multimatchanyindex", "multiMatchAnyIndex"},
317319
{"regexpextract", "regexpExtract"},
320+
{"regexpquotemeta", "regexpQuoteMeta"},
318321
{"replaceregexpall", "replaceRegexpAll"},
319322
{"replaceregexpone", "replaceRegexpOne"},
323+
{"splitbyregexp", "splitByRegexp"},
320324
{NULL, NULL},
321325
};
322326

test/expected/re2_functions.out

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,84 @@ SELECT * FROM t1 WHERE re2multimatchallindices(val, VARIADIC ARRAY['POSIX','PCRE
275275
1 | POSIX uses BRE and ERE
276276
(1 row)
277277

278+
EXPLAIN (VERBOSE, COSTS OFF)
279+
SELECT id FROM t1 WHERE re2regexpquotemeta(val) <> val;
280+
QUERY PLAN
281+
--------------------------------------------------------------------------------
282+
Foreign Scan on re2_test.t1
283+
Output: id
284+
Remote SQL: SELECT id FROM re2_test.t1 WHERE ((regexpQuoteMeta(val) <> val))
285+
(3 rows)
286+
287+
SELECT id FROM t1 WHERE re2regexpquotemeta(val) <> val;
288+
id
289+
----
290+
(0 rows)
291+
292+
EXPLAIN (VERBOSE, COSTS OFF)
293+
SELECT id FROM t1 WHERE re2splitbyregexp(val, ' ') = ARRAY['re2','uses','finite','automata'];
294+
QUERY PLAN
295+
--------------------------------------------------------------------------------------------------------------------
296+
Foreign Scan on re2_test.t1
297+
Output: id
298+
Remote SQL: SELECT id FROM re2_test.t1 WHERE ((splitByRegexp(' ', val, 0) = ['re2','uses','finite','automata']))
299+
(3 rows)
300+
301+
SELECT id FROM t1 WHERE re2splitbyregexp(val, ' ') = ARRAY['re2','uses','finite','automata'];
302+
id
303+
----
304+
2
305+
(1 row)
306+
307+
EXPLAIN (VERBOSE, COSTS OFF)
308+
SELECT id FROM t1 WHERE re2splitbyregexp(val, ' ', 2) = ARRAY['re2','uses'];
309+
QUERY PLAN
310+
------------------------------------------------------------------------------------------------
311+
Foreign Scan on re2_test.t1
312+
Output: id
313+
Remote SQL: SELECT id FROM re2_test.t1 WHERE ((splitByRegexp(' ', val, 2) = ['re2','uses']))
314+
(3 rows)
315+
316+
SELECT id FROM t1 WHERE re2splitbyregexp(val, ' ', 2) = ARRAY['re2','uses'];
317+
id
318+
----
319+
2
320+
(1 row)
321+
322+
EXPLAIN (VERBOSE, COSTS OFF)
323+
SELECT id FROM t1 WHERE array_length(re2extractallgroupsvertical(val, '(\w+) (\w+)'), 1) > 0;
324+
QUERY PLAN
325+
---------------------------------------------------------------------------------------------------------------
326+
Foreign Scan on re2_test.t1
327+
Output: id
328+
Remote SQL: SELECT id FROM re2_test.t1 WHERE ((length(extractAllGroupsVertical(val, '(\\w+) (\\w+)')) > 0))
329+
(3 rows)
330+
331+
SELECT id FROM t1 WHERE array_length(re2extractallgroupsvertical(val, '(\w+) (\w+)'), 1) > 0;
332+
id
333+
----
334+
1
335+
2
336+
3
337+
(3 rows)
338+
339+
EXPLAIN (VERBOSE, COSTS OFF)
340+
SELECT id FROM t1 WHERE array_length(re2extractallgroupshorizontal(val, '(\w+) (\w+)'), 1) = 2;
341+
QUERY PLAN
342+
-----------------------------------------------------------------------------------------------------------------
343+
Foreign Scan on re2_test.t1
344+
Output: id
345+
Remote SQL: SELECT id FROM re2_test.t1 WHERE ((length(extractAllGroupsHorizontal(val, '(\\w+) (\\w+)')) = 2))
346+
(3 rows)
347+
348+
SELECT id FROM t1 WHERE array_length(re2extractallgroupshorizontal(val, '(\w+) (\w+)'), 1) = 2;
349+
id
350+
----
351+
1
352+
2
353+
3
354+
(3 rows)
355+
278356
DROP EXTENSION re2;
279357
DROP USER MAPPING FOR CURRENT_USER SERVER re2_svr;
280358
SELECT clickhouse_raw_query('DROP DATABASE re2_test');

test/sql/re2_functions.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ EXPLAIN (VERBOSE, COSTS OFF)
8585
SELECT * FROM t1 WHERE re2multimatchallindices(val, VARIADIC ARRAY['POSIX','PCRE']) = ARRAY[1];
8686
SELECT * FROM t1 WHERE re2multimatchallindices(val, VARIADIC ARRAY['POSIX','PCRE']) = ARRAY[1];
8787

88+
EXPLAIN (VERBOSE, COSTS OFF)
89+
SELECT id FROM t1 WHERE re2regexpquotemeta(val) <> val;
90+
SELECT id FROM t1 WHERE re2regexpquotemeta(val) <> val;
91+
92+
EXPLAIN (VERBOSE, COSTS OFF)
93+
SELECT id FROM t1 WHERE re2splitbyregexp(' ', val) = ARRAY['re2','uses','finite','automata'];
94+
SELECT id FROM t1 WHERE re2splitbyregexp(' ', val) = ARRAY['re2','uses','finite','automata'];
95+
96+
EXPLAIN (VERBOSE, COSTS OFF)
97+
SELECT id FROM t1 WHERE re2splitbyregexp(' ', val, 2) = ARRAY['re2','uses'];
98+
SELECT id FROM t1 WHERE re2splitbyregexp(' ', val, 2) = ARRAY['re2','uses'];
99+
100+
EXPLAIN (VERBOSE, COSTS OFF)
101+
SELECT id FROM t1 WHERE array_length(re2extractallgroupsvertical(val, '(\w+) (\w+)'), 1) > 0;
102+
SELECT id FROM t1 WHERE array_length(re2extractallgroupsvertical(val, '(\w+) (\w+)'), 1) > 0;
103+
104+
EXPLAIN (VERBOSE, COSTS OFF)
105+
SELECT id FROM t1 WHERE array_length(re2extractallgroupshorizontal(val, '(\w+) (\w+)'), 1) = 2;
106+
SELECT id FROM t1 WHERE array_length(re2extractallgroupshorizontal(val, '(\w+) (\w+)'), 1) = 2;
107+
88108
DROP EXTENSION re2;
89109
DROP USER MAPPING FOR CURRENT_USER SERVER re2_svr;
90110
SELECT clickhouse_raw_query('DROP DATABASE re2_test');

0 commit comments

Comments
 (0)