From 1fe0edae089129ed29bb02deb088cb6c91179304 Mon Sep 17 00:00:00 2001 From: Nia Weiss Date: Wed, 21 Oct 2020 10:52:19 -0400 Subject: [PATCH] fix find & create foreign index keys --- executor.go | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/executor.go b/executor.go index b25634136..063463516 100644 --- a/executor.go +++ b/executor.go @@ -4827,8 +4827,10 @@ func (e *executor) preTranslate(ctx context.Context, index string, calls ...*pql } } - // Translate columns. + // Create keys. + // Both rows and columns need to be created first because of foreign index keys. cols = make(map[string]map[string]uint64) + rows = make(map[string]map[string]map[string]uint64) for idx, keys := range collector.createCols { translations, err := e.Cluster.createIndexKeys(ctx, index, keys...) if err != nil { @@ -4836,22 +4838,6 @@ func (e *executor) preTranslate(ctx context.Context, index string, calls ...*pql } cols[idx] = translations } - for idx, keys := range collector.findCols { - translations, err := e.Cluster.findIndexKeys(ctx, index, keys...) - if err != nil { - return nil, nil, errors.Wrap(err, "finding query column keys") - } - if prev := cols[idx]; prev != nil { - for key, id := range translations { - prev[key] = id - } - } else { - cols[idx] = translations - } - } - - // Translate rows. - rows = make(map[string]map[string]map[string]uint64) for idx, fields := range collector.createRows { idxRows := make(map[string]map[string]uint64) index := e.Holder.Index(idx) @@ -4871,6 +4857,21 @@ func (e *executor) preTranslate(ctx context.Context, index string, calls ...*pql } rows[idx] = idxRows } + + // Find other keys. + for idx, keys := range collector.findCols { + translations, err := e.Cluster.findIndexKeys(ctx, index, keys...) + if err != nil { + return nil, nil, errors.Wrap(err, "finding query column keys") + } + if prev := cols[idx]; prev != nil { + for key, id := range translations { + prev[key] = id + } + } else { + cols[idx] = translations + } + } for idx, fields := range collector.findRows { idxRows := rows[idx] if idxRows == nil {