Skip to content

Commit 82eee09

Browse files
authored
Import gp_url_tools extension from Greenplum (#40)
The initial source is got from https://github.com/open-gpdb/gp_url_tools. Fix decoding of UTF-16 surrogate pairs such as emoji in decode_url(). Make url_tools_schema accessible to all users via GRANT USAGE ON SCHEMA. Add new tests. Make refactoring. There is the extension description in gpcontrib/gp_url_tools/README.md.
1 parent 0a65125 commit 82eee09

11 files changed

Lines changed: 537 additions & 2 deletions

File tree

.github/workflows/build-cloudberry-rocky8.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ jobs:
319319
"make_configs":["gpcontrib/orafce:installcheck",
320320
"gpcontrib/zstd:installcheck",
321321
"gpcontrib/gp_sparse_vector:installcheck",
322-
"gpcontrib/gp_toolkit:installcheck"]
322+
"gpcontrib/gp_toolkit:installcheck",
323+
"gpcontrib/gp_url_tools:installcheck"]
323324
},
324325
{"test":"gpcontrib-gp-stats-collector",
325326
"make_configs":["gpcontrib/gp_stats_collector:installcheck"],

.github/workflows/build-cloudberry.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ jobs:
318318
"gpcontrib/gp_sparse_vector:installcheck",
319319
"gpcontrib/gp_toolkit:installcheck",
320320
"gpcontrib/gp_exttable_fdw:installcheck",
321-
"gpcontrib/gp_internal_tools:installcheck"]
321+
"gpcontrib/gp_internal_tools:installcheck",
322+
"gpcontrib/gp_url_tools:installcheck"]
322323
},
323324
{"test":"ic-diskquota",
324325
"make_configs":["gpcontrib/diskquota:installcheck"],

gpcontrib/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ifeq "$(enable_debug_extensions)" "yes"
2222
gp_legacy_string_agg \
2323
gp_replica_check \
2424
gp_toolkit \
25+
gp_url_tools \
2526
pg_hint_plan
2627
else
2728
recurse_targets = gp_sparse_vector \
@@ -30,6 +31,7 @@ else
3031
gp_legacy_string_agg \
3132
gp_exttable_fdw \
3233
gp_toolkit \
34+
gp_url_tools \
3335
pg_hint_plan
3436
endif
3537

gpcontrib/gp_url_tools/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
DATA = $(wildcard sql/*.sql)
2+
MODULES = $(patsubst %.c,%,$(wildcard src/*.c))
3+
EXTENSION = gp_url_tools
4+
5+
TESTS = $(wildcard test/sql/*.sql)
6+
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
7+
REGRESS_OPTS = --inputdir=test
8+
9+
ifdef USE_PGXS
10+
PG_CONFIG = pg_config
11+
PGXS := $(shell $(PG_CONFIG) --pgxs)
12+
include $(PGXS)
13+
else
14+
top_builddir = ../..
15+
include $(top_builddir)/src/Makefile.global
16+
include $(top_srcdir)/contrib/contrib-global.mk
17+
endif

gpcontrib/gp_url_tools/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# gp_url_tools: Cloudberry extension providing functionality for working with URL addresses
21+
22+
### Features
23+
`gp_url_tools` is an extension for the Cloudberry database that gives implementation
24+
for functions that encode/decode url/uri.
25+
26+
### Functions
27+
The extension creates the `url_tools_schema` schema and adds four SQL functions:
28+
29+
- `url_tools_schema.encode_url`/`.encode_uri`
30+
Encodes a text value for use as a URL/URI component by replacing reserved characters with percent-encoded sequences.
31+
32+
- `url_tools_schema.decode_url`/`.decode_uri`
33+
Decodes percent-encoded sequences in a URL/URI-encoded text value back to their original characters (human-readable).
34+
35+
### Usage
36+
```sql
37+
CREATE EXTENSION gp_url_tools;
38+
```
39+
```sql
40+
SELECT url_tools_schema.encode_url('Hello World');
41+
```
42+
```bash
43+
encode_url
44+
───────────────
45+
Hello%20World
46+
(1 row)
47+
```
48+
```sql
49+
SELECT url_tools_schema.decode_url('Hello%20World');
50+
```
51+
```bash
52+
decode_url
53+
─────────────
54+
Hello World
55+
(1 row)
56+
```
57+
```sql
58+
SELECT url_tools_schema.encode_uri('https://ru.wikipedia.org/wiki/Greenplum_(компания)');
59+
```
60+
```bash
61+
encode_uri
62+
────────────────────────────────────────────────────────────────────────────────────────────
63+
https://ru.wikipedia.org/wiki/Greenplum_(%D0%BA%D0%BE%D0%BC%D0%BF%D0%B0%D0%BD%D0%B8%D1%8F)
64+
```
65+
```sql
66+
SELECT url_tools_schema.decode_uri('https://ru.wikipedia.org/wiki/Greenplum_(%D0%BA%D0%BE%D0%BC%D0%BF%D0%B0%D0%BD%D0%B8%D1%8F)');
67+
```
68+
```bash
69+
decode_uri
70+
────────────────────────────────────────────────────
71+
https://ru.wikipedia.org/wiki/Greenplum_(компания)
72+
```
73+
74+
### Acknowledgments
75+
Thank you very much for the extension for PostgreSQL: https://github.com/okbob/url_encode, its sources were very useful.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# gp_url_tools extension
2+
comment = 'Functions for working with URL-s'
3+
default_version = '1.0'
4+
module_pathname = '$libdir/gp_url_tools'
5+
relocatable = true
6+
trusted = true
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* gp_url_tools--1.0.sql */
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use "CREATE EXTENSION gp_url_tools" to load this file. \quit
5+
6+
CREATE SCHEMA IF NOT EXISTS url_tools_schema;
7+
GRANT USAGE ON SCHEMA url_tools_schema TO public;
8+
9+
CREATE FUNCTION url_tools_schema.encode_url(text)
10+
RETURNS text
11+
AS 'MODULE_PATHNAME', 'encode_url'
12+
LANGUAGE C IMMUTABLE STRICT;
13+
14+
CREATE FUNCTION url_tools_schema.decode_url(text)
15+
RETURNS text
16+
AS 'MODULE_PATHNAME', 'decode_url'
17+
LANGUAGE C IMMUTABLE STRICT;
18+
19+
CREATE FUNCTION url_tools_schema.encode_uri(text)
20+
RETURNS text
21+
AS 'MODULE_PATHNAME', 'encode_uri'
22+
LANGUAGE C IMMUTABLE STRICT;
23+
24+
CREATE FUNCTION url_tools_schema.decode_uri(text)
25+
RETURNS text
26+
AS 'MODULE_PATHNAME', 'decode_uri'
27+
LANGUAGE C IMMUTABLE STRICT;

0 commit comments

Comments
 (0)