Merge pull request #981 from jaffee/single-equal-data-race

Fix data race on call map in single '=' logic
This commit is contained in:
Matthew Jaffee 2020-10-15 11:40:16 -05:00 committed by GitHub
commit c859a8aa2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 19 deletions

View file

@ -3174,24 +3174,6 @@ func (e *executor) executeRowShard(ctx context.Context, qcx *Qcx, index string,
}
}
timeNotSet := fromTime.IsZero() && toTime.IsZero()
// This is workaround to support pql.ASSIGN ('=') as condition ('==') for int and decimal fields
if c.Name == "Row" && timeNotSet &&
(f.Type() == FieldTypeInt || f.Type() == FieldTypeDecimal) {
// re-write args as conditions for fieldName
for k, v := range c.Args {
if _, ok := v.(*pql.Condition); k == fieldName && !ok {
c.Args[k] = &pql.Condition{
Op: pql.EQ,
Value: v,
}
return e.executeRowBSIGroupShard(ctx, qcx, index, c, shard)
}
}
}
rowID, rowOK, rowErr := c.UintArg(fieldName)
if rowErr != nil {
return nil, fmt.Errorf("Row() error with arg for row: %v", rowErr)
@ -3200,6 +3182,7 @@ func (e *executor) executeRowShard(ctx context.Context, qcx *Qcx, index string,
}
// Simply return row if times are not set.
timeNotSet := fromTime.IsZero() && toTime.IsZero()
if c.Name == "Row" && timeNotSet {
frag := e.Holder.fragment(index, fieldName, viewStandard, shard)
@ -4882,8 +4865,9 @@ func (e *executor) translateCall(ctx context.Context, indexName string, c *pql.C
}
// Translate row key, if field is specified & key exists.
var field *Field
if fieldName != "" {
field := idx.Field(fieldName)
field = idx.Field(fieldName)
if field == nil {
// Instead of returning ErrFieldNotFound here,
// we just return, and don't attempt the translation.
@ -5037,6 +5021,21 @@ func (e *executor) translateCall(ctx context.Context, indexName string, c *pql.C
}
}
// This is workaround to support pql.ASSIGN ('=') as condition ('==') for int and decimal fields
if c.Name == "Row" && field != nil &&
(field.Type() == FieldTypeInt || field.Type() == FieldTypeDecimal) {
// re-write args as conditions for fieldName
for k, v := range c.Args {
if _, ok := v.(*pql.Condition); k == fieldName && !ok {
c.Args[k] = &pql.Condition{
Op: pql.EQ,
Value: v,
}
break
}
}
}
return nil
}

View file

@ -2471,6 +2471,13 @@ func TestExecutor_Execute_Row_BSIGroup(t *testing.T) {
} else if got, exp := result.Results[0].(*pilosa.Row).Columns(), []uint64{50, (5 * ShardWidth) + 100}; !reflect.DeepEqual(exp, got) {
t.Fatalf("Query().Row.Columns=%#v, expected %#v", got, exp)
}
// EQ (single = form) <int>
if result, err := c.GetNode(0).API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Row(foo = 20)`}); err != nil {
t.Fatal(err)
} else if got, exp := result.Results[0].(*pilosa.Row).Columns(), []uint64{50, (5 * ShardWidth) + 100}; !reflect.DeepEqual(exp, got) {
t.Fatalf("Query().Row.Columns=%#v, expected %#v", got, exp)
}
})
t.Run("NEQ", func(t *testing.T) {