mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 00:55:55 +00:00
move the foreign index key check into applyTranslateStore()
This commit is contained in:
parent
f001ad199f
commit
b620e37e51
3 changed files with 15 additions and 40 deletions
15
api.go
15
api.go
|
|
@ -1086,22 +1086,11 @@ func (api *API) ImportValue(ctx context.Context, req *ImportValueRequest, opts .
|
|||
req.Shard = math.MaxUint64
|
||||
}
|
||||
|
||||
// Determine if foreign index is being used for translation.
|
||||
useKeys := field.Keys()
|
||||
foreignIndexName := field.ForeignIndex()
|
||||
if foreignIndexName != "" {
|
||||
foreignIndex := api.holder.indexes[foreignIndexName]
|
||||
if foreignIndex == nil {
|
||||
return errors.Errorf("foreign index not found: %q", foreignIndexName)
|
||||
}
|
||||
useKeys = foreignIndex.Keys()
|
||||
}
|
||||
|
||||
// Translate values when the field uses keys (for example, when
|
||||
// the field has a ForeignIndex with keys).
|
||||
if useKeys {
|
||||
if field.Keys() {
|
||||
// Perform translation.
|
||||
uints, err := api.cluster.translateIndexKeys(ctx, foreignIndexName, req.StringValues)
|
||||
uints, err := api.cluster.translateIndexKeys(ctx, field.ForeignIndex(), req.StringValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
29
executor.go
29
executor.go
|
|
@ -3656,17 +3656,6 @@ func (e *executor) translateCall(indexName string, c *pql.Call, keyMaps map[stri
|
|||
return nil
|
||||
}
|
||||
|
||||
// Determine if foreign index is being used for translation.
|
||||
useKeys := field.Keys()
|
||||
foreignIndexName := field.ForeignIndex()
|
||||
if foreignIndexName != "" {
|
||||
foreignIndex := e.Holder.indexes[foreignIndexName]
|
||||
if foreignIndex == nil {
|
||||
return errors.Errorf("foreign index not found: %q", foreignIndexName)
|
||||
}
|
||||
useKeys = foreignIndex.Keys()
|
||||
}
|
||||
|
||||
// Bool field keys do not use the translator because there
|
||||
// are only two possible values. Instead, they are handled
|
||||
// directly.
|
||||
|
|
@ -3685,7 +3674,8 @@ func (e *executor) translateCall(indexName string, c *pql.Call, keyMaps map[stri
|
|||
}
|
||||
c.Args[rowKey] = rowID
|
||||
}
|
||||
} else if useKeys {
|
||||
} else if field.Keys() {
|
||||
foreignIndexName := field.ForeignIndex()
|
||||
if c.Args[rowKey] != nil && isCondition(c.Args[rowKey]) {
|
||||
// In the case where a field has a foreign index with keys,
|
||||
// allow `== "key"` or `!= "key"` to be used against the BSI
|
||||
|
|
@ -3868,22 +3858,11 @@ func (e *executor) translateResult(index string, idx *Index, call *pql.Call, res
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
// Determine if foreign index is being used for translation.
|
||||
useKeys := field.Keys()
|
||||
foreignIndexName := field.ForeignIndex()
|
||||
if foreignIndexName != "" {
|
||||
foreignIndex := e.Holder.indexes[foreignIndexName]
|
||||
if foreignIndex == nil {
|
||||
return nil, errors.Errorf("foreign index not found: %q", foreignIndexName)
|
||||
}
|
||||
useKeys = foreignIndex.Keys()
|
||||
}
|
||||
|
||||
if useKeys {
|
||||
if field.Keys() {
|
||||
rslt := result.Pos
|
||||
other := &Row{Attrs: rslt.Attrs}
|
||||
for _, segment := range rslt.Segments() {
|
||||
keys, err := e.Cluster.translateIndexIDs(context.Background(), foreignIndexName, segment.Columns())
|
||||
keys, err := e.Cluster.translateIndexIDs(context.Background(), field.ForeignIndex(), segment.Columns())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "translating index ids")
|
||||
}
|
||||
|
|
|
|||
11
field.go
11
field.go
|
|
@ -520,8 +520,7 @@ func (f *Field) Open() error {
|
|||
return errors.Wrap(err, "opening attrstore")
|
||||
}
|
||||
|
||||
// If the field has a foreign index, and that index uses keys,
|
||||
// then use that index's translateStore instead.
|
||||
// Apply the field-specific translateStore.
|
||||
if err := f.applyTranslateStore(); err != nil {
|
||||
return errors.Wrap(err, "applying translate store")
|
||||
}
|
||||
|
|
@ -553,6 +552,14 @@ func (f *Field) applyTranslateStore() error {
|
|||
return errors.Wrap(err, "opening field translate store")
|
||||
}
|
||||
f.usesKeys = f.options.Keys
|
||||
|
||||
// In the case where the field has a foreign index, set
|
||||
// the usesKeys value accordingly.
|
||||
if foreignIndexName := f.ForeignIndex(); foreignIndexName != "" {
|
||||
if foreignIndex := f.holder.indexes[foreignIndexName]; foreignIndex != nil {
|
||||
f.usesKeys = foreignIndex.Keys()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue