From 15ba701576b3c6b2bec03dc26b74e7284e68441f Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 3 Jun 2024 13:11:45 -0600 Subject: [PATCH] d2oracle: glob null edges --- d2ir/compile.go | 7 +- d2ir/pattern_test.go | 12 + .../patterns/edge-glob-null.exp.json | 473 ++++++++++++++++++ 3 files changed, 491 insertions(+), 1 deletion(-) create mode 100644 testdata/d2ir/TestCompile/patterns/edge-glob-null.exp.json diff --git a/d2ir/compile.go b/d2ir/compile.go index 273637a9d..6d5145b53 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -991,7 +991,7 @@ func (c *compiler) compileEdges(refctx *RefContext) { func (c *compiler) _compileEdges(refctx *RefContext) { eida := NewEdgeIDs(refctx.Key) for i, eid := range eida { - if refctx.Key != nil && refctx.Key.Value.Null != nil { + if !eid.Glob && (refctx.Key.Primary.Null != nil || refctx.Key.Value.Null != nil) { refctx.ScopeMap.DeleteEdge(eid) continue } @@ -1016,6 +1016,11 @@ func (c *compiler) _compileEdges(refctx *RefContext) { }) refctx.ScopeMap.appendFieldReferences(0, refctx.Edge.Src, refctx, c) refctx.ScopeMap.appendFieldReferences(0, refctx.Edge.Dst, refctx, c) + + if refctx.Key.Primary.Null != nil || refctx.Key.Value.Null != nil { + refctx.ScopeMap.DeleteEdge(e.ID) + continue + } } } else { var err error diff --git a/d2ir/pattern_test.go b/d2ir/pattern_test.go index 941db0785..a8a835f2c 100644 --- a/d2ir/pattern_test.go +++ b/d2ir/pattern_test.go @@ -310,6 +310,18 @@ layers.x: { wrapper.p } assertQuery(t, m, 0, 0, nil, "layers.x.wrapper.p") }, }, + { + name: "edge-glob-null", + run: func(t testing.TB) { + m, err := compile(t, `a -> b +(* -> *)[*]: null +x -> y +`) + assert.Success(t, err) + // 4 fields and 0 edges + assertQuery(t, m, 4, 0, nil, "") + }, + }, { name: "double-glob/edge/1", run: func(t testing.TB) { diff --git a/testdata/d2ir/TestCompile/patterns/edge-glob-null.exp.json b/testdata/d2ir/TestCompile/patterns/edge-glob-null.exp.json new file mode 100644 index 000000000..a61325deb --- /dev/null +++ b/testdata/d2ir/TestCompile/patterns/edge-glob-null.exp.json @@ -0,0 +1,473 @@ +{ + "fields": [ + { + "name": "a", + "references": [ + { + "string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + }, + "key_path": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "context": { + "edge": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + }, + "key": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "edges": [ + { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": "b", + "references": [ + { + "string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + }, + "key_path": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "context": { + "edge": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + }, + "key": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "edges": [ + { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:6:6", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,0:5:5-0:6:6", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": "x", + "references": [ + { + "string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + }, + "key": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "edges": [ + { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + }, + { + "name": "y", + "references": [ + { + "string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + }, + "key_path": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "context": { + "edge": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + }, + "key": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "edges": [ + { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:6:31", + "src": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:0:25-2:1:26", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/patterns/edge-glob-null.d2,2:5:30-2:6:31", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + } + ] + } + ], + "edges": [] +}