Skip to content
Open
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
3 changes: 2 additions & 1 deletion .github/workflows/build-cloudberry-rocky8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ jobs:
"make_configs":["gpcontrib/orafce:installcheck",
"gpcontrib/zstd:installcheck",
"gpcontrib/gp_sparse_vector:installcheck",
"gpcontrib/gp_toolkit:installcheck"]
"gpcontrib/gp_toolkit:installcheck",
"gpcontrib/gp_url_tools:installcheck"]
},
{"test":"ic-fixme",
"make_configs":["src/test/regress:installcheck-fixme"],
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build-cloudberry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ jobs:
"gpcontrib/zstd:installcheck",
"gpcontrib/gp_sparse_vector:installcheck",
"gpcontrib/gp_toolkit:installcheck",
"gpcontrib/gp_exttable_fdw:installcheck"]
"gpcontrib/gp_exttable_fdw:installcheck",
"gpcontrib/gp_url_tools:installcheck"]
},
{"test":"ic-diskquota",
"make_configs":["gpcontrib/diskquota:installcheck"],
Expand Down
17 changes: 17 additions & 0 deletions gpcontrib/gp_url_tools/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DATA = $(wildcard sql/*.sql)
MODULES = $(patsubst %.c,%,$(wildcard src/*.c))
EXTENSION = gp_url_tools

TESTS = $(wildcard test/sql/*.sql)
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test

ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
75 changes: 75 additions & 0 deletions gpcontrib/gp_url_tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

# gp_url_tools: Cloudberry extension providing functionality for working with URL addresses

### Features
`gp_url_tools` is an extension for the Cloudberry database that gives implementation
for functions that encode/decode url/uri.

### Functions
The extension creates the `url_tools_schema` schema and adds four SQL functions:

- `url_tools_schema.encode_url`/`.encode_uri`
Encodes a text value for use as a URL/URI component by replacing reserved characters with percent-encoded sequences.

- `url_tools_schema.decode_url`/`.decode_uri`
Decodes percent-encoded sequences in a URL/URI-encoded text value back to their original characters (human-readable).

### Usage
```sql
CREATE EXTENSION gp_url_tools;
```
```sql
SELECT url_tools_schema.encode_url('Hello World');
```
```bash
encode_url
───────────────
Hello%20World
(1 row)
```
```sql
SELECT url_tools_schema.decode_url('Hello%20World');
```
```bash
decode_url
─────────────
Hello World
(1 row)
```
```sql
SELECT url_tools_schema.encode_uri('https://ru.wikipedia.org/wiki/Greenplum_(компания)');
```
```bash
encode_uri
────────────────────────────────────────────────────────────────────────────────────────────
https://ru.wikipedia.org/wiki/Greenplum_(%D0%BA%D0%BE%D0%BC%D0%BF%D0%B0%D0%BD%D0%B8%D1%8F)
```
```sql
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)');
```
```bash
decode_uri
────────────────────────────────────────────────────
https://ru.wikipedia.org/wiki/Greenplum_(компания)
```

### Acknowledgments
Thank you very much for the extension for PostgreSQL: https://github.com/okbob/url_encode, its sources were very useful.
6 changes: 6 additions & 0 deletions gpcontrib/gp_url_tools/gp_url_tools.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# gp_url_tools extension
comment = 'Functions for working with URL-s'
default_version = '1.0'
module_pathname = '$libdir/gp_url_tools'
relocatable = true
trusted = true
Comment thread
andr-sokolov marked this conversation as resolved.
27 changes: 27 additions & 0 deletions gpcontrib/gp_url_tools/sql/gp_url_tools--1.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* gp_url_tools--1.0.sql */

-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION gp_url_tools" to load this file. \quit

CREATE SCHEMA IF NOT EXISTS url_tools_schema;
GRANT USAGE ON SCHEMA url_tools_schema TO public;

CREATE FUNCTION url_tools_schema.encode_url(text)
RETURNS text
AS 'MODULE_PATHNAME', 'encode_url'
LANGUAGE C IMMUTABLE STRICT;

CREATE FUNCTION url_tools_schema.decode_url(text)
RETURNS text
AS 'MODULE_PATHNAME', 'decode_url'
LANGUAGE C IMMUTABLE STRICT;

CREATE FUNCTION url_tools_schema.encode_uri(text)
RETURNS text
AS 'MODULE_PATHNAME', 'encode_uri'
LANGUAGE C IMMUTABLE STRICT;

CREATE FUNCTION url_tools_schema.decode_uri(text)
RETURNS text
AS 'MODULE_PATHNAME', 'decode_uri'
LANGUAGE C IMMUTABLE STRICT;
Loading