From 002b65c516f6005bd1265d3b53875179e0225ea7 Mon Sep 17 00:00:00 2001 From: Samir Patel <48686912+54mir@users.noreply.github.com> Date: Mon, 1 Nov 2021 17:04:33 -0500 Subject: [PATCH] add checks for data presence on import req --- api.go | 7 ++++++- http/handler.go | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index 458164f6e..b954d9268 100644 --- a/api.go +++ b/api.go @@ -1760,6 +1760,9 @@ func (api *API) ImportValueWithTx(ctx context.Context, qcx *Qcx, req *ImportValu // if we're importing into a specific shard if req.Shard != math.MaxUint64 { + if len(req.ColumnIDs) == 0 { + return errors.Wrap(err, "calculating shard, no columns in request") + } // Check that column IDs match the stated shard. shard := req.ColumnIDs[0] / ShardWidth if s2 := req.ColumnIDs[len(req.ColumnIDs)-1] / ShardWidth; (shard != s2) || (shard != req.Shard) { @@ -1798,7 +1801,9 @@ func (api *API) ImportValueWithTx(ctx context.Context, qcx *Qcx, req *ImportValu return errors.Wrap(err, "importing value") } // end if req.Shard != math.MaxUint64 - + if len(req.ColumnIDs) == 0 { + return errors.Wrap(err, "calculating shard, no columns in request") + } options.IgnoreKeyCheck = true start := 0 shard := req.ColumnIDs[0] / ShardWidth diff --git a/http/handler.go b/http/handler.go index 59a3c3162..92f374e84 100644 --- a/http/handler.go +++ b/http/handler.go @@ -2721,6 +2721,10 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) { qcx := h.api.Txf().NewQcx() defer qcx.Abort() + if len(req.Values) == 0 { + return + } + if err := h.api.ImportValue(r.Context(), qcx, req, opts...); err != nil { switch errors.Cause(err) { case pilosa.ErrClusterDoesNotOwnShard, pilosa.ErrPreconditionFailed: