post merge, needs review of TODOs

This commit is contained in:
Travis 2020-01-14 22:10:12 -06:00
parent df51f07f96
commit 54679c12c4
4 changed files with 25 additions and 4 deletions

View file

@ -869,7 +869,7 @@ func shardPartition(index string, shard uint64, partitionN int) int {
return int(h.Sum64() % uint64(partitionN))
}
// keyPartition returns the partition that a shard belongs to.
// keyPartition returns the partition that a key belongs to.
func (c *cluster) keyPartition(index, key string) int {
return keyPartition(index, key, c.partitionN)
}

View file

@ -3689,7 +3689,27 @@ func (e *executor) translateCall(indexName string, idx *Index, isDefaultIndex bo
c.Args[rowKey] = rowID
}
} else if field.Keys() {
if c.Args[rowKey] != nil && !isString(c.Args[rowKey]) {
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
// field.
cond := c.Args[rowKey].(*pql.Condition)
if isString(cond.Value) {
switch cond.Op {
case pql.EQ, pql.NEQ:
id, err := field.TranslateStore().TranslateKey(cond.Value.(string))
if err != nil {
return errors.Wrap(err, "translating key")
}
c.Args[rowKey] = &pql.Condition{
Op: cond.Op,
Value: id,
}
default:
return errors.Errorf("conditional is not supported with string predicates: %s", cond.Op)
}
}
} else if c.Args[rowKey] != nil && !isString(c.Args[rowKey]) {
// allow passing row id directly (this can come in handy, but make sure it is a valid row id)
if !isValidID(c.Args[rowKey]) {
return errors.Errorf("row value must be a string or non-negative integer, but got: %v of %[1]T", c.Args[rowKey])
@ -3854,7 +3874,7 @@ func (e *executor) translateResult(index string, idx *Index, call *pql.Call, res
// In the case where a field/foreignIndex doesn't exist,
// fall back to using the index translateStore.
if store == nil && idx.Keys() {
store = idx.translateStore
store = nil // TODO: this may need to be idx.TranslateStore(?)
}
if store != nil {

View file

@ -3912,6 +3912,7 @@ func TestExecutor_ForeignIndex(t *testing.T) {
t.Fatalf("unexpected columns: %v", neq.Columns())
}
// TODO: this test is failing because field `color` is being associated to index `parent`
join := c.Query(t, "parent", `Intersect(Row(general=3), Distinct(Row(color="blue"), index="child", field="parent_id"))`).Results[0].(*pilosa.Row)
if !reflect.DeepEqual(join.Keys, []string{"one"}) {
t.Fatalf("unexpected keys: %v", join.Keys)

View file

@ -565,7 +565,7 @@ func (f *Field) applyForeignIndex() error {
return errors.Wrapf(ErrForeignIndexNotFound, "%s", f.options.ForeignIndex)
} else if foreignIndex.Keys() {
f.usesKeys = true
f.translateStore = foreignIndex.translateStore
f.translateStore = foreignIndex.TranslateStore(0) // TODO: this is wrong
return nil
}
return f.applyTranslateStore()