Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- **GFQL execution context is declared rather than attached at runtime**: the private `_gfql_*` per-execution fields (index policy and registry, row-pipeline base graph, carried seed nodes, edge aliases, shortest-path backend, and the indexed-bindings handoff) are now declared on `Plottable` with defaults on `PlotterBase`, instead of being set with `setattr` and read back with `getattr(..., default)`. No public API or behaviour change; internal call sites are typed, and hand-rolled `Plottable` stand-ins must now construct the full context.

### Fixed
- **Three BOUNDED variable-length shapes returned a silently different count on `engine='polars'` (#1787)**: the native polars `rows(binding_ops=...)` builder rebuilds a variable-length segment from the raw matching edge table, and for three bounded shapes that rebuild produces a different edge multiplicity than the pandas oracle — with no error, just a different number. They now raise `NotImplementedError` like every other shape this lowering cannot reproduce, which is a deliberate behaviour change: these were *served* before, so a silent wrong answer becomes a loud, actionable error, and `engine='pandas'` still answers all of them. The three: (1) directed `-[*k..m]->` with `min_hops >= 3`, and `min_hops >= 2` when the segment starts from a filtered seed — `max_reached_hop` in `compute/hop.py` is a dedup-by-node BFS eccentricity rather than a longest-walk length, so the oracle prunes to empty where the rebuild expands a different edge multiset; (2) the DEGENERATE undirected window `-[*1..1]-` / `-[*1]-`, which halved the count — it resolves to `min == max == 1` and so is not "multihop", yet pandas still routes it through the variable-length hop, which is exactly why it slipped past the existing gates (the gate therefore keys on an explicit variable-length window, not on `is_multihop`); (3) undirected `-[*1..k]-` that does not start from the full node set (filtered seed, or a non-first segment), where the doubled-pair expansion over-counts. Every neighbouring shape stays native and is pinned as such — unseeded `min_hops <= 2`, the directed twin of each undirected decline, the directed degenerate window, and the plain `-[]-` edge — so the gate is a scalpel rather than a blanket refusal of variable-length segments. Same root-cause family as the unbounded shapes #1781 declined; the gate should shrink again once the multiplicity is reconstructible. Found by differential fuzzing against the pandas oracle, and pinned by an engine-parametrized suite (pandas / polars / cuDF / polars-gpu) that encodes the intended per-engine behaviour — the polars engines must decline exactly where the pandas-API engines must answer — plus a seeded fuzz that fails if the gate declines too much.
- **`rows(table='edges')` silently returned the wrong table after a NAMED traversal**: the named-middle rewrite — which turns `[...named ops..., rows()]` into `rows(binding_ops=...)` so a Cypher multi-alias `RETURN` lowers to a bindings table — skipped itself when the call already carried `binding_ops`, `source` or `alias_endpoints`, but not when it carried a non-default `table`. So naming any op in the middle changed which table came back: an odd-length middle silently produced the BINDINGS table instead of the requested edges (no error, `table=` simply ignored), and an even-length middle — a path ending on an edge, e.g. `(person)-[r:KNOWS]-` — produced a non-alternating op list and raised "require ... a single connected alternating node/edge path". An unnamed middle was unaffected, which is what made it look shape-specific rather than naming-specific. Both chain surfaces are fixed (the generic chain and the native polars chain carry the rewrite independently, so fixing one left the other wrong). Note the guard keys on a NON-DEFAULT table: `rows()` declares `table='nodes'` and always emits it, so an explicit `rows(table='nodes')` is indistinguishable from a bare `rows()` and still rewrites — pinned as a known limitation rather than left to be rediscovered.
- **Indexed bindings bypass returned the WHOLE edge table for `rows(table='edges')`**: the bypass exists to SKIP the canonical traversal, so whatever it hands the suffix is the pre-traversal graph. That is sound for a bindings table — the indexed path bag already is the answer — but the gate declined only for `source` / `alias_endpoints` / `alias_prefilters`, not for a non-default `table`, so a `rows(table='edges')` after a named middle read the full edge frame instead of the traversal-narrowed one (measured on a 12-edge fixture: 12 rows instead of 3, on pandas, cuDF and native polars, and the wrong values survive a following `select`). Both gates now decline a non-default `table` (`chain._plan_indexed_middle` and the native polars `_try_indexed_middle_polars`), matching the named-middle rewrite's guard. This became reachable only once that rewrite stopped firing for a non-default `table` — before it, the rewrite converted the call on BOTH the indexed and the scan path, so the two agreed on the wrong table. Same class as the earlier "indexed bypass could return every node for `rows()` over an unnamed pattern".
- **The named-middle rewrite discarded the caller's other `rows()` params**: both rewrites built a FRESH `rows(binding_ops=...)` instead of adding `binding_ops` to the call the caller wrote, so every param the rewrite has no opinion about was thrown away. For `attach_prop_aliases` — the projection pushdown — that is observable: spelling a pattern as a NAMED middle rather than as explicit `binding_ops` silently attached every alias's properties instead of the requested ones, i.e. the same query returned a wider schema depending only on how it was written. `alias_prefilters` was dropped the same way. Both are now carried through, on both chain surfaces. Known remaining gap, pinned by a strict-xfail test rather than left to be rediscovered: the native polars bindings builder never receives `alias_prefilters` at all, so hand-written GFQL passing that hint without an equivalent post-filter still gets engine-dependent row counts (Cypher-generated plans always keep the post-filter, so they agree across engines and only lose the pushdown).
Expand Down
3 changes: 3 additions & 0 deletions bin/test-polars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ POLARS_TEST_FILES=(
graphistry/tests/compute/gfql/test_engine_polars_chain.py
graphistry/tests/compute/gfql/test_engine_polars_row_pipeline.py
graphistry/tests/compute/gfql/test_engine_polars_binding_rows.py
# engine-parametrized (pandas/polars/cudf/polars-gpu); the pandas params also run in
# test-gfql-core, but only this lane has polars installed
graphistry/tests/compute/gfql/test_varlen_bounded_engine_parity_1787.py
graphistry/tests/compute/gfql/test_engine_polars_with_match_reentry.py
graphistry/tests/compute/gfql/test_engine_polars_cypher_conformance.py
graphistry/tests/compute/gfql/test_engine_polars_conformance_matrix.py
Expand Down
35 changes: 35 additions & 0 deletions graphistry/compute/gfql/lazy/engine/polars/row_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,41 @@ def _names(lf: pl.LazyFrame) -> List[str]:
)
if _resolved_min != 1:
return None
# #1787, same root-cause family as the unbounded shapes #1781 declined: pandas'
# step_pairs come from the var-length `edge_op.execute` hop, whose hop-window
# pruning -- and, when seeded, its per-seed BFS -- changes an edge multiplicity
# this raw-edge rebuild cannot reproduce. Declining is a DELIBERATE divergence
# from master, which served these: parity-or-NIE means a loud error, never a
# different number. Shrink the gate again once the multiplicity is reconstructible.
# WHICH shapes, why each boundary sits where it does, and the counts that prove
# each one are executable rather than prose -- every claim that used to be written
# out here is now a named test in:
# graphistry/tests/compute/gfql/test_varlen_bounded_engine_parity_1787.py
#
# Keyed on an EXPLICIT window, NOT on `sem.is_multihop`: `-[*1..1]-` resolves to
# min == max == 1, is therefore not multihop, and pandas still routes it here.
if op.min_hops is not None or op.max_hops is not None:
_vl_max = op.max_hops if op.max_hops is not None else op.hops
_vl_min = op.min_hops if op.min_hops is not None else (
op.hops if op.hops is not None else 1
)
# a seed is anything that starts the segment from less than the whole node
# set: a filtered start alias, or a re-entry / `WITH` seed frame
_prev_op = ops[idx - 1] if idx >= 1 else None
_seeded_start = start_nodes is not None or (
isinstance(_prev_op, ASTNode) and bool(_prev_op.filter_dict)
)
if _vl_max is not None:
if op.direction == "undirected":
if _vl_max == 1: # the degenerate window `-[*1..1]-` / `-[*1]-`
return None
if _seeded_start or idx > 1: # doubled-pair expansion over-counts
return None
# `max_reached_hop` (compute/hop.py) is a dedup-by-node BFS eccentricity,
# not a longest-walk length, so pandas prunes where this rebuild expands
# a different edge multiset
elif _vl_min >= 3 or (_vl_min >= 2 and _seeded_start):
return None
if op.direction not in ("forward", "reverse", "undirected"):
return None
if any(
Expand Down
Loading
Loading