From 6ad39a376e4e0e62a85809140b5736c3d1c51d09 Mon Sep 17 00:00:00 2001 From: Seebs Date: Wed, 20 Nov 2019 14:57:15 -0600 Subject: [PATCH] handle precalls and cross-index queries better There's two actual changes here, but they're closely related. First, handle named parameters for precalls, not just indexed parameters. Second, when doing translation for a call, check whether it specifies an index, and if it does, use that index instead of the current index for the translation. --- executor.go | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/executor.go b/executor.go index e91ec5f30..31caaf7e7 100644 --- a/executor.go +++ b/executor.go @@ -366,6 +366,14 @@ func (e *executor) handlePreCallChildren(ctx context.Context, index string, c *p return err } } + for _, val := range c.Args { + // Handle Call() operations which exist inside named arguments, too. + if call, ok := val.(*pql.Call); ok { + if err := e.handlePreCalls(ctx, index, call, shards, opt); err != nil { + return err + } + } + } return nil } @@ -3095,7 +3103,20 @@ func (e *executor) translateCalls(ctx context.Context, index string, idx *Index, defer span.Finish() for i := range calls { - if err := e.translateCall(index, idx, calls[i]); err != nil { + // Possibly change to another index for translation, if this + // call crosses index boundaries. + newIdxName := calls[i].CallIndex() + var newIdx *Index + if newIdxName == "" || newIdxName == index { + newIdxName = index + newIdx = idx + } else { + newIdx = idx.holder.indexes[newIdxName] + if newIdx == nil { + return fmt.Errorf("unknown index %q specified in cross-index call", newIdxName) + } + } + if err := e.translateCall(newIdxName, newIdx, calls[i]); err != nil { return err } } @@ -3195,7 +3216,20 @@ func (e *executor) translateCall(index string, idx *Index, c *pql.Call) error { // Translate child calls. for _, child := range c.Children { - if err := e.translateCall(index, idx, child); err != nil { + // Possibly change to another index for translation, if this + // call crosses index boundaries. + newIdxName := child.CallIndex() + var newIdx *Index + if newIdxName == "" || newIdxName == index { + newIdxName = index + newIdx = idx + } else { + newIdx = idx.holder.indexes[newIdxName] + if newIdx == nil { + return fmt.Errorf("unknown index %q specified in cross-index call", newIdxName) + } + } + if err := e.translateCall(newIdxName, newIdx, child); err != nil { return err } }