mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-11 15:21:02 +00:00
move checks to api.go
This commit is contained in:
parent
c0e201d638
commit
67233d5720
2 changed files with 9 additions and 11 deletions
9
api.go
9
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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue