finish translate-if-exists

This commit is contained in:
Nia Weiss 2020-10-22 10:23:18 -04:00
parent a74eda1eb0
commit b0a588f8dd
No known key found for this signature in database
GPG key ID: 895E83409BFDA1BB
3 changed files with 10 additions and 75 deletions

View file

@ -2505,17 +2505,6 @@ func (c *cluster) setStatic(hosts []string) error {
return nil
}
// translateFieldKey gets a single key from translateFieldKeys.
func (c *cluster) translateFieldKey(ctx context.Context, field *Field, key string, writable bool) (uint64, error) {
ids, err := c.translateFieldKeys(ctx, field, []string{key}, writable)
if err != nil {
return 0, err
} else if len(ids) == 0 {
return 0, nil
}
return ids[0], nil
}
// translateFieldKeys is basically a wrapper around
// field.TranslateStore().TranslateKey(key), but in
// the case where the local node is not coordinator, then this method will forward the translation

View file

@ -523,7 +523,7 @@ func (e *executor) execute(ctx context.Context, qcx *Qcx, index string, q *pql.Q
// Apply call translation.
if !opt.Remote {
translated, err := e.translateCallNew(call, index, colTranslations, rowTranslations)
translated, err := e.translateCall(call, index, colTranslations, rowTranslations)
if err != nil {
return nil, errors.Wrap(err, "translating call")
}
@ -4286,7 +4286,7 @@ func (e *executor) executeBulkSetRowAttrs(ctx context.Context, qcx *Qcx, index s
// Apply call translation.
if !opt.Remote {
translated, err := e.translateCallNew(c, index, colTranslations, rowTranslations)
translated, err := e.translateCall(c, index, colTranslations, rowTranslations)
if err != nil {
return nil, errors.Wrap(err, "translating call")
}
@ -4707,7 +4707,7 @@ func (e *executor) preTranslate(ctx context.Context, index string, calls ...*pql
findRows: make(map[string]map[string][]string),
}
for _, call := range calls {
err := e.collectCallKeysNew(&collector, call, index)
err := e.collectCallKeys(&collector, call, index)
if err != nil {
return nil, nil, err
}
@ -4790,7 +4790,7 @@ func (e *executor) preTranslate(ctx context.Context, index string, calls ...*pql
return cols, rows, nil
}
func (e *executor) collectCallKeysNew(dst *keyCollector, c *pql.Call, index string) error {
func (e *executor) collectCallKeys(dst *keyCollector, c *pql.Call, index string) error {
// Check for an overriding 'index' argument.
// This also applies to all child calls.
if callIndex := c.CallIndex(); callIndex != "" {
@ -4941,7 +4941,7 @@ func (e *executor) collectCallKeysNew(dst *keyCollector, c *pql.Call, index stri
// Collect keys from child calls.
for _, child := range c.Children {
err := e.collectCallKeysNew(dst, child, index)
err := e.collectCallKeys(dst, child, index)
if err != nil {
return err
}
@ -4954,7 +4954,7 @@ func (e *executor) collectCallKeysNew(dst *keyCollector, c *pql.Call, index stri
continue
}
err := e.collectCallKeysNew(dst, argCall, index)
err := e.collectCallKeys(dst, argCall, index)
if err != nil {
return err
}
@ -5082,7 +5082,7 @@ func fieldValidateValue(f *Field, val interface{}) error {
return nil
}
func (e *executor) translateCallNew(c *pql.Call, index string, columnKeys map[string]map[string]uint64, rowKeys map[string]map[string]map[string]uint64) (*pql.Call, error) {
func (e *executor) translateCall(c *pql.Call, index string, columnKeys map[string]map[string]uint64, rowKeys map[string]map[string]map[string]uint64) (*pql.Call, error) {
// Check for an overriding 'index' argument.
// This also applies to all child calls.
if callIndex := c.CallIndex(); callIndex != "" {
@ -5305,7 +5305,7 @@ func (e *executor) translateCallNew(c *pql.Call, index string, columnKeys map[st
// Translate child calls.
for i, child := range c.Children {
translated, err := e.translateCallNew(child, index, columnKeys, rowKeys)
translated, err := e.translateCall(child, index, columnKeys, rowKeys)
if err != nil {
return nil, err
}
@ -5319,7 +5319,7 @@ func (e *executor) translateCallNew(c *pql.Call, index string, columnKeys map[st
continue
}
translated, err := e.translateCallNew(argCall, index, columnKeys, rowKeys)
translated, err := e.translateCall(argCall, index, columnKeys, rowKeys)
if err != nil {
return nil, err
}
@ -6203,18 +6203,6 @@ func (vc *ValCount) floatLarger(other ValCount) ValCount {
}
}
func callArgBool(call *pql.Call, key string) (bool, error) {
value, ok := call.Args[key]
if !ok {
return false, errors.New("missing bool argument")
}
b, ok := value.(bool)
if !ok {
return false, fmt.Errorf("invalid bool argument type: %T", value)
}
return b, nil
}
func callArgString(call *pql.Call, key string) string {
value, ok := call.Args[key]
if !ok {
@ -6224,39 +6212,6 @@ func callArgString(call *pql.Call, key string) string {
return s
}
func isString(v interface{}) bool {
_, ok := v.(string)
return ok
}
func isCondition(v interface{}) bool {
_, ok := v.(*pql.Condition)
return ok
}
// isValidID returns whether v can be interpreted as a valid row or
// column ID. In short, is v a non-negative integer? I think the int64
// and default cases are the only ones actually used since the PQL
// parser doesn't return any other integer types.
func isValidID(v interface{}) bool {
switch vt := v.(type) {
case uint, uint64, uint32, uint16, uint8:
return true
case int64:
return vt >= 0
case int:
return vt >= 0
case int32:
return vt >= 0
case int16:
return vt >= 0
case int8:
return vt >= 0
default:
return false
}
}
// groupByIterator contains several slices. Each slice contains a number of
// elements equal to the number of fields in the group by (the number of Rows
// calls).

View file

@ -84,7 +84,7 @@ func TestExecutor_TranslateRowsOnBool(t *testing.T) {
if err != nil {
t.Fatalf("pre-translating call: %v", err)
}
_, err = e.translateCallNew(c, "i", colTranslations, rowTranslations)
_, err = e.translateCall(c, "i", colTranslations, rowTranslations)
if err != nil {
t.Fatalf("translating call: %v", err)
}
@ -92,15 +92,6 @@ func TestExecutor_TranslateRowsOnBool(t *testing.T) {
}
}
func isInt(a interface{}) bool {
switch a.(type) {
case int, int64, uint, uint64:
return true
default:
return false
}
}
func TestFilterWithLimit(t *testing.T) {
f := filterWithLimit(5)