mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
* unifying idk and featurebase: first pass * resolved conflict with master for gitignore & dockerignore * deleted binaries that were accidentally pushed to git * combined gitlab jobs for idk & featurebase * run go fmt for idk * updated ssh env variable, and made docker password variable in gitlab env variables * fixed typo assigning variable name * trying to fix docker login error * trying a different solution for docker password * pass registry * fixed docker login * updated paths for idk * exclude idk tests from featurebase test run * fix vendor error * update certificates * grpc needs to be in version 1.38 genproto, which is imported by big query updates the grpc version to 1.47.0 grpc 1.47.0 causes etcd to deadlock when calling etcd.Close() the fix is to have a replace in go.mod to specify a specific grpc version * run go mod tidy * go mod * run go mod tidy * exclude bigquery since it is causing issues and undo grpc replace in go.mod * fix grpc version * fix formatting error * update formatting * attempt to fix formatting * update path for code coverage * update to use current branch binaries, not master * fix for building idk - path updates * udpate path for binaries * update job dependecies * update docker idk tests to use the current branch registry * update stages for jobs * updated job dependencies * not allow idk s3 dump to fail since it is a dependency for integration tests * update dependecy for idk tests * update paths for idk build and code coverage * download featurebase binary from s3 * pass branch name to all setup scripts * change to current branch instead of master * updated sonarcloud * sonarcloud fix and branch name fix * trying to speed up pipeline run time * update stage * branch name fix + sonar cloud * sonarcloud
84 lines
2.1 KiB
Go
84 lines
2.1 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// newJSONCodec creates a codec to stream a JSON array of objects, each of which represents a record.
|
|
// This returns an error if the data stream does not contain the start of a valid JSON array.
|
|
func newJSONCodec(r io.Reader) (*jsonCodec, error) {
|
|
// Create a JSON decoder.
|
|
d := json.NewDecoder(r)
|
|
|
|
// Enable the json.Number type in parsed output.
|
|
// This allows us to retain precision on numbers, rather than converting them to floating point.
|
|
d.UseNumber()
|
|
|
|
// Do not allow unknown fields.
|
|
d.DisallowUnknownFields()
|
|
|
|
// Read the opening bracket of the array.
|
|
token, err := d.Token()
|
|
if err != nil {
|
|
if err == io.EOF {
|
|
// The input included nothing (except maybe whitespace).
|
|
// This is not expected.
|
|
err = io.ErrUnexpectedEOF
|
|
}
|
|
return nil, errors.Wrap(err, "parsing start of JSON data")
|
|
}
|
|
switch token {
|
|
case json.Delim('['):
|
|
// This is the start of the array of records.
|
|
|
|
case json.Delim('{'):
|
|
// The input is a JSON object instead of an array.
|
|
// This seems like an easy user error, so provide a descriptive error.
|
|
return nil, errors.New("expected an array of records but found an object")
|
|
|
|
default:
|
|
// This is a number or something.
|
|
return nil, errors.Errorf("expected array of records but got %v", token)
|
|
}
|
|
|
|
return &jsonCodec{d: d}, nil
|
|
}
|
|
|
|
type record struct {
|
|
PrimaryKey interface{} `json:"primary-key"`
|
|
Values map[string]interface{} `json:"values"`
|
|
}
|
|
|
|
type jsonCodec struct {
|
|
d *json.Decoder
|
|
}
|
|
|
|
func (c *jsonCodec) Next() (record, error) {
|
|
if !c.d.More() {
|
|
// There are no more records in the stream.
|
|
// Read the ']'.
|
|
_, err := c.d.Token()
|
|
if err != nil {
|
|
if err == io.EOF {
|
|
// If the closing bracket is missing, then the stream was terminated prematurely.
|
|
err = io.ErrUnexpectedEOF
|
|
}
|
|
return record{}, errors.Wrap(err, "parsing end of record array")
|
|
}
|
|
|
|
// There are no more records.
|
|
return record{}, io.EOF
|
|
}
|
|
|
|
// Parse the record.
|
|
var r record
|
|
err := c.d.Decode(&r)
|
|
if err != nil {
|
|
return record{}, errors.Wrap(err, "parsing record")
|
|
}
|
|
|
|
return r, nil
|
|
}
|