fix find & create foreign index keys

This commit is contained in:
Nia Weiss 2020-10-21 10:52:19 -04:00
parent a6e3723190
commit 1fe0edae08
No known key found for this signature in database
GPG key ID: 895E83409BFDA1BB

View file

@ -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 {