Skip to content

Commit

Permalink
add support for casei and accenti (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitner authored Apr 17, 2024
1 parent e5be8a7 commit 61f6433
Show file tree
Hide file tree
Showing 11 changed files with 5,263 additions and 6 deletions.
746 changes: 746 additions & 0 deletions src/pgstac/migrations/pgstac.0.8.5-unreleased.sql

Large diffs are not rendered by default.

4,429 changes: 4,429 additions & 0 deletions src/pgstac/migrations/pgstac.unreleased.sql

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/pgstac/pgstac.sql
3 changes: 3 additions & 0 deletions src/pgstac/sql/000_idempotent_pre.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname='btree_gist') THEN
CREATE EXTENSION IF NOT EXISTS btree_gist;
END IF;
IF NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname='btree_gist') THEN
CREATE EXTENSION IF NOT EXISTS unaccent;
END IF;
END;
$$ LANGUAGE PLPGSQL;

Expand Down
4 changes: 3 additions & 1 deletion src/pgstac/sql/002b_cql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ INSERT INTO cql2_ops (op, template, types) VALUES
('between', '%s BETWEEN %s AND %s', NULL),
('isnull', '%s IS NULL', NULL),
('upper', 'upper(%s)', NULL),
('lower', 'lower(%s)', NULL)
('lower', 'lower(%s)', NULL),
('casei', 'upper(%s)', NULL),
('accenti', 'unaccent(%s)', NULL)
ON CONFLICT (op) DO UPDATE
SET
template = EXCLUDED.template
Expand Down
37 changes: 37 additions & 0 deletions src/pgstac/sql/998_idempotent_post.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,43 @@ INSERT INTO pgstac_settings (name, value) VALUES
ON CONFLICT DO NOTHING
;


INSERT INTO cql2_ops (op, template, types) VALUES
('eq', '%s = %s', NULL),
('neq', '%s != %s', NULL),
('ne', '%s != %s', NULL),
('!=', '%s != %s', NULL),
('<>', '%s != %s', NULL),
('lt', '%s < %s', NULL),
('lte', '%s <= %s', NULL),
('gt', '%s > %s', NULL),
('gte', '%s >= %s', NULL),
('le', '%s <= %s', NULL),
('ge', '%s >= %s', NULL),
('=', '%s = %s', NULL),
('<', '%s < %s', NULL),
('<=', '%s <= %s', NULL),
('>', '%s > %s', NULL),
('>=', '%s >= %s', NULL),
('like', '%s LIKE %s', NULL),
('ilike', '%s ILIKE %s', NULL),
('+', '%s + %s', NULL),
('-', '%s - %s', NULL),
('*', '%s * %s', NULL),
('/', '%s / %s', NULL),
('not', 'NOT (%s)', NULL),
('between', '%s BETWEEN %s AND %s', NULL),
('isnull', '%s IS NULL', NULL),
('upper', 'upper(%s)', NULL),
('lower', 'lower(%s)', NULL),
('casei', 'upper(%s)', NULL),
('accenti', 'unaccent(%s)', NULL)
ON CONFLICT (op) DO UPDATE
SET
template = EXCLUDED.template
;


ALTER FUNCTION to_text COST 5000;
ALTER FUNCTION to_float COST 5000;
ALTER FUNCTION to_int COST 5000;
Expand Down
2 changes: 1 addition & 1 deletion src/pgstac/sql/999_version.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT set_version('0.8.5');
SELECT set_version('unreleased');
2 changes: 1 addition & 1 deletion src/pgstac/tests/pgtap.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CREATE EXTENSION IF NOT EXISTS pgtap;
SET SEARCH_PATH TO pgstac, pgtap, public;

-- Plan the tests.
SELECT plan(218);
SELECT plan(225);
--SELECT * FROM no_plan();

-- Run the tests.
Expand Down
40 changes: 40 additions & 0 deletions src/pgstac/tests/pgtap/004_search.sql
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,46 @@ SELECT results_eq($$
$$, 'Test lower'
);

SELECT results_eq($$
SELECT BTRIM(stac_search_to_where($q$
{
"filter-lang": "cql2-json",
"filter": {
"op": "eq",
"args": [
{"op": "casei", "args":[{ "property": "mission" }]},
{"op": "casei", "args":["sentinel"]}
]
}
}
$q$),E' \n');
$$, $$
SELECT BTRIM($r$
upper(to_text(content->'properties'->'mission')) = upper(to_text('"sentinel"'))
$r$,E' \n');
$$, 'Test casei'
);

SELECT results_eq($$
SELECT BTRIM(stac_search_to_where($q$
{
"filter-lang": "cql2-json",
"filter": {
"op": "eq",
"args": [
{"op": "accenti", "args":[{ "property": "mission" }]},
{"op": "accenti", "args":["sentinel"]}
]
}
}
$q$),E' \n');
$$, $$
SELECT BTRIM($r$
unaccent(to_text(content->'properties'->'mission')) = unaccent(to_text('"sentinel"'))
$r$,E' \n');
$$, 'Test accenti'
);



/* template
Expand Down
2 changes: 1 addition & 1 deletion src/pypgstac/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pypgstac"
version = "0.8.5"
version = "0.8.5-dev"
description = "Schema, functions and a python library for storing and accessing STAC collections and items in PostgreSQL"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
2 changes: 1 addition & 1 deletion src/pypgstac/python/pypgstac/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Version."""
__version__ = "0.8.5"
__version__ = "0.8.5-dev"

0 comments on commit 61f6433

Please sign in to comment.