Skip to main content

Module pattern

Module pattern 

Source
Expand description

SPARQL group-graph-pattern parser — the WHERE-clause grammar.

Parses { … } groups into the Pattern arena the planner/executor already consume: basic triple patterns, OPTIONAL { … }, { … } UNION { … }, MINUS { … }, nested groups, << s p o >> quoted triples, and FILTER(…) (whose expression is parsed by super::expr).

§The arena-contiguity constraint

Pattern::Group { start_idx, len } is planned by joining the contiguous range [start_idx, start_idx+len) of the pattern arena. So a group’s direct children must be allocated as one uninterrupted batch. We therefore parse a group into a list of ChildSpecs — building any inner sub-patterns (OPTIONAL/UNION/MINUS inners) eagerly and referencing them by id — and only then allocate the direct-child nodes contiguously. Plain nested groups are flattened into the parent (group nesting is join-associative), which also sidesteps the contiguity problem for them.

§Engine semantics

An OPTIONAL group child lowers to a real left-join and a MINUS child to a real anti-join (SPARQL 1.1: a left solution survives MINUS unless a right solution is compatible with it and shares a bound variable). Filter/BIND scoping over a group is simplified (both apply over the whole group’s join result — see below), which is the remaining deliberate simplification here.

Functions§

parse_where_group
Parse a WHERE group graph pattern from a fragment beginning at (or before) the opening {. Returns the root PatternId.