Skip to main content

Module pattern

Module pattern 

Source
Expand description

SQL/PGQ pattern matching: GRAPH_TABLE (g MATCH … COLUMNS (…)) (#296).

Ursa’s parser rewrites GRAPH_TABLE ( body ) into graph_table('body'); the relation planner hands the body here. parse reads it into a Pattern; lower resolves each variable to one of the graph’s element tables and says what to join: a Lowered match, which the planner builds as a logical plan (scans of the element tables, equality conditions, the pattern’s conditions and COLUMNS). DataFusion’s optimizer turns the equalities into hash joins.

Supported:

GRAPH_TABLE ( graph
  MATCH path [, path …]
  [WHERE condition]
  COLUMNS ( expression [AS name], … ) )

path       := [var =] [selector] [mode [PATH | PATHS]] node (edge node)*
selector   := ANY SHORTEST | ALL SHORTEST | ANY [k] | SHORTEST k | ALL
mode       := WALK | TRAIL | SIMPLE | ACYCLIC
node       := ( [var] [:label | IS label] [WHERE condition] )
edge       := (-[ spec ]->  |  <-[ spec ]-  |  -[ spec ]-  |  ->  |  <-  |  -) [quantifier]
quantifier := * | + | ? | {n} | {m,n} | {m,} | {,n}
spec       := [var] [:label | IS label] [WHERE condition]

Conditions and COLUMNS are SQL expressions over the variables (a.name); each variable is a relation of that name. A label names an element table: by its name or one of its labels. A variable without one gets the only table it can be: from the edges next to it and their REFERENCES, or because the graph has one table of that kind; otherwise the pattern is refused, never guessed.

Each variable reads its element table’s properties: every column, or what its labels’ PROPERTIES clauses give, under their property names. An undirected edge -[e]- matches both orientations of each edge (a self-loop once): the match is a UNION ALL with one branch per orientation, so every join stays an equality join.

A quantified edge, and the edge of a path with a path variable, a selector or a mode, is not joined: it is a Segment, searched on the graph index (see super::path_search), and joined to the nodes at its ends. A path with a variable, a selector or a mode is one edge between two nodes for now. Label expressions (|, &, !) and parenthesized path patterns are refused with a message.

Structs§

Lowered
A pattern resolved against a graph: what to scan and join.
PathPattern
One path of a MATCH: [p =] [selector] [mode] (a)-[e]->…(b).
Pattern
A parsed GRAPH_TABLE body.
Quantifier
An edge’s quantifier: how many times it repeats, {min,max}.
Segment
An edge searched on the graph index rather than joined: a quantified edge, or the edge of a path with a path variable, a selector or a mode. It is a relation of paths, named var, with the columns of super::path_search: the path’s first and last node, its length, and its nodes and edges.
Source
What a variable reads: an element table (or the graph’s nodes table), all its columns or columns as (column, property name).
Spec
A node or edge: [var] [:label] [WHERE condition].

Enums§

Direction
Element
One element of a path: nodes and edges alternate, starting with a node.
Join
A condition the lowering adds.
Mode
Which walks a path may be (SQL/PGQ’s path modes).
Selector
Which of a pair of nodes’ paths a path keeps.

Constants§

FUNCTION
The table function Ursa’s parser rewrites GRAPH_TABLE ( … ) into.

Functions§

lower
Resolve pattern against graph. schema_of gives a table’s columns (for properties).
parse
Parse a GRAPH_TABLE body: graph MATCH … [WHERE …] COLUMNS (…).

Type Aliases§

VarColumn
A column of a variable: (variable, column).