Skip to content

Commit

Permalink
Add pattern matching pushdown support to docs and release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjonesbr committed Mar 22, 2024
1 parent 389514d commit 9538c6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Release date: **YYYY-MM-DD**

* [`USER MAPPING`](https://github.com/jimjonesbr/rdf_fdw?tab=readme-ov-file#create-user-mapping) support: This feature defines a mapping of a PostgreSQL user to an user in the target triplestore - `user` and `password`, so that the user can be authenticated. Requested by Matt Goldberg.

* Pushdown suuport for [pattern matching operators](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE) `LIKE` and `ILIKE`: these operators are now translated into SPARQL FILTER expressions as REGEX and pushed down.

### Bug Fixes
* SELECT clause without any variable: This bug led some SPARQL queries to be created without any variable in the SELECT clause. We now use 'SELECT *' in case the planner cannot identify which nodes should be retrieved, which can be a bit inefficent if we're dealing with many columns, but it is better than an error message.

## 1.0.0
Release date: **2024-03-15**

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ The `rdf_fdw` will attempt to translate RDF literals to the data type of the map

| Data type | Operators |
|------------------------------------------------------------|---------------------------------------|
| `text`, `char`, `varchar`, `name` | `=`, `<>`, `!=` |
| `text`, `char`, `varchar`, `name` | `=`, `<>`, `!=`, `~~`, `!~~`, `~~*`, `!~~*` |
| `date`, `timestamp`, `timestamp with time zone` | `=`, `<>`, `!=`, `>`, `>=`, `<`, `<=` |
| `smallint`, `int`, `bigint`, `numeric`, `double precision` | `=`, `<>`, `!=`, `>`, `>=`, `<`, `<=` |
| `boolean` | `IS`, `IS NOT` |
Expand All @@ -411,14 +411,20 @@ The `rdf_fdw` will attempt to translate RDF literals to the data type of the map

SQL `IN` and `ANY` constructs are translated into the SPARQL [`IN` operator](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-in), which will be placed in a [`FILTER` evaluation](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#evaluation).

#### LIKE / ILIKE pattern matching operators

Expressions using `LIKE` and `ILIKE` - or their equivalent operators `~~` and `~~*` - are converted to [REGEX](https://www.w3.org/TR/sparql11-query/#func-regex) filters in SPARQL. It is important to notice that pattern matching operations using `LIKE`/`ILIKE` only support the wildcards `%` and `_`, and therefore only these characters will be translated to their `REGEX` equivalents. Any other character that might be potentially used as a wildcard in `REGEX`, such as `^`, `|` or `$`, will be escaped.

### Pushdown Examples

Foreign table columns with the option `literaltype`

| PostgreSQL Type | Literal Type | SQL WHERE Condition | SPARQL (pushdown) |
| PostgreSQL Type | Literal Type | SQL WHERE Condition | SPARQL (pushdown) |
|------------------|----------------|-------------------------------------------------------|------------------------------------------------------------------------------------------------|
| `text` | `xsd:string` | `name = 'foo'` | `FILTER(?s = "foo"^^xsd:string)` |
| `text` | `*` | `name <> 'foo'` | `FILTER(STR(?s) != "foo")` |
| `text` | `*` | `name ILIKE '%Jon_s'`, ` name ~~* '%Jon_s'` | `FILTER(REGEX(?name,".*Jon.s$","i"))` |
| `text` | `*` | `name LIKE '%foo%'`, `name ~~ '%foo%';` | `FILTER(REGEX(?name,".*foo.*"))` |
| `int` | `xsd:integer` | `runtime > 42 ` | `FILTER(?runtime > 42)` |
| `int` | `xsd:integer` | `runtime > 40+2 ` | `FILTER(?runtime > 42)` |
| `numeric` | - | `val >= 42.73` | `FILTER(?val >= 42.73)` |
Expand Down

0 comments on commit 9538c6b

Please sign in to comment.