From 67233d572096ccadd5d9be264b1ded93c8122434 Mon Sep 17 00:00:00 2001 From: Samir Patel <48686912+54mir@users.noreply.github.com> Date: Thu, 4 Nov 2021 15:52:37 -0500 Subject: [PATCH] move checks to api.go --- api.go | 9 +++++++++ http/handler.go | 11 ----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/api.go b/api.go index b954d9268..5aba8d272 100644 --- a/api.go +++ b/api.go @@ -1688,6 +1688,15 @@ func (api *API) ImportValueWithTx(ctx context.Context, qcx *Qcx, req *ImportValu return errors.Wrap(err, "validating api method") } + numCols := len(req.ColumnIDs) + len(req.ColumnKeys) + numVals := len(req.Values) + len(req.FloatValues) + len(req.TimestampValues) + len(req.StringValues) + if numCols != numVals { + return errors.New(fmt.Sprintf("number of columns (%v) and number of values (%v) do not match", numCols, numVals)) + } + if numCols == 0 { + return nil + } + idx, field, err := api.indexField(req.Index, req.Field, req.Shard) if err != nil { return errors.Wrap(err, fmt.Sprintf("getting index '%v' and field '%v'; shard=%v", req.Index, req.Field, req.Shard)) diff --git a/http/handler.go b/http/handler.go index 28663cc23..59a3c3162 100644 --- a/http/handler.go +++ b/http/handler.go @@ -2721,12 +2721,6 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) { qcx := h.api.Txf().NewQcx() defer qcx.Abort() - if isImportRequestEmpty(req) { - if len(req.ColumnIDs) > 0 || len(req.ColumnKeys) > 0 { - http.Error(w, "columns provided but no values", http.StatusBadRequest) - } - return - } if err := h.api.ImportValue(r.Context(), qcx, req, opts...); err != nil { switch errors.Cause(err) { case pilosa.ErrClusterDoesNotOwnShard, pilosa.ErrPreconditionFailed: @@ -3469,8 +3463,3 @@ func (h *Handler) handlePostRestore(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte("OK")) //nolint:errcheck } - -func isImportRequestEmpty(req *pilosa.ImportValueRequest) bool { - totalData := len(req.Values) + len(req.FloatValues) + len(req.TimestampValues) + len(req.StringValues) - return totalData == 0 -}