Skip to content

Support linear composition (NEXT) to chain statements in a single query #98

Description

@matiastoro

What is missing

There is no way to chain statements. All of these fail in the parser:

MATCH (n:Interseccion) RETURN n.osmid AS id
NEXT MATCH (m:Interseccion {osmid: id}) RETURN m.lat AS lat
-- ValueError: unexpected token Name("NEXT") at position 12

MATCH (n:Interseccion) WITH n.lat AS x RETURN x LIMIT 3
-- ValueError: unexpected token Name("WITH") at position 6

LET x = 1 RETURN x
-- ValueError: expected path pattern, got Name("LET")

MATCH (n:Interseccion) FILTER n.lat > -33.45 RETURN n.osmid AS id
-- ValueError: unexpected token Name("FILTER") at position 6

The ISO form is NEXT (linear composition), not Cypher's WITH — worth implementing that one, and it is the coherent choice given the rest of the engine follows ISO.

Why it matters

Any two-stage query splits into two round-trips with string interpolation in between. The concrete case: "the nearest corner to this point, and from there the route to that one."

-- today: two execute() calls, with the first result pasted by hand into the second
MATCH (n:Interseccion)
WHERE n.lat > -33.4503 AND n.lat < -33.4403
RETURN n.osmid AS id
ORDER BY (n.lat + 33.4453) * (n.lat + 33.4453) ASC
LIMIT 1
-- … then format that id into the second query

-- with NEXT: one query
MATCH (n:Interseccion) WHERE …
RETURN n.osmid AS origin ORDER BY … ASC LIMIT 1
NEXT
MATCH p = SHORTEST 1 (a:Interseccion {osmid: origin})-[:TRAMO]->*(b:Interseccion {osmid: '99'})
RETURN p

And since there is no parameter binding either ($id dies in the lexer: unexpected character: '$'), that intermediate paste is string concatenation — the very injection vector the README already warns about. NEXT shrinks the surface where it is needed considerably.

Reported against frogql 0.3.0 (PyPI wheel cp38-abi3-manylinux_2_17_x86_64, Python 3.11, Linux x64).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions