From 43b34c7d844d4f7e3cac51e2ae4e29284e58dbcf Mon Sep 17 00:00:00 2001 From: rachithrr Date: Thu, 2 Sep 2021 08:59:21 -0400 Subject: [PATCH] CORE-747: Build tooling to provide datagen-like functionality that uses the API Featurebase --- client/client.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/client/client.go b/client/client.go index dc97b008b..cac4b9ec3 100644 --- a/client/client.go +++ b/client/client.go @@ -33,14 +33,14 @@ import ( "time" "github.com/golang/protobuf/proto" //nolint:staticcheck - "github.com/opentracing/opentracing-go" - "github.com/molecula/featurebase/v2" + pilosa "github.com/molecula/featurebase/v2" "github.com/molecula/featurebase/v2/logger" pnet "github.com/molecula/featurebase/v2/net" "github.com/molecula/featurebase/v2/pb" "github.com/molecula/featurebase/v2/pql" "github.com/molecula/featurebase/v2/roaring" "github.com/molecula/featurebase/v2/stats" + "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "golang.org/x/sync/errgroup" ) @@ -779,6 +779,34 @@ func (c *Client) readSchema() ([]SchemaIndex, error) { return schemaInfo.Indexes, nil } +func (c *Client) IngestSchema(reqBody map[string]interface{}) (body []byte, err error) { + data, err := json.Marshal(reqBody) + if err != nil { + return data, errors.Wrap(err, " error building Schema body to Ingest") + } + return c.IngestRequest("/internal/schema", data) +} + +func (c *Client) IngestData(index string, reqBody []map[string]interface{}) (body []byte, err error) { + data, err := json.Marshal(reqBody) + if err != nil { + return data, errors.Wrap(err, " error building request body to Ingest") + } + return c.IngestRequest("/internal/ingest/"+index, data) +} + +func (c *Client) IngestRequest(Uri string, data []byte) (body []byte, err error) { + var header = make(map[string]string) + header["Content-Type"] = "application/json" + header["Accept"] = "application/json" + header["User-Agent"] = "pilosa/" + pilosa.Version + _, body, err = c.HTTPRequest("POST", Uri, data, header) + if err != nil { + return nil, errors.Wrap(err, "requesting "+Uri) + } + return body, err +} + func (c *Client) shardsMax() (map[string]uint64, error) { _, data, err := c.HTTPRequest("GET", "/internal/shards/max", nil, nil) if err != nil {