Skip to content

Commit

Permalink
Add regexp_not_like() for orafce and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
foreyes authored and my-ship-it committed Jul 23, 2024
1 parent 1d078e8 commit 7bda696
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gpcontrib/orafce/expected/gp_partition_by.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CREATE TABLE t3 (
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'str' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO t3 VALUES ('a'), ('b'), ('c');
ANALYZE t3;
SELECT * FROM t3 ORDER BY str;
str
-----
Expand Down Expand Up @@ -37,6 +38,7 @@ CREATE TABLE t4 (
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'str' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO t4 VALUES ('a'), ('b'), ('c');
ANALYZE t4;
SELECT * FROM t4 ORDER BY str;
str
-----
Expand Down
34 changes: 34 additions & 0 deletions gpcontrib/orafce/orafce--4.8--4.9.sql
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,37 @@ END;
$$
LANGUAGE plpgsql STRICT IMMUTABLE PARALLEL SAFE;

-- Add regexp_not_like based on regexp_like

-- REGEXP_NOT_LIKE( string text, pattern text) -> boolean
-- If one of the param is NULL returns NULL, declared STRICT
CREATE OR REPLACE FUNCTION oracle.regexp_not_like(text, text)
RETURNS boolean
AS $$
-- Oracle default behavior is newline-sensitive,
-- PostgreSQL not, so force 'p' modifier to affect
-- newline-sensitivity but not ^ and $ search.
SELECT CASE WHEN (count(*) > 0) THEN false ELSE true END FROM regexp_matches($1, $2, 'p');
$$
LANGUAGE 'sql' STRICT;

-- REGEXP_NOT_LIKE( string text, pattern text, flags text ) -> boolean
CREATE OR REPLACE FUNCTION oracle.regexp_not_like(text, text, text)
RETURNS boolean
AS $$
DECLARE
modifiers text;
BEGIN
-- Only modifier can be NULL
IF $1 IS NULL OR $2 IS NULL THEN
RETURN NULL;
END IF;
modifiers := oracle.translate_oracle_modifiers($3, false);
IF (regexp_matches($1, $2, modifiers))[1] IS NOT NULL THEN
RETURN false;
END IF;
RETURN true;
END;
$$
LANGUAGE plpgsql;

34 changes: 34 additions & 0 deletions gpcontrib/orafce/orafce--4.9.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4012,6 +4012,40 @@ RETURNS text
AS 'MODULE_PATHNAME','orafce_textregexreplace'
LANGUAGE 'c' IMMUTABLE PARALLEL SAFE;

-- Add regexp_not_like based on regexp_like

-- REGEXP_NOT_LIKE( string text, pattern text) -> boolean
-- If one of the param is NULL returns NULL, declared STRICT
CREATE OR REPLACE FUNCTION oracle.regexp_not_like(text, text)
RETURNS boolean
AS $$
-- Oracle default behavior is newline-sensitive,
-- PostgreSQL not, so force 'p' modifier to affect
-- newline-sensitivity but not ^ and $ search.
SELECT CASE WHEN (count(*) > 0) THEN false ELSE true END FROM regexp_matches($1, $2, 'p');
$$
LANGUAGE 'sql' STRICT;

-- REGEXP_NOT_LIKE( string text, pattern text, flags text ) -> boolean
CREATE OR REPLACE FUNCTION oracle.regexp_not_like(text, text, text)
RETURNS boolean
AS $$
DECLARE
modifiers text;
BEGIN
-- Only modifier can be NULL
IF $1 IS NULL OR $2 IS NULL THEN
RETURN NULL;
END IF;
modifiers := oracle.translate_oracle_modifiers($3, false);
IF (regexp_matches($1, $2, modifiers))[1] IS NOT NULL THEN
RETURN false;
END IF;
RETURN true;
END;
$$
LANGUAGE plpgsql;

----
-- Add LEAST/GREATEST declaration to return NULL on NULL input.
-- PostgreSQL only returns NULL when all the parameters are NULL.
Expand Down
2 changes: 2 additions & 0 deletions gpcontrib/orafce/sql/gp_partition_by.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CREATE TABLE t3 (
PARTITION t3_2 VALUES ('c')
);
INSERT INTO t3 VALUES ('a'), ('b'), ('c');
ANALYZE t3;
SELECT * FROM t3 ORDER BY str;
\d+ t3

Expand All @@ -18,6 +19,7 @@ CREATE TABLE t4 (
PARTITION t4_2 VALUES ('c')
);
INSERT INTO t4 VALUES ('a'), ('b'), ('c');
ANALYZE t4;
SELECT * FROM t4 ORDER BY str;
\d+ t4

Expand Down

0 comments on commit 7bda696

Please sign in to comment.