Skip to content

Commit 2204c14

Browse files
DavidS-ovmactions-user
authored andcommitted
Merge pull request #631 from overmindtech/liq-to-edge
Rewrite Gateway query processing to use separate edges instead of embedded LinkedItemQueries GitOrigin-RevId: e4bcb01c6adc601cd8168845467a26f6a1ec1488
1 parent f0a0d35 commit 2204c14

File tree

8 files changed

+478
-265
lines changed

8 files changed

+478
-265
lines changed

discovery/engine_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func TestNats(t *testing.T) {
256256
Scope: "test",
257257
}, 0)
258258

259-
_, _, err := req.Execute(context.Background(), e.natsConnection)
259+
_, _, _, err := req.Execute(context.Background(), e.natsConnection)
260260

261261
if err != nil {
262262
t.Error(err)
@@ -643,7 +643,7 @@ func TestNatsAuth(t *testing.T) {
643643
e.ClearCache()
644644
})
645645

646-
_, _, err := sdp.NewQueryProgress(&sdp.Query{
646+
_, _, _, err := sdp.NewQueryProgress(&sdp.Query{
647647
Type: "person",
648648
Method: sdp.QueryMethod_GET,
649649
Query: "basic",

discovery/enginerequests_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func TestSendQuerySync(t *testing.T) {
359359
}, 0)
360360
progress.StartTimeout = 1 * time.Second
361361

362-
items, errs, err := progress.Execute(ctx, e.natsConnection)
362+
items, _, errs, err := progress.Execute(ctx, e.natsConnection)
363363

364364
if err != nil {
365365
t.Error(err)

sdp-go/items.go

Lines changed: 117 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ import (
2121
const WILDCARD = "*"
2222

2323
// Copy copies all information from one item pointer to another
24-
func (liq *BlastPropagation) Copy(dest *BlastPropagation) {
25-
dest.In = liq.GetIn()
26-
dest.Out = liq.GetOut()
24+
func (bp *BlastPropagation) Copy(dest *BlastPropagation) {
25+
dest.In = bp.GetIn()
26+
dest.Out = bp.GetOut()
27+
}
28+
29+
func (bp *BlastPropagation) IsEqual(other *BlastPropagation) bool {
30+
return bp.GetIn() == other.GetIn() && bp.GetOut() == other.GetOut()
2731
}
2832

2933
// Copy copies all information from one item pointer to another
@@ -153,6 +157,12 @@ func (i *Item) Hash() string {
153157
return hashSum(([]byte(fmt.Sprint(i.GloballyUniqueName()))))
154158
}
155159

160+
func (e *Edge) IsEqual(other *Edge) bool {
161+
return e.GetFrom().IsEqual(other.GetFrom()) &&
162+
e.GetTo().IsEqual(other.GetTo()) &&
163+
e.GetBlastPropagation().IsEqual(other.GetBlastPropagation())
164+
}
165+
156166
// Hash Returns a 12 character hash for the item. This is likely but not
157167
// guaranteed to be unique. The hash is calculated using the GloballyUniqueName
158168
func (r *Reference) Hash() string {
@@ -168,13 +178,61 @@ func (r *Reference) Hash() string {
168178
//
169179
// They are concatenated with dots (.)
170180
func (r *Reference) GloballyUniqueName() string {
171-
return strings.Join([]string{
172-
r.GetScope(),
173-
r.GetType(),
174-
r.GetUniqueAttributeValue(),
175-
},
176-
".",
177-
)
181+
if r == nil {
182+
// in the llm templates nil references are processed, and after spending
183+
// half an hour on trying to figure out what was happening in the
184+
// reflect code, I decided to just return an empty string here. DS,
185+
// 2025-02-26
186+
return ""
187+
}
188+
if r.GetIsQuery() {
189+
if r.GetMethod() == QueryMethod_GET {
190+
// GET queries are single items
191+
return fmt.Sprintf("%v.%v.%v", r.GetScope(), r.GetType(), r.GetQuery())
192+
}
193+
panic(fmt.Sprintf("cannot get globally unique name for query reference: %v", r))
194+
}
195+
return fmt.Sprintf("%v.%v.%v", r.GetScope(), r.GetType(), r.GetUniqueAttributeValue())
196+
197+
}
198+
199+
// Key returns a globally unique string for this reference, even if it is a GET query
200+
func (r *Reference) Key() string {
201+
if r == nil {
202+
panic("cannot get key for nil reference")
203+
}
204+
if r.GetIsQuery() {
205+
if r.IsSingle() {
206+
// GET queries without wildcards are single items
207+
return fmt.Sprintf("%v.%v.%v", r.GetScope(), r.GetType(), r.GetQuery())
208+
}
209+
return fmt.Sprintf("%v: %v.%v.%v", r.GetMethod(), r.GetScope(), r.GetType(), r.GetQuery())
210+
}
211+
return r.GloballyUniqueName()
212+
}
213+
214+
// IsSingle returns true if this references a single item, false if it is a LIST
215+
// or SEARCH query, or a GET query with scope and/or type wildcards.
216+
func (r *Reference) IsSingle() bool {
217+
// nil reference is never good
218+
if r == nil {
219+
return false
220+
}
221+
// if it is a query, then it is only a single item if it is a GET query with no wildcards
222+
if r.GetIsQuery() {
223+
return r.GetMethod() == QueryMethod_GET && r.GetScope() != "*" && r.GetType() != "*"
224+
}
225+
// if it is not a query, then it is always single item
226+
return true
227+
}
228+
229+
func (r *Reference) IsEqual(other *Reference) bool {
230+
return r.GetScope() == other.GetScope() &&
231+
r.GetType() == other.GetType() &&
232+
r.GetUniqueAttributeValue() == other.GetUniqueAttributeValue() &&
233+
r.GetIsQuery() == other.GetIsQuery() &&
234+
r.GetMethod() == other.GetMethod() &&
235+
r.GetQuery() == other.GetQuery()
178236
}
179237

180238
// Copy copies all information from one Reference pointer to another
@@ -184,6 +242,24 @@ func (r *Reference) Copy(dest *Reference) {
184242
dest.Scope = r.GetScope()
185243
}
186244

245+
func (r *Reference) ToQuery() *Query {
246+
if !r.GetIsQuery() {
247+
return &Query{
248+
Scope: r.GetScope(),
249+
Type: r.GetType(),
250+
Method: QueryMethod_GET,
251+
Query: r.GetUniqueAttributeValue(),
252+
}
253+
}
254+
255+
return &Query{
256+
Scope: r.GetScope(),
257+
Type: r.GetType(),
258+
Method: r.GetMethod(),
259+
Query: r.GetQuery(),
260+
}
261+
}
262+
187263
// Copy copies all information from one Metadata pointer to another
188264
func (m *Metadata) Copy(dest *Metadata) {
189265
if m == nil {
@@ -350,6 +426,37 @@ func (r *Query) ParseUuid() uuid.UUID {
350426
return reqUUID
351427
}
352428

429+
func (qr *QueryResponse) ToGatewayResponse() *GatewayResponse {
430+
switch qr.GetResponseType().(type) {
431+
case *QueryResponse_NewItem:
432+
return &GatewayResponse{
433+
ResponseType: &GatewayResponse_NewItem{
434+
NewItem: qr.GetNewItem(),
435+
},
436+
}
437+
case *QueryResponse_Edge:
438+
return &GatewayResponse{
439+
ResponseType: &GatewayResponse_NewEdge{
440+
NewEdge: qr.GetEdge(),
441+
},
442+
}
443+
case *QueryResponse_Error:
444+
return &GatewayResponse{
445+
ResponseType: &GatewayResponse_QueryError{
446+
QueryError: qr.GetError(),
447+
},
448+
}
449+
case *QueryResponse_Response:
450+
return &GatewayResponse{
451+
ResponseType: &GatewayResponse_QueryStatus{
452+
QueryStatus: qr.GetResponse().ToQueryStatus(),
453+
},
454+
}
455+
default:
456+
panic(fmt.Sprintf("encountered unknown QueryResponse type: %T", qr))
457+
}
458+
}
459+
353460
func (x *CancelQuery) GetUUIDParsed() *uuid.UUID {
354461
u, err := uuid.FromBytes(x.GetUUID())
355462
if err != nil {

0 commit comments

Comments
 (0)