From 05a2e471f36e5ceb7c414c79ebd65471f999e80e Mon Sep 17 00:00:00 2001 From: Sean Johnson Date: Tue, 27 Oct 2026 18:28:10 -0500 Subject: [PATCH 1/6] fix: single-bound roots passing to SP harness --- cypher/models/pgsql/translate/expansion.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cypher/models/pgsql/translate/expansion.go b/cypher/models/pgsql/translate/expansion.go index 4ea4d438..12c39132 100644 --- a/cypher/models/pgsql/translate/expansion.go +++ b/cypher/models/pgsql/translate/expansion.go @@ -3285,6 +3285,17 @@ func (s *ExpansionBuilder) boundEndpointFilterParameters() ([]pgsql.Expression, return nil, nil } + // Dynamic filter SQL is executed inside PL/pgSQL and cannot see an outer + // translation frame. Materialize a single correlated endpoint in the outer + // query and use the existing array overload instead. Both-bound endpoints + // must retain their pair filter because independent arrays lose pair semantics. + if !hasPairFilter && s.usesBoundRootIDs() != s.usesBoundTerminalIDs() { + return []pgsql.Expression{ + endpointIDsArrayParameter(rootFilterStatement, hasRootFilter), + endpointIDsArrayParameter(terminalFilterStatement, hasTerminalFilter), + }, nil + } + // Pair filters supersede separate root/terminal filters because they encode // the allowed combinations, not just independent endpoint sets. var ( @@ -3327,6 +3338,16 @@ func (s *ExpansionBuilder) boundEndpointFilterParameters() ([]pgsql.Expression, return filterParameters, nil } +func endpointIDsArrayParameter(filterStatement pgsql.Insert, hasFilter bool) pgsql.Expression { + if !hasFilter { + return pgsql.ArrayLiteral{CastType: pgsql.Int8Array} + } + + return pgsql.NewTypeCast(pgsql.ArrayExpression{ + Expression: *filterStatement.Source, + }, pgsql.Int8Array) +} + // shortestPathsParameters renders a forward search's query fragments, depth limit, and filter inserts as harness parameters. func (s *ExpansionBuilder) shortestPathsParameters(expansionModel *Expansion, forwardFrontPrimerQuery pgsql.SetExpression, forwardFrontRecursiveQuery pgsql.SetExpression) ([]pgsql.Expression, error) { var ( From 4cdced862ad20f5163a8eb8ac296c84a3afda466 Mon Sep 17 00:00:00 2001 From: Sean Johnson Date: Tue, 27 Oct 2026 18:28:39 -0500 Subject: [PATCH 2/6] chore: tests for single-bound roots passing --- .../test/translation_cases/shortest_paths.sql | 28 +++++++++++++++++-- .../testdata/cases/shortest_paths_inline.json | 21 ++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/cypher/models/pgsql/test/translation_cases/shortest_paths.sql b/cypher/models/pgsql/test/translation_cases/shortest_paths.sql index 279b7480..562301b8 100644 --- a/cypher/models/pgsql/test/translation_cases/shortest_paths.sql +++ b/cypher/models/pgsql/test/translation_cases/shortest_paths.sql @@ -63,8 +63,8 @@ with s0 as (with s1(root_id, next_id, depth, satisfied, is_cycle, path) as (sele with s0 as (with s1(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, false)) select s1.path as ep0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from s1 join node n1 on n1.id = s1.root_id join node n0 on n0.id = s1.next_id) select case when (s0.n0).id is null or s0.ep0 is null or (s0.n1).id is null then null else ordered_edge_ids_to_path(0, s0.n0, s0.ep0, array [s0.n0, s0.n1]::nodecomposite[])::pathcomposite end as p from s0 where ((s0.n0).id <> (s0.n1).id); -- case: match p=(c:NodeKind1)-[]->(u:NodeKind2) match p2=shortestPath((u:NodeKind2)-[*1..]->(d:NodeKind1)) return p, p2 limit 500 --- pgsql_params:{"__strlit0":"insert into traversal_root_filter (id) select distinct (s0.n1).id from s0 where (s0.n1).id is not null;","__strlit1":"insert into traversal_terminal_filter (id) select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@\u003e) array [1]::int2[] and n2.id is not null;","pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select distinct n1.id as root_id from traversal_root_filter s2_seed_filter join node n1 on n1.id = s2_seed_filter.id where n1.kind_ids operator (pg_catalog.@\u003e) array [2]::int2[]) select e1.start_id, e1.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.end_id);"} -with s0 as (select e0.id as e0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [1]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [2]::int2[] and n1.id = e0.end_id), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (@__strlit0::text)::text, (@__strlit1::text)::text, false)) select s0.e0 as e0, s2.path as ep0, s0.n0 as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n0).id is null or s1.e0 is null or (s1.n1).id is null then null else ordered_edge_ids_to_path(0, s1.n0, array [s1.e0]::int8[], array [s1.n0, s1.n1]::nodecomposite[])::pathcomposite end as p, case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p2 from s1 limit 500; +-- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select distinct n1.id as root_id from traversal_root_filter s2_seed_filter join node n1 on n1.id = s2_seed_filter.id where n1.kind_ids operator (pg_catalog.@\u003e) array [2]::int2[]) select e1.start_id, e1.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.end_id);"} +with s0 as (select e0.id as e0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [1]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [2]::int2[] and n1.id = e0.end_id), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[], (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [1]::int2[] and n2.id is not null))::int8[], false)) select s0.e0 as e0, s2.path as ep0, s0.n0 as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n0).id is null or s1.e0 is null or (s1.n1).id is null then null else ordered_edge_ids_to_path(0, s1.n0, array [s1.e0]::int8[], array [s1.n0, s1.n1]::nodecomposite[])::pathcomposite end as p, case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p2 from s1 limit 500; -- case: match p = allShortestPaths((a)-[:EdgeKind1*..]->()) return p -- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select e0.start_id, e0.end_id, 1, exists (select 1 from edge where end_id = e0.start_id), e0.start_id = e0.end_id, array [e0.id] from edge e0 where e0.kind_id = any (array [3]::int2[]) and dawgs_admit_traversal_v1(1, e0.id) and case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e0.start_id) = 0 then true else shortest_path_self_endpoint_error(e0.start_id, e0.start_id) end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s1.root_id, e0.end_id, s1.depth + 1, exists (select 1 from edge where end_id = e0.start_id), false, s1.path || e0.id from forward_front s1 join edge e0 on e0.start_id = s1.next_id where e0.kind_id = any (array [3]::int2[]) and dawgs_admit_traversal_v1(s1.depth + 1, e0.id) and e0.id != all (s1.path);"} @@ -86,6 +86,30 @@ with s0 as (select (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0 from -- pgsql_params:{"__strlit0":"","__strlit1":"insert into traversal_terminal_filter (id) select distinct n1.id from node n1 where n1.kind_ids operator (pg_catalog.@\u003e) array [2]::int2[] and n1.id is not null;","pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select n0.id as root_id from node n0 where n0.kind_ids operator (pg_catalog.@\u003e) array [1]::int2[]) select e0.start_id, e0.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e0.end_id), e0.start_id = e0.end_id, array [e0.id] from s2_seed join edge e0 on e0.start_id = s2_seed.root_id where e0.kind_id = any (array [3]::int2[]) and dawgs_admit_traversal_v1(1, e0.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e0.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e0.start_id) = 0 then true else shortest_path_self_endpoint_error(e0.start_id, e0.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e0.end_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e0.end_id), false, s2.path || e0.id from forward_front s2 join edge e0 on e0.start_id = s2.next_id where e0.kind_id = any (array [3]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e0.id) and e0.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e0.end_id);"} with s0 as (with s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (@__strlit0::text)::text, (@__strlit1::text)::text, false)) select (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from s2 join node n0 on n0.id = s2.root_id join node n1 on n1.id = s2.next_id where case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select distinct s1.n1 as n2, count(s1.n0)::int8 as i0 from s1 group by n1) select ((s0.n2).properties -> E'name') as "Group.name", s0.i0 as "UserCount" from s0 order by s0.i0 desc limit 5; +-- case: MATCH p=shortestPath((n:Group)-[:AdminTo*1..]->(m:Computer)) RETURN p +-- pgsql_params:{"__strlit0":"","__strlit1":"insert into traversal_terminal_filter (id) select distinct n1.id from node n1 where n1.kind_ids operator (pg_catalog.@\u003e) array [5]::int2[] and n1.id is not null;","pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s1_seed(root_id) as not materialized (select n0.id as root_id from node n0 where n0.kind_ids operator (pg_catalog.@\u003e) array [13]::int2[]) select e0.start_id, e0.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e0.end_id), e0.start_id = e0.end_id, array [e0.id] from s1_seed join edge e0 on e0.start_id = s1_seed.root_id where e0.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e0.id) and case when exists (select 1 from s1_seed where s1_seed.root_id = e0.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e0.start_id) = 0 then true else shortest_path_self_endpoint_error(e0.start_id, e0.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s1.root_id, e0.end_id, s1.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e0.end_id), false, s1.path || e0.id from forward_front s1 join edge e0 on e0.start_id = s1.next_id where e0.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s1.depth + 1, e0.id) and e0.id != all (s1.path) and not exists (select 1 from visited where visited.root_id = s1.root_id and visited.id = e0.end_id);"} +with s0 as (with s1(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (@__strlit0::text)::text, (@__strlit1::text)::text, false)) select s1.path as ep0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from s1 join node n0 on n0.id = s1.root_id join node n1 on n1.id = s1.next_id where case when s1.root_id != s1.next_id then true else shortest_path_self_endpoint_error(s1.root_id, s1.next_id) end) select case when (s0.n0).id is null or s0.ep0 is null or (s0.n1).id is null then null else ordered_edge_ids_to_path(0, s0.n0, s0.ep0, array [s0.n0, s0.n1]::nodecomposite[])::pathcomposite end as p from s0; + +-- case: MATCH (:User)-[:MemberOf]->(u:Group) MATCH p=shortestPath((u)-[:AdminTo*1..]->(d)) RETURN p +-- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.start_id, e1.end_id, 1, exists (select 1 from edge where end_id = e1.start_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from edge where end_id = e1.start_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.end_id);"} +with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[], array []::int8[], false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p from s1; + +-- case: MATCH (:User)-[:MemberOf]->(d:Group) MATCH p=shortestPath((u:Computer)-[:AdminTo*1..]->(d)) RETURN p +-- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.end_id, e1.start_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.end_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.end_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id) = 0 then true else shortest_path_self_endpoint_error(e1.end_id, e1.end_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.start_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id), false, e1.id || s2.path from forward_front s2 join edge e1 on e1.end_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.start_id);"} +with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[], (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n2.id is not null))::int8[], false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n2).id is null or s1.ep0 is null or (s1.n1).id is null then null else ordered_edge_ids_to_path(0, s1.n2, s1.ep0, array [s1.n2, s1.n1]::nodecomposite[])::pathcomposite end as p from s1; + +-- case: MATCH (:User)-[:MemberOf]->(u:Group) MATCH p=allShortestPaths((u)-[:AdminTo*1..]->(d:Computer)) RETURN p +-- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.start_id, e1.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path);"} +with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_asp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[], (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n2.id is not null))::int8[], false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p from s1; + +-- case: MATCH (u:Group) WITH u MATCH p=shortestPath((u)-[:AdminTo*1..]->(d:Computer)) RETURN p LIMIT 5 +-- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s3_seed(root_id) as not materialized (select s3_seed_filter.id as root_id from traversal_root_filter s3_seed_filter) select e0.start_id, e0.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e0.end_id), e0.start_id = e0.end_id, array [e0.id] from s3_seed join edge e0 on e0.start_id = s3_seed.root_id where e0.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e0.id) and case when exists (select 1 from s3_seed where s3_seed.root_id = e0.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e0.start_id) = 0 then true else shortest_path_self_endpoint_error(e0.start_id, e0.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s3.root_id, e0.end_id, s3.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e0.end_id), false, s3.path || e0.id from forward_front s3 join edge e0 on e0.start_id = s3.next_id where e0.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s3.depth + 1, e0.id) and e0.id != all (s3.path) and not exists (select 1 from visited where visited.root_id = s3.root_id and visited.id = e0.end_id);"} +with s0 as (with s1 as (select (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0 from node n0 where n0.kind_ids operator (pg_catalog.@>) array [13]::int2[]) select s1.n0 as n0 from s1), s2 as (with s3(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n0).id from s0 where (s0.n0).id is not null))::int8[], (array(select distinct n1.id from node n1 where n1.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n1.id is not null))::int8[], false)) select s3.path as ep0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from s0, s3 join node n0 on n0.id = s3.root_id join node n1 on n1.id = s3.next_id where (s0.n0).id = s3.root_id and case when s3.root_id != s3.next_id then true else shortest_path_self_endpoint_error(s3.root_id, s3.next_id) end limit 5) select case when (s2.n0).id is null or s2.ep0 is null or (s2.n1).id is null then null else ordered_edge_ids_to_path(0, s2.n0, s2.ep0, array [s2.n0, s2.n1]::nodecomposite[])::pathcomposite end as p from s2 limit 5; + +-- case: MATCH (:User)-[:MemberOf]->(u:Group) MATCH p=shortestPath((u)-[:AdminTo*1..]->(d:Computer)) RETURN p +-- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.start_id, e1.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.end_id);"} +with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[], (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n2.id is not null))::int8[], false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p from s1; + -- case: MATCH (g1:Group) MATCH (g2:Group) WHERE g1.name STARTS WITH 'DOMAIN USERS@' AND g2.name STARTS WITH 'DOMAIN ADMINS@' MATCH p=shortestPath((g1)-[:AddAllowedToAct|AddMember|AdminTo|AllExtendedRights|AllowedToDelegate|CanRDP|Contains|ForceChangePassword|GenericAll|GenericWrite|GetChangesAll|GetChanges|HasSession|MemberOf|Owns|ReadLAPSPassword|SQLAdmin|TrustedBy|WriteAccountRestrictions|WriteOwner*1..]->(g2)) WHERE NONE(r IN relationships(p) WHERE type(r) = 'HasSession' AND startNode(r).name = 'DF-WIN10-DEV01.DUMPSTER.FIRE') RETURN p -- pgsql_params:{"__strlit0":"string","__strlit1":"DOMAIN ADMINS@%","__strlit2":"DOMAIN USERS@%","__strlit3":"name","__strlit4":"DF-WIN10-DEV01.DUMPSTER.FIRE","pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s3_seed(root_id) as not materialized (select s3_seed_filter.id as root_id from traversal_root_filter s3_seed_filter) select e0.start_id, e0.end_id, 1, exists (select 1 from traversal_pair_filter where traversal_pair_filter.root_id = e0.start_id and traversal_pair_filter.terminal_id = e0.end_id), e0.start_id = e0.end_id, array [e0.id] from s3_seed join edge e0 on e0.start_id = s3_seed.root_id where e0.kind_id = any (array [14, 15, 16, 17, 18, 19, 12, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 29, 30, 31]::int2[]) and dawgs_admit_traversal_v1(1, e0.id) and case when exists (select 1 from s3_seed where s3_seed.root_id = e0.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e0.start_id) = 0 then true else shortest_path_self_endpoint_error(e0.start_id, e0.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s3.root_id, e0.end_id, s3.depth + 1, exists (select 1 from traversal_pair_filter where traversal_pair_filter.root_id = s3.root_id and traversal_pair_filter.terminal_id = e0.end_id), false, s3.path || e0.id from forward_front s3 join edge e0 on e0.start_id = s3.next_id where e0.kind_id = any (array [14, 15, 16, 17, 18, 19, 12, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 29, 30, 31]::int2[]) and dawgs_admit_traversal_v1(s3.depth + 1, e0.id) and e0.id != all (s3.path) and not exists (select 1 from visited where visited.root_id = s3.root_id and visited.id = e0.end_id);"} with s0 as (select (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0 from node n0 where n0.kind_ids operator (pg_catalog.@>) array [13]::int2[]), s1 as (select s0.n0 as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from s0, node n1 where (((jsonb_typeof((n1.properties -> E'name')) = @__strlit0::text and (n1.properties ->> E'name') like @__strlit1::text) or (not (jsonb_typeof((n1.properties -> E'name')) = @__strlit0::text) and null)) and ((jsonb_typeof(((s0.n0).properties -> E'name')) = @__strlit0::text and ((s0.n0).properties ->> E'name') like @__strlit2::text) or (not (jsonb_typeof(((s0.n0).properties -> E'name')) = @__strlit0::text) and null))) and n1.kind_ids operator (pg_catalog.@>) array [13]::int2[]), s2 as (with s3_pairs(root_id, terminal_id) as (select distinct (s1.n0).id, (s1.n1).id from s1 where (s1.n0).id is not null and (s1.n1).id is not null), s3(root_id, next_id, depth, satisfied, is_cycle, path) as (select unidirectional_sp_harness_v2.* from s3_pairs, unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, array [s3_pairs.root_id]::int8[], array [s3_pairs.terminal_id]::int8[], false)) select s3.path as ep0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from s1, s3 join node n0 on n0.id = s3.root_id join node n1 on n1.id = s3.next_id where (s1.n0).id = s3.root_id and (s1.n1).id = s3.next_id and case when s3.root_id != s3.next_id then true else shortest_path_self_endpoint_error(s3.root_id, s3.next_id) end) select case when (s2.n0).id is null or s2.ep0 is null or (s2.n1).id is null then null else ordered_edge_ids_to_path(0, s2.n0, s2.ep0, array [s2.n0, s2.n1]::nodecomposite[])::pathcomposite end as p from s2 where ((not exists (select 1 from edge i0 where ((jsonb_typeof(((start_node((i0.id, i0.start_id, i0.end_id, i0.kind_id, i0.properties)::edgecomposite)::nodecomposite).properties -> @__strlit3::text)) = @__strlit0::text and ((start_node((i0.id, i0.start_id, i0.end_id, i0.kind_id, i0.properties)::edgecomposite)::nodecomposite).properties ->> @__strlit3::text) = @__strlit4::text) and i0.kind_id = 7) and i0.id = any (s2.ep0)) and s2.ep0 is not null)::bool); diff --git a/integration/testdata/cases/shortest_paths_inline.json b/integration/testdata/cases/shortest_paths_inline.json index ddfe5352..13adb47f 100644 --- a/integration/testdata/cases/shortest_paths_inline.json +++ b/integration/testdata/cases/shortest_paths_inline.json @@ -108,6 +108,27 @@ ] }, "assert": {"ordered_row_values": [["admins", 2], ["staff", 1]]} + }, + { + "name": "shortest path uses endpoint bound by prior match", + "cypher": "MATCH (:NodeKind1)-[:EdgeKind1]->(u:NodeKind2) MATCH p=shortestPath((u)-[:EdgeKind2*1..]->(d:NodeKind3)) RETURN p", + "fixture": { + "nodes": [ + {"id": "a", "kinds": ["NodeKind1"], "properties": {}}, + {"id": "b", "kinds": ["NodeKind2"], "properties": {}}, + {"id": "c", "kinds": ["NodeKind2"], "properties": {}}, + {"id": "d", "kinds": ["NodeKind3"], "properties": {}}, + {"id": "x", "kinds": ["NodeKind1"], "properties": {}}, + {"id": "y", "kinds": ["NodeKind2"], "properties": {}} + ], + "edges": [ + {"start_id": "a", "end_id": "b", "kind": "EdgeKind1"}, + {"start_id": "b", "end_id": "c", "kind": "EdgeKind2"}, + {"start_id": "c", "end_id": "d", "kind": "EdgeKind2"}, + {"start_id": "x", "end_id": "y", "kind": "EdgeKind1"} + ] + }, + "assert": {"row_count": 1, "path_node_ids": [["b", "c", "d"]]} } ] } From 91878bd807c534849ee756474675a3f6764ff894 Mon Sep 17 00:00:00 2001 From: Sean Johnson Date: Tue, 27 Oct 2026 18:30:47 -0500 Subject: [PATCH 3/6] chore: output coverage for integration tests --- Makefile | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 24dcc197..a70136c8 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,8 @@ COVERPKG := $(shell $(GO_CMD) list ./... | grep -v '/cypher/parser$$' | tr '\n' # Metric configuration METRICS_DIR ?= .coverage -COVERAGE_PROFILE ?= $(METRICS_DIR)/unit.out +UNIT_COVERAGE_PROFILE ?= $(METRICS_DIR)/unit.out +INTEGRATION_COVERAGE_PROFILE ?= $(METRICS_DIR)/integration.out COVERAGE_FUNC_REPORT ?= $(METRICS_DIR)/coverage.txt CYCLO_REPORT ?= $(METRICS_DIR)/cyclomatic.txt CRAP_TEXT_REPORT ?= $(METRICS_DIR)/crap.txt @@ -124,15 +125,15 @@ format: # Test targets test: $(METRICS_DIR) @echo "Running tests..." - @$(GO_CMD) test -vet=off -race -covermode=atomic -coverprofile=$(COVERAGE_PROFILE) -coverpkg=$(COVERPKG) -count=1 -parallel=10 $(MAIN_PACKAGES) - @$(GO_CMD) tool cover -func=$(COVERAGE_PROFILE) > $(COVERAGE_FUNC_REPORT) + @$(GO_CMD) test -vet=off -race -covermode=atomic -coverprofile=$(UNIT_COVERAGE_PROFILE) -coverpkg=$(COVERPKG) -count=1 -parallel=10 $(MAIN_PACKAGES) + @$(GO_CMD) tool cover -func=$(UNIT_COVERAGE_PROFILE) > $(COVERAGE_FUNC_REPORT) @echo "Coverage report written to $(COVERAGE_FUNC_REPORT)" test_all: test test_integration test_bdd_integration -test_integration: +test_integration: $(METRICS_DIR) @echo "Running all integration tests..." - @$(GO_CMD) test -vet=off -tags 'manual_integration integration' -race -cover -count=1 -p=1 -parallel=1 $(MAIN_PACKAGES) + @$(GO_CMD) test -vet=off -tags 'manual_integration integration' -race -cover -coverprofile=$(INTEGRATION_COVERAGE_PROFILE) -count=1 -p=1 -parallel=1 $(MAIN_PACKAGES) test_bdd_integration: $(METRICS_DIR) @echo "Running all BDD integration tests..." @$(GO_CMD) test -vet=off -v -tags 'bdd_integration' -count=1 ./bdd @@ -272,29 +273,29 @@ complexity_check: $(METRICS_DIR) crap: test @echo "Calculating CRAP metrics..." - @$(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -text $(CRAP_TEXT_REPORT) -json $(CRAP_JSON_REPORT) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) + @$(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(UNIT_COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -text $(CRAP_TEXT_REPORT) -json $(CRAP_JSON_REPORT) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) @echo "CRAP and quality reports written to $(CRAP_TEXT_REPORT), $(CRAP_JSON_REPORT), $(QUALITY_TEXT_REPORT), $(QUALITY_JSON_REPORT), and $(METRICS_HTML_REPORT)" crap_check: test @echo "Checking CRAP metrics..." @if [ "$(METRICS_ENFORCE)" = "1" ]; then \ - $(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -text $(CRAP_TEXT_REPORT) -json $(CRAP_JSON_REPORT) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) -fail-over $(CRAP_OVER) -fail-quality; \ + $(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(UNIT_COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -text $(CRAP_TEXT_REPORT) -json $(CRAP_JSON_REPORT) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) -fail-over $(CRAP_OVER) -fail-quality; \ else \ - $(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -text $(CRAP_TEXT_REPORT) -json $(CRAP_JSON_REPORT) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT); \ + $(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(UNIT_COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -text $(CRAP_TEXT_REPORT) -json $(CRAP_JSON_REPORT) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT); \ echo "METRICS_ENFORCE=0; CRAP threshold $(CRAP_OVER) is report-only."; \ fi quality: test @echo "Calculating quality metrics..." - @$(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) -stdout=false + @$(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(UNIT_COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) -stdout=false @echo "Quality reports written to $(QUALITY_TEXT_REPORT), $(QUALITY_JSON_REPORT), and $(METRICS_HTML_REPORT)" quality_check: test @echo "Checking quality metrics..." @if [ "$(METRICS_ENFORCE)" = "1" ]; then \ - $(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) -stdout=false -fail-quality; \ + $(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(UNIT_COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) -stdout=false -fail-quality; \ else \ - $(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) -stdout=false; \ + $(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(UNIT_COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) $(QUALITY_INPUTS) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) -stdout=false; \ echo "METRICS_ENFORCE=0; quality watch signals are report-only."; \ fi @@ -310,7 +311,7 @@ quality_backend: test CONNECTION_STRING="$(NEO4J_CONNECTION_STRING)" $(GO_CMD) test -vet=off -json -tags 'manual_integration integration' -race -cover -count=1 -p=1 -parallel=1 $(MAIN_PACKAGES) > $(BACKEND_NEO4J_REPORT); \ neo4j_status=$$?; \ set -e; \ - $(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) -backend-result pg=$(BACKEND_PG_REPORT) -backend-result neo4j=$(BACKEND_NEO4J_REPORT) $(QUALITY_INPUTS) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) -stdout=false; \ + $(GO_CMD) tool dawgs-metrics -source-root . -coverprofile $(UNIT_COVERAGE_PROFILE) -ignore '$(METRICS_IGNORE)' -top $(CRAP_TOP) -over $(CRAP_OVER) -cyclo-over $(CYCLO_OVER) -backend-result pg=$(BACKEND_PG_REPORT) -backend-result neo4j=$(BACKEND_NEO4J_REPORT) $(QUALITY_INPUTS) -quality-text $(QUALITY_TEXT_REPORT) -quality-json $(QUALITY_JSON_REPORT) -html $(METRICS_HTML_REPORT) -stdout=false; \ if [ $$pg_status -ne 0 ]; then exit $$pg_status; fi; \ if [ $$neo4j_status -ne 0 ]; then exit $$neo4j_status; fi From 2fb7da97d95b6a3bcc0076dd3ea1efb0eaca45cc Mon Sep 17 00:00:00 2001 From: Sean Johnson Date: Wed, 28 Oct 2026 17:02:24 -0500 Subject: [PATCH 4/6] fix(pg): don't exit from allShortestPaths after first satisfied root --- .../test/translation_cases/shortest_paths.sql | 24 +-- cypher/models/pgsql/translate/expansion.go | 28 ++- .../translate/shortest_workspace_test.go | 24 +++ .../pg/query/asp_harness_integration_test.go | 100 +++++++++ drivers/pg/query/sql/schema_up.sql | 10 +- integration/testdata/README.md | 10 + .../all_shortest_path_pair_resolution.json | 194 ++++++++++++++++++ 7 files changed, 373 insertions(+), 17 deletions(-) create mode 100644 drivers/pg/query/asp_harness_integration_test.go create mode 100644 integration/testdata/templates/all_shortest_path_pair_resolution.json diff --git a/cypher/models/pgsql/test/translation_cases/shortest_paths.sql b/cypher/models/pgsql/test/translation_cases/shortest_paths.sql index 562301b8..7824c402 100644 --- a/cypher/models/pgsql/test/translation_cases/shortest_paths.sql +++ b/cypher/models/pgsql/test/translation_cases/shortest_paths.sql @@ -63,8 +63,8 @@ with s0 as (with s1(root_id, next_id, depth, satisfied, is_cycle, path) as (sele with s0 as (with s1(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, false)) select s1.path as ep0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from s1 join node n1 on n1.id = s1.root_id join node n0 on n0.id = s1.next_id) select case when (s0.n0).id is null or s0.ep0 is null or (s0.n1).id is null then null else ordered_edge_ids_to_path(0, s0.n0, s0.ep0, array [s0.n0, s0.n1]::nodecomposite[])::pathcomposite end as p from s0 where ((s0.n0).id <> (s0.n1).id); -- case: match p=(c:NodeKind1)-[]->(u:NodeKind2) match p2=shortestPath((u:NodeKind2)-[*1..]->(d:NodeKind1)) return p, p2 limit 500 --- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select distinct n1.id as root_id from traversal_root_filter s2_seed_filter join node n1 on n1.id = s2_seed_filter.id where n1.kind_ids operator (pg_catalog.@\u003e) array [2]::int2[]) select e1.start_id, e1.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.end_id);"} -with s0 as (select e0.id as e0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [1]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [2]::int2[] and n1.id = e0.end_id), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[], (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [1]::int2[] and n2.id is not null))::int8[], false)) select s0.e0 as e0, s2.path as ep0, s0.n0 as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n0).id is null or s1.e0 is null or (s1.n1).id is null then null else ordered_edge_ids_to_path(0, s1.n0, array [s1.e0]::int8[], array [s1.n0, s1.n1]::nodecomposite[])::pathcomposite end as p, case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p2 from s1 limit 500; +-- pgsql_params:{"__strlit0":"insert into traversal_root_filter (id) select unnest(%L::int8[])","__strlit1":"insert into traversal_terminal_filter (id) select unnest(%L::int8[])","pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select distinct n1.id as root_id from traversal_root_filter s2_seed_filter join node n1 on n1.id = s2_seed_filter.id where n1.kind_ids operator (pg_catalog.@\u003e) array [2]::int2[]) select e1.start_id, e1.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.end_id);"} +with s0 as (select e0.id as e0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [1]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [2]::int2[] and n1.id = e0.end_id), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, format(@__strlit0::text, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[])::text, format(@__strlit1::text, (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [1]::int2[] and n2.id is not null))::int8[])::text, false)) select s0.e0 as e0, s2.path as ep0, s0.n0 as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n0).id is null or s1.e0 is null or (s1.n1).id is null then null else ordered_edge_ids_to_path(0, s1.n0, array [s1.e0]::int8[], array [s1.n0, s1.n1]::nodecomposite[])::pathcomposite end as p, case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p2 from s1 limit 500; -- case: match p = allShortestPaths((a)-[:EdgeKind1*..]->()) return p -- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select e0.start_id, e0.end_id, 1, exists (select 1 from edge where end_id = e0.start_id), e0.start_id = e0.end_id, array [e0.id] from edge e0 where e0.kind_id = any (array [3]::int2[]) and dawgs_admit_traversal_v1(1, e0.id) and case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e0.start_id) = 0 then true else shortest_path_self_endpoint_error(e0.start_id, e0.start_id) end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s1.root_id, e0.end_id, s1.depth + 1, exists (select 1 from edge where end_id = e0.start_id), false, s1.path || e0.id from forward_front s1 join edge e0 on e0.start_id = s1.next_id where e0.kind_id = any (array [3]::int2[]) and dawgs_admit_traversal_v1(s1.depth + 1, e0.id) and e0.id != all (s1.path);"} @@ -91,24 +91,24 @@ with s0 as (with s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, pa with s0 as (with s1(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (@__strlit0::text)::text, (@__strlit1::text)::text, false)) select s1.path as ep0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from s1 join node n0 on n0.id = s1.root_id join node n1 on n1.id = s1.next_id where case when s1.root_id != s1.next_id then true else shortest_path_self_endpoint_error(s1.root_id, s1.next_id) end) select case when (s0.n0).id is null or s0.ep0 is null or (s0.n1).id is null then null else ordered_edge_ids_to_path(0, s0.n0, s0.ep0, array [s0.n0, s0.n1]::nodecomposite[])::pathcomposite end as p from s0; -- case: MATCH (:User)-[:MemberOf]->(u:Group) MATCH p=shortestPath((u)-[:AdminTo*1..]->(d)) RETURN p --- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.start_id, e1.end_id, 1, exists (select 1 from edge where end_id = e1.start_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from edge where end_id = e1.start_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.end_id);"} -with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[], array []::int8[], false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p from s1; +-- pgsql_params:{"__strlit0":"insert into traversal_root_filter (id) select unnest(%L::int8[])","__strlit1":"","pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.start_id, e1.end_id, 1, exists (select 1 from edge where end_id = e1.start_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from edge where end_id = e1.start_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.end_id);"} +with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, format(@__strlit0::text, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[])::text, (@__strlit1::text)::text, false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p from s1; -- case: MATCH (:User)-[:MemberOf]->(d:Group) MATCH p=shortestPath((u:Computer)-[:AdminTo*1..]->(d)) RETURN p --- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.end_id, e1.start_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.end_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.end_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id) = 0 then true else shortest_path_self_endpoint_error(e1.end_id, e1.end_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.start_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id), false, e1.id || s2.path from forward_front s2 join edge e1 on e1.end_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.start_id);"} -with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[], (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n2.id is not null))::int8[], false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n2).id is null or s1.ep0 is null or (s1.n1).id is null then null else ordered_edge_ids_to_path(0, s1.n2, s1.ep0, array [s1.n2, s1.n1]::nodecomposite[])::pathcomposite end as p from s1; +-- pgsql_params:{"__strlit0":"insert into traversal_root_filter (id) select unnest(%L::int8[])","__strlit1":"insert into traversal_terminal_filter (id) select unnest(%L::int8[])","pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.end_id, e1.start_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.end_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.end_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id) = 0 then true else shortest_path_self_endpoint_error(e1.end_id, e1.end_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.start_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id), false, e1.id || s2.path from forward_front s2 join edge e1 on e1.end_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.start_id);"} +with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, format(@__strlit0::text, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[])::text, format(@__strlit1::text, (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n2.id is not null))::int8[])::text, false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n2).id is null or s1.ep0 is null or (s1.n1).id is null then null else ordered_edge_ids_to_path(0, s1.n2, s1.ep0, array [s1.n2, s1.n1]::nodecomposite[])::pathcomposite end as p from s1; -- case: MATCH (:User)-[:MemberOf]->(u:Group) MATCH p=allShortestPaths((u)-[:AdminTo*1..]->(d:Computer)) RETURN p --- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.start_id, e1.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path);"} -with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_asp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[], (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n2.id is not null))::int8[], false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p from s1; +-- pgsql_params:{"__strlit0":"insert into traversal_root_filter (id) select unnest(%L::int8[])","__strlit1":"insert into traversal_terminal_filter (id) select unnest(%L::int8[])","pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.start_id, e1.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path);"} +with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_asp_harness_v2(@pi0::text, @pi1::text, 0, format(@__strlit0::text, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[])::text, format(@__strlit1::text, (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n2.id is not null))::int8[])::text, false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p from s1; -- case: MATCH (u:Group) WITH u MATCH p=shortestPath((u)-[:AdminTo*1..]->(d:Computer)) RETURN p LIMIT 5 --- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s3_seed(root_id) as not materialized (select s3_seed_filter.id as root_id from traversal_root_filter s3_seed_filter) select e0.start_id, e0.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e0.end_id), e0.start_id = e0.end_id, array [e0.id] from s3_seed join edge e0 on e0.start_id = s3_seed.root_id where e0.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e0.id) and case when exists (select 1 from s3_seed where s3_seed.root_id = e0.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e0.start_id) = 0 then true else shortest_path_self_endpoint_error(e0.start_id, e0.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s3.root_id, e0.end_id, s3.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e0.end_id), false, s3.path || e0.id from forward_front s3 join edge e0 on e0.start_id = s3.next_id where e0.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s3.depth + 1, e0.id) and e0.id != all (s3.path) and not exists (select 1 from visited where visited.root_id = s3.root_id and visited.id = e0.end_id);"} -with s0 as (with s1 as (select (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0 from node n0 where n0.kind_ids operator (pg_catalog.@>) array [13]::int2[]) select s1.n0 as n0 from s1), s2 as (with s3(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n0).id from s0 where (s0.n0).id is not null))::int8[], (array(select distinct n1.id from node n1 where n1.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n1.id is not null))::int8[], false)) select s3.path as ep0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from s0, s3 join node n0 on n0.id = s3.root_id join node n1 on n1.id = s3.next_id where (s0.n0).id = s3.root_id and case when s3.root_id != s3.next_id then true else shortest_path_self_endpoint_error(s3.root_id, s3.next_id) end limit 5) select case when (s2.n0).id is null or s2.ep0 is null or (s2.n1).id is null then null else ordered_edge_ids_to_path(0, s2.n0, s2.ep0, array [s2.n0, s2.n1]::nodecomposite[])::pathcomposite end as p from s2 limit 5; +-- pgsql_params:{"__strlit0":"insert into traversal_root_filter (id) select unnest(%L::int8[])","__strlit1":"insert into traversal_terminal_filter (id) select unnest(%L::int8[])","pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s3_seed(root_id) as not materialized (select s3_seed_filter.id as root_id from traversal_root_filter s3_seed_filter) select e0.start_id, e0.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e0.end_id), e0.start_id = e0.end_id, array [e0.id] from s3_seed join edge e0 on e0.start_id = s3_seed.root_id where e0.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e0.id) and case when exists (select 1 from s3_seed where s3_seed.root_id = e0.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e0.start_id) = 0 then true else shortest_path_self_endpoint_error(e0.start_id, e0.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s3.root_id, e0.end_id, s3.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e0.end_id), false, s3.path || e0.id from forward_front s3 join edge e0 on e0.start_id = s3.next_id where e0.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s3.depth + 1, e0.id) and e0.id != all (s3.path) and not exists (select 1 from visited where visited.root_id = s3.root_id and visited.id = e0.end_id);"} +with s0 as (with s1 as (select (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0 from node n0 where n0.kind_ids operator (pg_catalog.@>) array [13]::int2[]) select s1.n0 as n0 from s1), s2 as (with s3(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, format(@__strlit0::text, (array(select distinct (s0.n0).id from s0 where (s0.n0).id is not null))::int8[])::text, format(@__strlit1::text, (array(select distinct n1.id from node n1 where n1.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n1.id is not null))::int8[])::text, false)) select s3.path as ep0, (n0.id, n0.kind_ids, n0.properties)::nodecomposite as n0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from s0, s3 join node n0 on n0.id = s3.root_id join node n1 on n1.id = s3.next_id where (s0.n0).id = s3.root_id and case when s3.root_id != s3.next_id then true else shortest_path_self_endpoint_error(s3.root_id, s3.next_id) end limit 5) select case when (s2.n0).id is null or s2.ep0 is null or (s2.n1).id is null then null else ordered_edge_ids_to_path(0, s2.n0, s2.ep0, array [s2.n0, s2.n1]::nodecomposite[])::pathcomposite end as p from s2 limit 5; -- case: MATCH (:User)-[:MemberOf]->(u:Group) MATCH p=shortestPath((u)-[:AdminTo*1..]->(d:Computer)) RETURN p --- pgsql_params:{"pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.start_id, e1.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.end_id);"} -with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[], (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n2.id is not null))::int8[], false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p from s1; +-- pgsql_params:{"__strlit0":"insert into traversal_root_filter (id) select unnest(%L::int8[])","__strlit1":"insert into traversal_terminal_filter (id) select unnest(%L::int8[])","pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s2_seed(root_id) as not materialized (select s2_seed_filter.id as root_id from traversal_root_filter s2_seed_filter) select e1.start_id, e1.end_id, 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), e1.start_id = e1.end_id, array [e1.id] from s2_seed join edge e1 on e1.start_id = s2_seed.root_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(1, e1.id) and case when exists (select 1 from s2_seed where s2_seed.root_id = e1.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e1.start_id) = 0 then true else shortest_path_self_endpoint_error(e1.start_id, e1.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s2.root_id, e1.end_id, s2.depth + 1, exists (select 1 from traversal_terminal_filter where traversal_terminal_filter.id = e1.end_id), false, s2.path || e1.id from forward_front s2 join edge e1 on e1.start_id = s2.next_id where e1.kind_id = any (array [16]::int2[]) and dawgs_admit_traversal_v1(s2.depth + 1, e1.id) and e1.id != all (s2.path) and not exists (select 1 from visited where visited.root_id = s2.root_id and visited.id = e1.end_id);"} +with s0 as (select (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1 from edge e0 join node n0 on n0.kind_ids operator (pg_catalog.@>) array [6]::int2[] and n0.id = e0.start_id join node n1 on n1.kind_ids operator (pg_catalog.@>) array [13]::int2[] and n1.id = e0.end_id where e0.kind_id = any (array [25]::int2[])), s1 as (with s2(root_id, next_id, depth, satisfied, is_cycle, path) as (select * from unidirectional_sp_harness_v2(@pi0::text, @pi1::text, 0, format(@__strlit0::text, (array(select distinct (s0.n1).id from s0 where (s0.n1).id is not null))::int8[])::text, format(@__strlit1::text, (array(select distinct n2.id from node n2 where n2.kind_ids operator (pg_catalog.@>) array [5]::int2[] and n2.id is not null))::int8[])::text, false)) select s2.path as ep0, (n1.id, n1.kind_ids, n1.properties)::nodecomposite as n1, (n2.id, n2.kind_ids, n2.properties)::nodecomposite as n2 from s0, s2 join node n1 on n1.id = s2.root_id join node n2 on n2.id = s2.next_id where (s0.n1).id = s2.root_id and case when s2.root_id != s2.next_id then true else shortest_path_self_endpoint_error(s2.root_id, s2.next_id) end) select case when (s1.n1).id is null or s1.ep0 is null or (s1.n2).id is null then null else ordered_edge_ids_to_path(0, s1.n1, s1.ep0, array [s1.n1, s1.n2]::nodecomposite[])::pathcomposite end as p from s1; -- case: MATCH (g1:Group) MATCH (g2:Group) WHERE g1.name STARTS WITH 'DOMAIN USERS@' AND g2.name STARTS WITH 'DOMAIN ADMINS@' MATCH p=shortestPath((g1)-[:AddAllowedToAct|AddMember|AdminTo|AllExtendedRights|AllowedToDelegate|CanRDP|Contains|ForceChangePassword|GenericAll|GenericWrite|GetChangesAll|GetChanges|HasSession|MemberOf|Owns|ReadLAPSPassword|SQLAdmin|TrustedBy|WriteAccountRestrictions|WriteOwner*1..]->(g2)) WHERE NONE(r IN relationships(p) WHERE type(r) = 'HasSession' AND startNode(r).name = 'DF-WIN10-DEV01.DUMPSTER.FIRE') RETURN p -- pgsql_params:{"__strlit0":"string","__strlit1":"DOMAIN ADMINS@%","__strlit2":"DOMAIN USERS@%","__strlit3":"name","__strlit4":"DF-WIN10-DEV01.DUMPSTER.FIRE","pi0":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) with s3_seed(root_id) as not materialized (select s3_seed_filter.id as root_id from traversal_root_filter s3_seed_filter) select e0.start_id, e0.end_id, 1, exists (select 1 from traversal_pair_filter where traversal_pair_filter.root_id = e0.start_id and traversal_pair_filter.terminal_id = e0.end_id), e0.start_id = e0.end_id, array [e0.id] from s3_seed join edge e0 on e0.start_id = s3_seed.root_id where e0.kind_id = any (array [14, 15, 16, 17, 18, 19, 12, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 29, 30, 31]::int2[]) and dawgs_admit_traversal_v1(1, e0.id) and case when exists (select 1 from s3_seed where s3_seed.root_id = e0.start_id) then case when (select count(*)::int8 from traversal_terminal_filter where traversal_terminal_filter.id = e0.start_id) = 0 then true else shortest_path_self_endpoint_error(e0.start_id, e0.start_id) end else true end;","pi1":"insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) select s3.root_id, e0.end_id, s3.depth + 1, exists (select 1 from traversal_pair_filter where traversal_pair_filter.root_id = s3.root_id and traversal_pair_filter.terminal_id = e0.end_id), false, s3.path || e0.id from forward_front s3 join edge e0 on e0.start_id = s3.next_id where e0.kind_id = any (array [14, 15, 16, 17, 18, 19, 12, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 29, 30, 31]::int2[]) and dawgs_admit_traversal_v1(s3.depth + 1, e0.id) and e0.id != all (s3.path) and not exists (select 1 from visited where visited.root_id = s3.root_id and visited.id = e0.end_id);"} diff --git a/cypher/models/pgsql/translate/expansion.go b/cypher/models/pgsql/translate/expansion.go index 12c39132..01c0975f 100644 --- a/cypher/models/pgsql/translate/expansion.go +++ b/cypher/models/pgsql/translate/expansion.go @@ -3287,9 +3287,18 @@ func (s *ExpansionBuilder) boundEndpointFilterParameters() ([]pgsql.Expression, // Dynamic filter SQL is executed inside PL/pgSQL and cannot see an outer // translation frame. Materialize a single correlated endpoint in the outer - // query and use the existing array overload instead. Both-bound endpoints + // query before passing its IDs to the harness. Both-bound endpoints // must retain their pair filter because independent arrays lose pair semantics. if !hasPairFilter && s.usesBoundRootIDs() != s.usesBoundTerminalIDs() { + if !s.traversalStep.Expansion.Options.MaxDepth.Set { + // Open array overloads represent one endpoint pair. Render set + // filters in the outer query so the open harness can load all IDs + // without referencing the preceding translation frame itself. + return []pgsql.Expression{ + endpointIDsFilterParameter(rootFilterStatement, hasRootFilter), + endpointIDsFilterParameter(terminalFilterStatement, hasTerminalFilter), + }, nil + } return []pgsql.Expression{ endpointIDsArrayParameter(rootFilterStatement, hasRootFilter), endpointIDsArrayParameter(terminalFilterStatement, hasTerminalFilter), @@ -3338,6 +3347,23 @@ func (s *ExpansionBuilder) boundEndpointFilterParameters() ([]pgsql.Expression, return filterParameters, nil } +// endpointIDsFilterParameter quotes endpoint IDs into filter SQL at the caller's +// scope, where queries against a preceding translation frame remain visible. +func endpointIDsFilterParameter(filterStatement pgsql.Insert, hasFilter bool) pgsql.Expression { + if !hasFilter { + return pgsql.NewTypeCast(pgsql.NewLiteral("", pgsql.Text), pgsql.Text) + } + + return pgsql.FunctionCall{ + Function: pgsql.Identifier("format"), + Parameters: []pgsql.Expression{ + pgsql.NewLiteral("insert into "+filterStatement.Table.Name.String()+" (id) select unnest(%L::int8[])", pgsql.Text), + endpointIDsArrayParameter(filterStatement, true), + }, + CastType: pgsql.Text, + } +} + func endpointIDsArrayParameter(filterStatement pgsql.Insert, hasFilter bool) pgsql.Expression { if !hasFilter { return pgsql.ArrayLiteral{CastType: pgsql.Int8Array} diff --git a/cypher/models/pgsql/translate/shortest_workspace_test.go b/cypher/models/pgsql/translate/shortest_workspace_test.go index ce75b278..6e365801 100644 --- a/cypher/models/pgsql/translate/shortest_workspace_test.go +++ b/cypher/models/pgsql/translate/shortest_workspace_test.go @@ -49,6 +49,30 @@ func TestSelfEndpointErrorRequiresAnEligibleSeedRoot(t *testing.T) { require.Contains(t, formatted.Statement, "case when exists (select 1 from s1_seed where s1_seed.root_id = e0.start_id) then case") } +func TestBoundedShortestPathKeepsSingleBoundEndpointSets(t *testing.T) { + for _, mode := range []OptimizerMode{OptimizerEnabled, OptimizerDisabled} { + for _, source := range []string{ + "MATCH (:User)-[:MemberOf]->(u:Group) MATCH p=shortestPath((u)-[:AdminTo*1..4]->(d)) RETURN p", + "MATCH (:User)-[:MemberOf]->(d:Group) MATCH p=shortestPath((u:Computer)-[:AdminTo*1..4]->(d)) RETURN p", + } { + t.Run(fmt.Sprintf("%s/%s", mode, source), func(t *testing.T) { + query, err := frontend.ParseCypher(frontend.NewContext(), source) + require.NoError(t, err) + translation, err := TranslateWithOptions(context.Background(), query, optimizerSafetyKindMapper(), nil, DefaultGraphID, Options{OptimizerMode: mode}) + require.NoError(t, err) + formatted, err := Translated(translation) + require.NoError(t, err) + // The bounded harness accepts whole endpoint sets, including an + // unconstrained opposite endpoint. Materialize IDs in the caller. + require.Contains(t, formatted.Statement, "(array(select distinct (s0.") + require.Contains(t, formatted.Statement, ")::int8[]") + require.NotContains(t, formatted.Statement, "format(") + require.NotContains(t, formatted.Statement, "_harness_v2(") + }) + } + } +} + func TestSingletonShortestPathFragmentsUseCurrentEndpointArrays(t *testing.T) { for _, mode := range []OptimizerMode{OptimizerEnabled, OptimizerDisabled} { for _, bound := range []int{65, 128} { diff --git a/drivers/pg/query/asp_harness_integration_test.go b/drivers/pg/query/asp_harness_integration_test.go new file mode 100644 index 00000000..5e94db2a --- /dev/null +++ b/drivers/pg/query/asp_harness_integration_test.go @@ -0,0 +1,100 @@ +// Copyright 2026 Specter Ops, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//go:build manual_integration && integration + +package query + +import ( + "os" + "testing" + + "github.com/jackc/pgx/v5" + "github.com/stretchr/testify/require" +) + +// TestUnidirectionalASPResolvesPairsIndependently protects both overloads from +// stopping at the first satisfied root or retiring a root before its other +// terminals are reached. Equal-depth witnesses survive; longer paths do not. +func TestUnidirectionalASPResolvesPairsIndependently(t *testing.T) { + connection := os.Getenv("CONNECTION_STRING") + if !isPostgreSQLConnection(connection) { + t.Skip("CONNECTION_STRING does not select PostgreSQL") + } + + ctx := t.Context() + conn, err := pgx.Connect(ctx, connection) + require.NoError(t, err) + t.Cleanup(func() { _ = conn.Close(ctx) }) + _, err = conn.Exec(ctx, sqlSchemaUp) + require.NoError(t, err) + + tx, err := conn.Begin(ctx) + require.NoError(t, err) + defer func() { _ = tx.Rollback(ctx) }() + _, err = tx.Exec(ctx, ` + create temporary table edge (id int8, start_id int8, end_id int8) on commit drop; + insert into edge values + (101, 1, 2), (102, 1, 2), (103, 1, 10), + (104, 10, 2), (105, 10, 4), + (106, 3, 30), (107, 30, 4), + (108, 3, 40), (109, 40, 2), + (110, 5, 50), (111, 10, 11), (112, 11, 4); + `) + require.NoError(t, err) + + const primer = `insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) + select e.start_id, e.end_id, 1, e.end_id in (2, 4), false, array[e.id] + from edge e join traversal_root_filter r on r.id = e.start_id` + const recursive = `insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) + select f.root_id, e.end_id, f.depth + 1, e.end_id in (2, 4), false, f.path || e.id + from forward_front f join edge e on e.start_id = f.next_id` + + for _, testCase := range []struct { + name string + filters []any + }{ + {name: "array filters", filters: []any{[]int64{1, 3, 5}, []int64{2, 4}}}, + {name: "array open terminals", filters: []any{[]int64{1, 3, 5}, []int64{}}}, + {name: "text filters", filters: []any{ + "insert into traversal_root_filter values (1), (3), (5)", + "insert into traversal_terminal_filter values (2), (4)", + }}, + {name: "text open terminals", filters: []any{ + "insert into traversal_root_filter values (1), (3), (5)", "", + }}, + } { + t.Run(testCase.name, func(t *testing.T) { + filterType := "text" + if _, ok := testCase.filters[0].([]int64); ok { + filterType = "int8[]" + } + query := `select root_id, next_id, depth, path + from public.unidirectional_asp_harness($1::text, $2::text, 4, $3::` + filterType + `, $4::` + filterType + `) + order by root_id, next_id, path` + + // Reuse the same physical session so resolved pairs from a previous + // invocation cannot suppress a later invocation's results. + for range 2 { + args := append([]any{primer, recursive}, testCase.filters...) + rows, err := tx.Query(ctx, query, args...) + require.NoError(t, err) + type pathResult struct { + RootID int64 + NextID int64 + Depth int32 + Path []int64 + } + results, err := pgx.CollectRows(rows, pgx.RowToStructByPos[pathResult]) + require.NoError(t, err) + require.Equal(t, []pathResult{ + {1, 2, 1, []int64{101}}, + {1, 2, 1, []int64{102}}, + {1, 4, 2, []int64{103, 105}}, + {3, 2, 2, []int64{108, 109}}, + {3, 4, 2, []int64{106, 107}}, + }, results) + } + }) + } +} diff --git a/drivers/pg/query/sql/schema_up.sql b/drivers/pg/query/sql/schema_up.sql index b157bad8..9a997bc1 100644 --- a/drivers/pg/query/sql/schema_up.sql +++ b/drivers/pg/query/sql/schema_up.sql @@ -5919,14 +5919,15 @@ begin -- Check to see if the root front is satisfied if exists(select 1 from next_front r where r.satisfied) then - -- Return all satisfied paths from the next front + -- Return every shortest witness at this depth before recording the + -- resolved pairs. Other terminals and roots must keep expanding. return query select r.* from next_front r where r.satisfied and not exists (select 1 from dawgs_asp_resolved_v2 p where p.root_id = r.root_id and p.terminal_id = r.next_id); insert into dawgs_asp_resolved_v2 select distinct r.root_id, r.next_id from next_front r where r.satisfied on conflict do nothing; end if; -- A root is complete only after every requested terminal has been - -- resolved and all witnesses in this layer have been returned. + -- resolved and all witnesses in this layer have been returned. if terminal_filter_count > 0 then delete from next_front f using ( select p.root_id from dawgs_asp_resolved_v2 p @@ -5987,14 +5988,15 @@ begin -- Check to see if the root front is satisfied if exists(select 1 from next_front r where r.satisfied) then - -- Return all satisfied paths from the next front + -- Return every shortest witness at this depth before recording the + -- resolved pairs. Other terminals and roots must keep expanding. return query select r.* from next_front r where r.satisfied and not exists (select 1 from dawgs_asp_resolved_v2 p where p.root_id = r.root_id and p.terminal_id = r.next_id); insert into dawgs_asp_resolved_v2 select distinct r.root_id, r.next_id from next_front r where r.satisfied on conflict do nothing; end if; -- A root is complete only after every requested terminal has been - -- resolved and all witnesses in this layer have been returned. + -- resolved and all witnesses in this layer have been returned. if terminal_filter_count > 0 then delete from next_front f using ( select p.root_id from dawgs_asp_resolved_v2 p diff --git a/integration/testdata/README.md b/integration/testdata/README.md index f8d7b91a..842f8b99 100644 --- a/integration/testdata/README.md +++ b/integration/testdata/README.md @@ -522,3 +522,13 @@ malformed SQL fragments that must not return or stop at unrelated endpoints. Property-filtered open shortest searches additionally check that self-endpoint errors apply only to eligible roots, including terminals with outgoing edges, wrong-direction empty results, inbound searches and exact mutation targets. + +`all_shortest_path_pair_resolution.json` checks roots and terminals reached at +different depths, relationship-distinct equal-length paths, longer alternatives +to already resolved pairs, and unreachable endpoints. Label-filtered and +prior-MATCH-bound roots share the same expectations on both backends. Mutations +with and without RETURN verify the complete node state, including untouched +unreachable targets. PostgreSQL driver-scoped tests exercise both unidirectional +harness overloads and repeated calls on the same physical session. Open-ended +shortestPath and allShortestPaths variants preserve prior-MATCH endpoint sets +in reads and mutations, including multiple terminals. diff --git a/integration/testdata/templates/all_shortest_path_pair_resolution.json b/integration/testdata/templates/all_shortest_path_pair_resolution.json new file mode 100644 index 00000000..2344d048 --- /dev/null +++ b/integration/testdata/templates/all_shortest_path_pair_resolution.json @@ -0,0 +1,194 @@ +{ + "families": [ + { + "name": "resolve roots and terminals independently", + "template": "{{prefix}}MATCH p={{function}}((s:ASPResolutionRoot)-[:ASPResolutionStep|ASPResolutionAlternate*{{bounds}}]->(e:ASPResolutionTarget)) {{suffix}}", + "fixture": { + "nodes": [ + {"id": "entry", "kinds": ["ASPResolutionEntry"], "properties": {}}, + {"id": "r1", "kinds": ["ASPResolutionRoot"], "properties": {}}, + {"id": "r2", "kinds": ["ASPResolutionRoot"], "properties": {}}, + {"id": "r3", "kinds": ["ASPResolutionRoot"], "properties": {}}, + {"id": "mid", "kinds": ["ASPResolutionMiddle"], "properties": {}}, + {"id": "near", "kinds": ["ASPResolutionTarget"], "properties": {}}, + {"id": "far", "kinds": ["ASPResolutionTarget"], "properties": {}}, + {"id": "unreachable", "kinds": ["ASPResolutionTarget"], "properties": {}} + ], + "edges": [ + {"start_id": "entry", "end_id": "r1", "kind": "ASPResolutionBind"}, + {"start_id": "entry", "end_id": "r2", "kind": "ASPResolutionBind"}, + {"start_id": "entry", "end_id": "r3", "kind": "ASPResolutionBind"}, + {"start_id": "r1", "end_id": "near", "kind": "ASPResolutionStep"}, + {"start_id": "r1", "end_id": "near", "kind": "ASPResolutionAlternate"}, + {"start_id": "r1", "end_id": "mid", "kind": "ASPResolutionStep"}, + {"start_id": "r2", "end_id": "mid", "kind": "ASPResolutionStep"}, + {"start_id": "mid", "end_id": "near", "kind": "ASPResolutionStep"}, + {"start_id": "mid", "end_id": "far", "kind": "ASPResolutionStep"} + ] + }, + "variants": [ + { + "name": "label filters preserve every shortest pair", + "vars": {"prefix": "", "function": "allShortestPaths", "bounds": "1..4", "suffix": "RETURN p"}, + "assert": { + "row_count": 5, + "path_node_ids": [["r1", "near"], ["r1", "near"], ["r1", "mid", "far"], ["r2", "mid", "near"], ["r2", "mid", "far"]], + "path_lengths": [1, 1, 2, 2, 2] + } + }, + { + "name": "prior match roots preserve every shortest pair", + "vars": { + "prefix": "MATCH (:ASPResolutionEntry)-[:ASPResolutionBind]->(s:ASPResolutionRoot) ", + "function": "allShortestPaths", + "bounds": "1..4", + "suffix": "RETURN p" + }, + "assert": { + "row_count": 5, + "path_node_ids": [["r1", "near"], ["r1", "near"], ["r1", "mid", "far"], ["r2", "mid", "near"], ["r2", "mid", "far"]], + "path_lengths": [1, 1, 2, 2, 2] + } + }, + { + "name": "mutation returns all shortest paths", + "vars": { + "prefix": "MATCH (:ASPResolutionEntry)-[:ASPResolutionBind]->(s:ASPResolutionRoot) ", + "function": "allShortestPaths", + "bounds": "1..4", + "suffix": "SET e.selected=true RETURN p" + }, + "assert": { + "row_count": 5, + "path_node_ids": [["r1", "near"], ["r1", "near"], ["r1", "mid", "far"], ["r2", "mid", "near"], ["r2", "mid", "far"]] + }, + "post_assertions": [ + { + "cypher": "MATCH (n) RETURN n", + "assert": { + "node_records": [ + {"id": "entry", "kinds": ["ASPResolutionEntry"], "props": {}}, + {"id": "r1", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "r2", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "r3", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "mid", "kinds": ["ASPResolutionMiddle"], "props": {}}, + {"id": "near", "kinds": ["ASPResolutionTarget"], "props": {"selected": true}}, + {"id": "far", "kinds": ["ASPResolutionTarget"], "props": {"selected": true}}, + {"id": "unreachable", "kinds": ["ASPResolutionTarget"], "props": {}} + ] + } + } + ] + }, + { + "name": "mutation without return updates every reachable terminal", + "vars": {"prefix": "", "function": "allShortestPaths", "bounds": "1..4", "suffix": "SET e.selected=true"}, + "assert": "no_error", + "post_assertions": [ + { + "cypher": "MATCH (n) RETURN n", + "assert": { + "node_records": [ + {"id": "entry", "kinds": ["ASPResolutionEntry"], "props": {}}, + {"id": "r1", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "r2", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "r3", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "mid", "kinds": ["ASPResolutionMiddle"], "props": {}}, + {"id": "near", "kinds": ["ASPResolutionTarget"], "props": {"selected": true}}, + {"id": "far", "kinds": ["ASPResolutionTarget"], "props": {"selected": true}}, + {"id": "unreachable", "kinds": ["ASPResolutionTarget"], "props": {}} + ] + } + } + ] + }, + { + "name": "open search preserves all prior match roots and terminals", + "vars": { + "prefix": "MATCH (:ASPResolutionEntry)-[:ASPResolutionBind]->(s:ASPResolutionRoot) ", + "function": "allShortestPaths", + "bounds": "1..", + "suffix": "RETURN p" + }, + "assert": { + "row_count": 5, + "path_node_ids": [["r1", "near"], ["r1", "near"], ["r1", "mid", "far"], ["r2", "mid", "near"], ["r2", "mid", "far"]] + } + }, + { + "name": "open mutation preserves every prior match pair", + "vars": { + "prefix": "MATCH (:ASPResolutionEntry)-[:ASPResolutionBind]->(s:ASPResolutionRoot) ", + "function": "allShortestPaths", + "bounds": "1..", + "suffix": "SET e.selected=true RETURN p" + }, + "assert": { + "row_count": 5, + "path_node_ids": [["r1", "near"], ["r1", "near"], ["r1", "mid", "far"], ["r2", "mid", "near"], ["r2", "mid", "far"]] + }, + "post_assertions": [ + { + "cypher": "MATCH (n) RETURN n", + "assert": { + "node_records": [ + {"id": "entry", "kinds": ["ASPResolutionEntry"], "props": {}}, + {"id": "r1", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "r2", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "r3", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "mid", "kinds": ["ASPResolutionMiddle"], "props": {}}, + {"id": "near", "kinds": ["ASPResolutionTarget"], "props": {"selected": true}}, + {"id": "far", "kinds": ["ASPResolutionTarget"], "props": {"selected": true}}, + {"id": "unreachable", "kinds": ["ASPResolutionTarget"], "props": {}} + ] + } + } + ] + }, + { + "name": "open shortest path preserves every prior match pair", + "vars": { + "prefix": "MATCH (:ASPResolutionEntry)-[:ASPResolutionBind]->(s:ASPResolutionRoot) ", + "function": "shortestPath", + "bounds": "1..", + "suffix": "RETURN p" + }, + "assert": { + "row_count": 4, + "path_node_ids": [["r1", "near"], ["r1", "mid", "far"], ["r2", "mid", "near"], ["r2", "mid", "far"]] + } + }, + { + "name": "open shortest mutation updates every reachable terminal", + "vars": { + "prefix": "MATCH (:ASPResolutionEntry)-[:ASPResolutionBind]->(s:ASPResolutionRoot) ", + "function": "shortestPath", + "bounds": "1..", + "suffix": "SET e.selected=true RETURN p" + }, + "assert": { + "row_count": 4, + "path_node_ids": [["r1", "near"], ["r1", "mid", "far"], ["r2", "mid", "near"], ["r2", "mid", "far"]] + }, + "post_assertions": [ + { + "cypher": "MATCH (n) RETURN n", + "assert": { + "node_records": [ + {"id": "entry", "kinds": ["ASPResolutionEntry"], "props": {}}, + {"id": "r1", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "r2", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "r3", "kinds": ["ASPResolutionRoot"], "props": {}}, + {"id": "mid", "kinds": ["ASPResolutionMiddle"], "props": {}}, + {"id": "near", "kinds": ["ASPResolutionTarget"], "props": {"selected": true}}, + {"id": "far", "kinds": ["ASPResolutionTarget"], "props": {"selected": true}}, + {"id": "unreachable", "kinds": ["ASPResolutionTarget"], "props": {}} + ] + } + } + ] + } + ] + } + ] +} From 60445a5090ef08a254a212e505c8e08a77dfdadd Mon Sep 17 00:00:00 2001 From: Sean Johnson Date: Wed, 28 Oct 2026 17:27:53 -0500 Subject: [PATCH 5/6] chore: update tests for ASP --- .../pgsql/test/validation_integration_test.go | 168 +++++++++++++++--- .../testdata/cases/shortest_paths_inline.json | 41 +++++ 2 files changed, 187 insertions(+), 22 deletions(-) diff --git a/cypher/models/pgsql/test/validation_integration_test.go b/cypher/models/pgsql/test/validation_integration_test.go index b47a21c9..acc86337 100644 --- a/cypher/models/pgsql/test/validation_integration_test.go +++ b/cypher/models/pgsql/test/validation_integration_test.go @@ -130,25 +130,133 @@ func TestTranslationTestCases(t *testing.T) { } } -func TestBidirectionalASPHarnessOverloads(t *testing.T) { +func setupShortestPathHarnessTest(t *testing.T) (context.Context, *pgxpool.Pool) { + t.Helper() + testCtx, done := context.WithCancel(context.Background()) - defer done() + t.Cleanup(done) pgConnectionStr := pgConnectionString(t) pgxPoolCfg, err := pgxpool.ParseConfig(pgConnectionStr) require.NoError(t, err) pgxPool, err := pg.NewPool(pgxPoolCfg) require.NoError(t, err) - defer pgxPool.Close() + t.Cleanup(pgxPool.Close) connection, err := dawgs.Open(context.TODO(), pg.DriverName, dawgs.Config{ GraphQueryMemoryLimit: size.Gibibyte, Pool: pgxPool, }) require.NoError(t, err) - defer connection.Close(testCtx) + t.Cleanup(func() { + connection.Close(testCtx) + }) require.NoError(t, connection.AssertSchema(testCtx, translationValidationGraphSchema())) + return testCtx, pgxPool +} + +func TestUnidirectionalASPHarness(t *testing.T) { + testCtx, pgxPool := setupShortestPathHarnessTest(t) + + t.Run("resolves roots independently", func(t *testing.T) { + testCases := []struct { + name string + query string + parameters []any + }{ + { + name: "array overload", + query: "select root_id, next_id, depth, path from unidirectional_asp_harness($1::text, $2::text, 4, $3::int8[], $4::int8[]) order by root_id, next_id, path", + parameters: []any{ + []int64{1, 3, 5}, + []int64{2, 4, 6}, + }, + }, + { + name: "text overload", + query: "select root_id, next_id, depth, path from unidirectional_asp_harness($1::text, $2::text, 4, ''::text, ''::text) order by root_id, next_id, path", + }, + } + + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + tx, err := pgxPool.Begin(testCtx) + require.NoError(t, err) + defer tx.Rollback(testCtx) + + var ( + graphID int64 + kindID int16 + ) + + require.NoError(t, tx.QueryRow(testCtx, "select id from graph where name = 'test'").Scan(&graphID)) + require.NoError(t, tx.QueryRow(testCtx, "select id from kind where name = 'EdgeKind1'").Scan(&kindID)) + + _, err = tx.Exec(testCtx, + "insert into edge (graph_id, start_id, end_id, kind_id, properties) values ($1, 30, 30, $2, '{}'::jsonb) on conflict do nothing", + graphID, + kindID, + ) + require.NoError(t, err) + + var ( + forwardPrimer = nextFrontValues( + "(1::int8, 2::int8, 1::int4, true, false, array [102]::int8[])", + "(1::int8, 2::int8, 1::int4, true, false, array [103]::int8[])", + "(3::int8, 30::int8, 1::int4, false, false, array [330]::int8[])", + "(5::int8, 50::int8, 1::int4, false, false, array [550]::int8[])", + ) + forwardRecursive = `insert into next_front (root_id, next_id, depth, satisfied, is_cycle, path) +select root_id, 4::int8, depth + 1, true, false, path || 304::int8 +from forward_front +where root_id = 3::int8;` + ) + + args := []any{forwardPrimer, forwardRecursive} + args = append(args, testCase.parameters...) + rows, err := tx.Query(testCtx, testCase.query, args...) + require.NoError(t, err) + defer rows.Close() + + type result struct { + rootID int64 + nextID int64 + depth int32 + path []int64 + } + + var results []result + for rows.Next() { + var next result + require.NoError(t, rows.Scan(&next.rootID, &next.nextID, &next.depth, &next.path)) + results = append(results, next) + } + require.NoError(t, rows.Err()) + + require.Equal(t, []result{{ + rootID: 1, + nextID: 2, + depth: 1, + path: []int64{102}, + }, { + rootID: 1, + nextID: 2, + depth: 1, + path: []int64{103}, + }, { + rootID: 3, + nextID: 4, + depth: 2, + path: []int64{330, 304}, + }}, results) + }) + } + }) +} + +func TestBidirectionalASPHarness(t *testing.T) { + testCtx, pgxPool := setupShortestPathHarnessTest(t) t.Run("array overload does not require pair filter", func(t *testing.T) { tx, err := pgxPool.Begin(testCtx) @@ -303,39 +411,43 @@ func TestBidirectionalASPHarnessOverloads(t *testing.T) { path: []int64{330, 305}, }}, results) }) +} + +func TestUnidirectionalSPHarness(t *testing.T) { + testCtx, pgxPool := setupShortestPathHarnessTest(t) - t.Run("shortest path harnesses avoid output column ambiguity", func(t *testing.T) { + t.Run("avoids output column ambiguity", func(t *testing.T) { var ( - frontier = nextFrontValues("(1::int8, 2::int8, 1::int4, false, false, array [101]::int8[])") - unidirectionalCount int + frontier = nextFrontValues("(1::int8, 2::int8, 1::int4, false, false, array [101]::int8[])") + count int ) require.NoError(t, pgxPool.QueryRow(testCtx, "select count(*) from unidirectional_sp_harness($1::text, $2::text, 1, array []::int8[], array []::int8[])", frontier, emptyFrontier, - ).Scan(&unidirectionalCount)) - require.Equal(t, 0, unidirectionalCount) + ).Scan(&count)) + require.Equal(t, 0, count) + }) +} + +func TestBidirectionalSPHarness(t *testing.T) { + testCtx, pgxPool := setupShortestPathHarnessTest(t) + + t.Run("avoids output column ambiguity", func(t *testing.T) { + var ( + frontier = nextFrontValues("(1::int8, 2::int8, 1::int4, false, false, array [101]::int8[])") + count int + ) - var bidirectionalCount int require.NoError(t, pgxPool.QueryRow(testCtx, "select count(*) from bidirectional_sp_harness($1::text, $2::text, $3::text, $4::text, 1, array []::int8[], array []::int8[])", frontier, emptyFrontier, emptyFrontier, emptyFrontier, - ).Scan(&bidirectionalCount)) - require.Equal(t, 0, bidirectionalCount) - }) - - t.Run("shortest path self endpoint helper reports clear error", func(t *testing.T) { - var ( - ok bool - err = pgxPool.QueryRow(testCtx, "select shortest_path_self_endpoint_error(1::int8, 1::int8)").Scan(&ok) - ) - - require.Error(t, err) - require.Contains(t, err.Error(), "shortest path endpoints must not resolve to the same node") + ).Scan(&count)) + require.Equal(t, 0, count) }) t.Run("pair-aware shortest path harness resolves all explicit pairs", func(t *testing.T) { @@ -394,3 +506,15 @@ func TestBidirectionalASPHarnessOverloads(t *testing.T) { }}, results) }) } + +func TestShortestPathSelfEndpointError(t *testing.T) { + testCtx, pgxPool := setupShortestPathHarnessTest(t) + + var ( + ok bool + err = pgxPool.QueryRow(testCtx, "select shortest_path_self_endpoint_error(1::int8, 1::int8)").Scan(&ok) + ) + + require.Error(t, err) + require.Contains(t, err.Error(), "shortest path endpoints must not resolve to the same node") +} diff --git a/integration/testdata/cases/shortest_paths_inline.json b/integration/testdata/cases/shortest_paths_inline.json index 13adb47f..c2aaa491 100644 --- a/integration/testdata/cases/shortest_paths_inline.json +++ b/integration/testdata/cases/shortest_paths_inline.json @@ -129,6 +129,47 @@ ] }, "assert": {"row_count": 1, "path_node_ids": [["b", "c", "d"]]} + }, + { + "name": "all shortest paths resolves prior match roots independently", + "cypher": "MATCH (:NodeKind1)-[:EdgeKind1]->(u:NodeKind2) MATCH p=allShortestPaths((u)-[:EdgeKind2*1..]->(d:NodeKind3)) RETURN p", + "fixture": { + "nodes": [ + {"id": "a", "kinds": ["NodeKind1"], "properties": {}}, + {"id": "b", "kinds": ["NodeKind2"], "properties": {}}, + {"id": "d", "kinds": ["NodeKind3"], "properties": {}}, + {"id": "x", "kinds": ["NodeKind1"], "properties": {}}, + {"id": "y", "kinds": ["NodeKind2"], "properties": {}}, + {"id": "z", "kinds": ["NodeKind2"], "properties": {}} + ], + "edges": [ + {"start_id": "a", "end_id": "b", "kind": "EdgeKind1"}, + {"start_id": "x", "end_id": "y", "kind": "EdgeKind1"}, + {"start_id": "b", "end_id": "d", "kind": "EdgeKind2"}, + {"start_id": "y", "end_id": "z", "kind": "EdgeKind2"}, + {"start_id": "z", "end_id": "d", "kind": "EdgeKind2"} + ] + }, + "assert": {"row_count": 2, "path_node_ids": [["b", "d"], ["y", "z", "d"]]} + }, + { + "name": "all shortest paths text filters resolve roots independently", + "cypher": "MATCH p=allShortestPaths((u:NodeKind1)-[:EdgeKind2*1..]->(d:NodeKind3)) RETURN p", + "fixture": { + "nodes": [ + {"id": "a", "kinds": ["NodeKind1"], "properties": {}}, + {"id": "d", "kinds": ["NodeKind3"], "properties": {}}, + {"id": "w", "kinds": ["NodeKind1"], "properties": {}}, + {"id": "x", "kinds": ["NodeKind1"], "properties": {}}, + {"id": "y", "kinds": ["NodeKind2"], "properties": {}} + ], + "edges": [ + {"start_id": "a", "end_id": "d", "kind": "EdgeKind2"}, + {"start_id": "x", "end_id": "y", "kind": "EdgeKind2"}, + {"start_id": "y", "end_id": "d", "kind": "EdgeKind2"} + ] + }, + "assert": {"row_count": 2, "path_node_ids": [["a", "d"], ["x", "y", "d"]]} } ] } From 09f2e1279a384bf9538e19c3ce911e8caa68d934 Mon Sep 17 00:00:00 2001 From: Sean Johnson Date: Thu, 29 Oct 2026 13:27:35 -0500 Subject: [PATCH 6/6] chore: makefile rabbit penance --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a70136c8..a851f260 100644 --- a/Makefile +++ b/Makefile @@ -133,7 +133,7 @@ test_all: test test_integration test_bdd_integration test_integration: $(METRICS_DIR) @echo "Running all integration tests..." - @$(GO_CMD) test -vet=off -tags 'manual_integration integration' -race -cover -coverprofile=$(INTEGRATION_COVERAGE_PROFILE) -count=1 -p=1 -parallel=1 $(MAIN_PACKAGES) + @$(GO_CMD) test -vet=off -tags 'manual_integration integration' -race -cover -coverpkg=$(COVERPKG) -coverprofile=$(INTEGRATION_COVERAGE_PROFILE) -count=1 -p=1 -parallel=1 $(MAIN_PACKAGES) test_bdd_integration: $(METRICS_DIR) @echo "Running all BDD integration tests..." @$(GO_CMD) test -vet=off -v -tags 'bdd_integration' -count=1 ./bdd