-
Notifications
You must be signed in to change notification settings - Fork 8
feat(cysql): support CREATE and UNWIND #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zinic
wants to merge
7
commits into
SpecterOps:main
Choose a base branch
from
zinic:unwind
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8180ff9
feat(cysql): add Cypher UNWIND clause translation support
zinic 75cbcde
feat(cysql): support cypher create
zinic b143c47
fix (cysql): avoid materializing synthetic frames in FROM statements
zinic 95c17c6
fix (cysql): materialize unwind before downstream clauses
zinic be84f36
fix (cysql): rectify distinc propagation
zinic 5fdae0a
fix (cysql): pull through graph_id down to CREATE statements
zinic d9546ab
fix (cysql): make graph_id emit regardless of the value set
zinic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| -- Copyright 2026 Specter Ops, Inc. | ||
| -- | ||
| -- Licensed under the Apache License, Version 2.0 | ||
| -- you may not use this file except in compliance with the License. | ||
| -- You may obtain a copy of the License at | ||
| -- | ||
| -- http://www.apache.org/licenses/LICENSE-2.0 | ||
| -- | ||
| -- Unless required by applicable law or agreed to in writing, software | ||
| -- distributed under the License is distributed on an "AS IS" BASIS, | ||
| -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| -- See the License for the specific language governing permissions and | ||
| -- limitations under the License. | ||
| -- | ||
| -- SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| -- case: create (n:NodeKind1 {name: 'Bob'}) return n | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object('name', 'Bob')::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0) select s0.n0 as n from s0; | ||
|
|
||
| -- case: create (n:NodeKind1) | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0) select 1; | ||
|
|
||
| -- case: create (n) | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array []::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0) select 1; | ||
|
|
||
| -- case: create (n:NodeKind1:NodeKind2 {name: 'Bob', value: 1}) return n | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1, 2]::int2[], jsonb_build_object('name', 'Bob', 'value', 1)::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0) select s0.n0 as n from s0; | ||
|
|
||
| -- case: create (n) return n | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array []::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0) select s0.n0 as n from s0; | ||
|
|
||
| -- case: create (n:NodeKind1 {name: 'Alice', value: 42}) return n | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object('name', 'Alice', 'value', 42)::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0) select s0.n0 as n from s0; | ||
|
|
||
| -- case: match (n:NodeKind1) with n create (m:NodeKind2) return m | ||
| 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 [1]::int2[]) select s1.n0 as n0 from s1), s2 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1) select s2.n1 as m from s2; | ||
|
|
||
| -- case: match (n:NodeKind1) with n create (m:NodeKind2 {name: 'Bob'}) return m | ||
| 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 [1]::int2[]) select s1.n0 as n0 from s1), s2 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object('name', 'Bob')::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1) select s2.n1 as m from s2; | ||
|
|
||
| -- case: match (n:NodeKind1) with n create (m:NodeKind2) | ||
| 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 [1]::int2[]) select s1.n0 as n0 from s1), s2 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1) select 1; | ||
|
|
||
| -- case: create (a:NodeKind1)-[:EdgeKind1]->(b:NodeKind2) | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0), s1 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1), s2 as (insert into edge (start_id, end_id, kind_id, properties) select (s0.n0).id, (s1.n1).id, 3, jsonb_build_object()::jsonb from s0, s1 returning (id, start_id, end_id, kind_id, properties)::edgecomposite as e0) select 1; | ||
|
|
||
| -- case: create (a:NodeKind1)-[r:EdgeKind1]->(b:NodeKind2) return r | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0), s1 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1), s2 as (insert into edge (start_id, end_id, kind_id, properties) select (s0.n0).id, (s1.n1).id, 3, jsonb_build_object()::jsonb from s0, s1 returning (id, start_id, end_id, kind_id, properties)::edgecomposite as e0) select s2.e0 as r from s2; | ||
|
|
||
| -- case: create (a:NodeKind1)-[:EdgeKind1 {name: 'rel'}]->(b:NodeKind2) | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0), s1 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1), s2 as (insert into edge (start_id, end_id, kind_id, properties) select (s0.n0).id, (s1.n1).id, 3, jsonb_build_object('name', 'rel')::jsonb from s0, s1 returning (id, start_id, end_id, kind_id, properties)::edgecomposite as e0) select 1; | ||
|
|
||
| -- case: create (a:NodeKind1)<-[:EdgeKind1]-(b:NodeKind2) | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0), s1 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1), s2 as (insert into edge (start_id, end_id, kind_id, properties) select (s1.n1).id, (s0.n0).id, 3, jsonb_build_object()::jsonb from s1, s0 returning (id, start_id, end_id, kind_id, properties)::edgecomposite as e0) select 1; | ||
|
|
||
| -- case: match (a:NodeKind1) with a create (a)-[:EdgeKind1]->(b:NodeKind2) | ||
| 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 [1]::int2[]) select s1.n0 as n0 from s1), s2 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1), s3 as (insert into edge (start_id, end_id, kind_id, properties) select (s0.n0).id, (s2.n1).id, 3, jsonb_build_object()::jsonb from s0, s2 returning (id, start_id, end_id, kind_id, properties)::edgecomposite as e0) select 1; | ||
|
|
||
| -- case: match (a:NodeKind1) with a create (a)-[r:EdgeKind1]->(b:NodeKind2) return r | ||
| 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 [1]::int2[]) select s1.n0 as n0 from s1), s2 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object()::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1), s3 as (insert into edge (start_id, end_id, kind_id, properties) select (s0.n0).id, (s2.n1).id, 3, jsonb_build_object()::jsonb from s0, s2 returning (id, start_id, end_id, kind_id, properties)::edgecomposite as e0) select s3.e0 as r from s3; | ||
|
|
||
| -- case: create (a:NodeKind1 {name: 'abc'})-[:EdgeKind1 {prop: 123}]->(:NodeKind2 {name: 'test'}) return a | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object('name', 'abc')::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0), s1 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object('name', 'test')::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1), s2 as (insert into edge (start_id, end_id, kind_id, properties) select (s0.n0).id, (s1.n1).id, 3, jsonb_build_object('prop', 123)::jsonb from s0, s1 returning (id, start_id, end_id, kind_id, properties)::edgecomposite as e0) select s0.n0 as a from s0; | ||
|
|
||
| -- case: create (:NodeKind1 {name: 'abc'})-[:EdgeKind1 {prop: 123}]->(c:NodeKind2 {name: 'test'}) return c | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object('name', 'abc')::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0), s1 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object('name', 'test')::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1), s2 as (insert into edge (start_id, end_id, kind_id, properties) select (s0.n0).id, (s1.n1).id, 3, jsonb_build_object('prop', 123)::jsonb from s0, s1 returning (id, start_id, end_id, kind_id, properties)::edgecomposite as e0) select s1.n1 as c from s1; | ||
|
|
||
| -- case: create (:NodeKind1 {name: 'abc'})-[:EdgeKind1 {prop: 123}]->(c:NodeKind2 {name: 'test'})<-[:EdgeKind2]-(:NodeKind1 {name: 'other'}) return c | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object('name', 'abc')::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0), s1 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object('name', 'test')::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1), s2 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object('name', 'other')::jsonb) returning (id, kind_ids, properties)::nodecomposite as n2), s3 as (insert into edge (start_id, end_id, kind_id, properties) select (s0.n0).id, (s1.n1).id, 3, jsonb_build_object('prop', 123)::jsonb from s0, s1 returning (id, start_id, end_id, kind_id, properties)::edgecomposite as e0), s4 as (insert into edge (start_id, end_id, kind_id, properties) select (s2.n2).id, (s1.n1).id, 4, jsonb_build_object()::jsonb from s2, s1 returning (id, start_id, end_id, kind_id, properties)::edgecomposite as e1) select s1.n1 as c from s1; | ||
|
|
||
| -- case: create p = (:NodeKind1 {name: 'abc'})-[:EdgeKind1 {prop: 123}]->(:NodeKind2 {name: 'test'}) return p | ||
| with s0 as (insert into node (graph_id, kind_ids, properties) values (0, array [1]::int2[], jsonb_build_object('name', 'abc')::jsonb) returning (id, kind_ids, properties)::nodecomposite as n0), s1 as (insert into node (graph_id, kind_ids, properties) values (0, array [2]::int2[], jsonb_build_object('name', 'test')::jsonb) returning (id, kind_ids, properties)::nodecomposite as n1), s2 as (insert into edge (start_id, end_id, kind_id, properties) select (s0.n0).id, (s1.n1).id, 3, jsonb_build_object('prop', 123)::jsonb from s0, s1 returning (id, start_id, end_id, kind_id, properties)::edgecomposite as e0) select edges_to_path(variadic array [(s2.e0).id]::int8[])::pathcomposite as p from s0, s2, s1; | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the passed
ctxinstead ofcontext.Background()inAssertLive.AssertLiveaccepts actx context.Contextand correctly threads it intodriver.Runon Line 213, buttranslate.Translatehere is invoked withcontext.Background(). If the test's context carries a deadline/cancellation or test-scoped values (e.g., for the context-aware kind mapper), they are ignored during translation. The pre-existingWriteTo/Assertpaths have no caller-provided context, butAssertLivedoes.🛠️ Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents