Skip to content

cql, features-sql: composite-key result sets (inResultSetByKey) - #631

Merged
azahnen merged 1 commit into
masterfrom
inresultsetbykey
Sep 23, 2026
Merged

azahnen merged 1 commit into
masterfrom
inresultsetbykey

Conversation

@cportele

Copy link
Copy Markdown
Contributor

Part of addressing ldproxy/ldproxy#1774.

Comments:

The predicate is encoded as EXISTS, not as a row-constructor IN: with IN, a null in any key part would make the negation unknown and drop the feature, although "this key is not a member" is what the filter asks for. EXISTS also gives the three sources of a result set — materialized table, inlined values, re-derived producer — the same shape, and its negation is NOT EXISTS without further handling.

The producer of a key set selects DISTINCT keys, since the members of the set are the distinct keys rather than the rows of the producing feature type.

ResultSetReference is the common interface of the two predicates, so the materializer collects, orders and rewrites both without knowing which kind it holds.

A result set of a query expression could only be joined on a single
value: the ids of the selected features, or the values of one of their
properties. A key with several parts therefore had to be approximated by
a conjunction of one predicate per part, which selects a superset —
every combination of the part values, not only the combinations that
actually occur.

The new predicate joins on the whole key at once. Both sides name the
parts, and the parts are matched by name rather than by position:

  "resultSets": { "s": { "key": { "land": "gmd_lan", "kreis": "gmd_krs" } } }

  { "op": "inResultSetByKey",
    "args": [ { "land": {"property": "gkz_lan"},
                "kreis": {"property": "gkz_krs"} }, "s" ] }

Names rather than positions because a key whose parts share a type — as
administrative keys do — could otherwise have two parts transposed, and
the query would run and return the wrong features with nothing to show
for it. A part that one side does not declare is reported before the
query is encoded.

The predicate is encoded as EXISTS, not as a row-constructor IN: with
IN, a null in any key part would make the negation unknown and drop the
feature, although "this key is not a member" is what the filter asks
for. EXISTS also gives the three sources of a result set — materialized
table, inlined values, re-derived producer — the same shape, and its
negation is NOT EXISTS without further handling.

The parts have to be columns of the main table on both sides; a property
in a child or junction table would encode as a semi-join subquery, which
cannot take part in a row-wise comparison. Both sides check this against
the mapping and name the offending part.

inResultSet is unchanged, so existing query expressions are unaffected;
a result set is either a set of values or a set of keys, and consuming
one as the other is rejected. The producer of a key set selects DISTINCT
keys, since the members of the set are the distinct keys rather than the
rows of the producing feature type. There is no CQL2-Text encoding; the
predicate can only be used in a query expression.

ResultSetReference is the common interface of the two predicates, so the
materializer collects, orders and rewrites both without knowing which
kind it holds.
@azahnen
azahnen merged commit aee81f0 into master Sep 23, 2026
3 checks passed
@azahnen
azahnen deleted the inresultsetbykey branch September 23, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants