From 4f86b2be830a6cbc09763198c0df7583cf8322ba Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Fri, 6 Jul 2018 17:32:04 -0500 Subject: [PATCH 1/3] fix test that differed based on map key order --- executor.go | 24 +++++++++++++++--------- executor_test.go | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/executor.go b/executor.go index afea60112..4e2705b00 100644 --- a/executor.go +++ b/executor.go @@ -1059,6 +1059,16 @@ func (e *executor) executeClearBitField(ctx context.Context, index string, c *pq // executeSet executes a Set() call. func (e *executor) executeSet(ctx context.Context, index string, c *pql.Call, opt *execOptions) (bool, error) { + + // Read colID. + colID, ok, err := c.UintArg("_" + columnLabel) + if err != nil { + return false, fmt.Errorf("reading Set() column: %v", err) + } else if !ok { + return false, fmt.Errorf("Set() column argument '%v' required", columnLabel) + } + + // Read field name. fieldName, err := c.FieldArg() if err != nil { return false, errors.New("Set() argument required: field") @@ -1074,14 +1084,6 @@ func (e *executor) executeSet(ctx context.Context, index string, c *pql.Call, op return false, ErrFieldNotFound } - // Read colID using labels. - colID, ok, err := c.UintArg("_" + columnLabel) - if err != nil { - return false, fmt.Errorf("reading Set() column: %v", err) - } else if !ok { - return false, fmt.Errorf("Set() column argument '%v' required", columnLabel) - } - if f.Type() == FieldTypeInt { // Read remaining fields using labels. rowVal, ok, err := c.IntArg(fieldName) @@ -1575,7 +1577,11 @@ func (e *executor) translateCall(index string, idx *Index, c *pql.Call) error { if fieldName != "" { field := idx.Field(fieldName) if field == nil { - return ErrFieldNotFound + // Instead of returning ErrFieldNotFound here, + // we just return, and don't attempt the translation. + // The assumption is that the non-existant field + // will raise an error downstream when it's used. + return nil } if field.keys() { if c.Args[rowKey] != nil && !isString(c.Args[rowKey]) { diff --git a/executor_test.go b/executor_test.go index 41341b814..6e01f111f 100644 --- a/executor_test.go +++ b/executor_test.go @@ -440,7 +440,7 @@ func TestExecutor_Execute_SetValue(t *testing.T) { } t.Run("ErrColumnBSIGroupRequired", func(t *testing.T) { - if _, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Set(invalid_column_name=10, f=100)`}); err == nil || errors.Cause(err).Error() != `field not found` { + if _, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Set(invalid_column_name=10, f=100)`}); err == nil || errors.Cause(err).Error() != `Set() column argument 'col' required` { t.Fatalf("unexpected error: %s", err) } }) From babdb5ff4e8ea2516c1a0ab73838413d3c8f8cdc Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Fri, 6 Jul 2018 17:38:06 -0500 Subject: [PATCH 2/3] adjust test to account for new source of error downstream --- server/handler_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/handler_test.go b/server/handler_test.go index 9670df2c2..bac09a1cc 100644 --- a/server/handler_test.go +++ b/server/handler_test.go @@ -336,7 +336,7 @@ func TestHandler_Endpoints(t *testing.T) { h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/index/i0/query", strings.NewReader(`Row(row=30)`))) if w.Code != gohttp.StatusBadRequest { t.Fatalf("unexpected status code: %d", w.Code) - } else if body := w.Body.String(); body != `{"error":"executing: field not found"}`+"\n" { + } else if body := w.Body.String(); body != `{"error":"executing: map reduce: field not found"}`+"\n" { t.Fatalf("unexpected body: %q", body) } }) @@ -353,7 +353,7 @@ func TestHandler_Endpoints(t *testing.T) { var resp pilosa.QueryResponse if err := cmd.API.Serializer.Unmarshal(w.Body.Bytes(), &resp); err != nil { t.Fatal(err) - } else if s := resp.Err.Error(); s != `executing: field not found` { + } else if s := resp.Err.Error(); s != `executing: map reduce: field not found` { t.Fatalf("unexpected error: %s", s) } }) From e2406a4b523cc9253d3ef811634e6f9ce3542bcf Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Fri, 6 Jul 2018 17:50:23 -0500 Subject: [PATCH 3/3] fix typo --- executor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor.go b/executor.go index 4e2705b00..43bd06f32 100644 --- a/executor.go +++ b/executor.go @@ -1579,7 +1579,7 @@ func (e *executor) translateCall(index string, idx *Index, c *pql.Call) error { if field == nil { // Instead of returning ErrFieldNotFound here, // we just return, and don't attempt the translation. - // The assumption is that the non-existant field + // The assumption is that the non-existent field // will raise an error downstream when it's used. return nil }