diff --git a/field.go b/field.go index c61093569..8c404068c 100644 --- a/field.go +++ b/field.go @@ -1992,14 +1992,18 @@ func (o *FieldOptions) MarshalJSON() ([]byte, error) { }) case FieldTypeTimestamp: return json.Marshal(struct { - Type string `json:"type"` - Epoch time.Time `json:"epoch"` - BitDepth uint64 `json:"bitDepth"` - TimeUnit string `json:"timeUnit"` + Type string `json:"type"` + Epoch time.Time `json:"epoch"` + BitDepth uint64 `json:"bitDepth"` + Min pql.Decimal `json:"min"` + Max pql.Decimal `json:"max"` + TimeUnit string `json:"timeUnit"` }{ o.Type, time.Unix(0, o.Base*TimeUnitNanos(o.TimeUnit)).UTC(), o.BitDepth, + o.Min, + o.Max, o.TimeUnit, }) case FieldTypeTime: diff --git a/field_test.go b/field_test.go index 000a18371..40697addb 100644 --- a/field_test.go +++ b/field_test.go @@ -2,11 +2,14 @@ package pilosa_test import ( + "bytes" + "encoding/json" "math" "testing" "github.com/google/go-cmp/cmp" - "github.com/molecula/featurebase/v3" + pilosa "github.com/molecula/featurebase/v3" + "github.com/molecula/featurebase/v3/pql" "github.com/molecula/featurebase/v3/roaring" "github.com/molecula/featurebase/v3/test" "github.com/molecula/featurebase/v3/testhook" @@ -271,3 +274,19 @@ func TestField_ClearValue(t *testing.T) { } }) } + +func TestFieldInfoMarshal(t *testing.T) { + f := &pilosa.FieldInfo{Name: "timestamp", CreatedAt: 1649270079233541000, + Options: pilosa.FieldOptions{Base: 0, BitDepth: 0x0, Min: pql.Decimal{Value: -4294967296, + Scale: 0}, Max: pql.Decimal{Value: 4294967296, Scale: 0}, Scale: 0, Keys: false, + NoStandardView: false, CacheType: "", Type: "timestamp", TimeUnit: "s", + TimeQuantum: "", ForeignIndex: "", Ttl: 0}, Cardinality: (*uint64)(nil)} + a, err := json.Marshal(f) + if err != nil { + t.Fatalf("unexpected error marshalling index info, %v", err) + } + expected := []byte(`{"name":"timestamp","createdAt":1649270079233541000,"options":{"type":"timestamp","epoch":"1970-01-01T00:00:00Z","bitDepth":0,"min":-4294967296,"max":4294967296,"timeUnit":"s"}}`) + if bytes.Compare(a, expected) != 0 { + t.Fatalf("expected %s, got %s", expected, a) + } +} diff --git a/qa/testcases/bug-repros/fb-1332-datagen.yaml b/qa/testcases/bug-repros/fb-1332-datagen.yaml new file mode 100644 index 000000000..b4ab21d15 --- /dev/null +++ b/qa/testcases/bug-repros/fb-1332-datagen.yaml @@ -0,0 +1,57 @@ +fields: + - name: "id" + type: uint + step: 1 + distribution: "sequential" + min: 1 + max: 200 + - name: "segid" + type: "int" # (default IntField) + min: 0 + max: 3 + distribution: "zipfian" + s: 1.1 + v: 5.1 + - name: "ts" + type: "timestamp" + min_date: 2006-01-02T15:04:05.001Z # RFC3339Nano + max_date: 2022-01-02T15:04:05.001Z # RFC3339Nano + distribution: "increasing" # only "increasing" is supported right now + min_step_duration: "1ms" + max_step_duration: "200ms" + - name: "lastupdated" + type: "timestamp" + min_date: 2006-01-02T15:04:05.001Z # RFC3339Nano + max_date: 2022-01-02T15:04:05.001Z # RFC3339Nano + distribution: "increasing" # only "increasing" is supported right now + min_step_duration: "1ms" + max_step_duration: "200ms" + - name: "slice" + type: "uint-set" # (default IDArrayField) + min: 0 + max: 35000 + distribution: "zipfian" + s: 1.1 + v: 5.1 + min_num: 1 + max_num: 50 + +idk_params: + primary_key_config: + field: "id" + fields: + segid: + - type: "ID" + ts: + - type: "RecordTime" + layout: "2006-01-02T15:04:05Z" + epoch: 1970-01-01T00:00:00.0Z + name: "na" + - type: "Timestamp" + layout: "2006-01-02T15:04:05Z" + epoch: 1970-01-01T00:00:00.0Z + name: "last_update" + granularity: "s" + slice: + - type: "IDArray" + time_quantum: "D" diff --git a/qa/testcases/bug-repros/fb-1332.sh b/qa/testcases/bug-repros/fb-1332.sh new file mode 100644 index 000000000..b1d5b50ad --- /dev/null +++ b/qa/testcases/bug-repros/fb-1332.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# datagen some timestamps onto DATANODE0 in index fb_1332_test +/data/datagen_linux_arm64 -s custom --custom-config=./fb-1332-datagen.yaml --pilosa.index=fb1332 --pilosa.batch-size=100 --pilosa.hosts=$1 +if (( $? != 0 )); then + echo "couldn't datagen" + exit 1 +fi + +# take a backup +featurebase backup --host=$1 -o=fb1332.bak --index=fb1332 +if (( $? != 0 )); then + echo "couldn't backup" + exit 1 +fi + +# delete that index +if [[ $( curl -XDELETE $1/index/fb1332| jq '.error' ) != "null" ]]; then + echo "couldn't delete index" + exit 1 +fi + +# fb restore +featurebase restore --host=$1 -s=fb1332.bak +if (( $? != 0 )); then + echo "couldn't restore" + exit 1 +fi + + +# datagen some more +/data/datagen_linux_arm64 -s custom --custom-config=./fb-1332-datagen.yaml --pilosa.index=fb1332 --pilosa.batch-size=100 --pilosa.hosts=$1 +if (( $? != 0 )); then + echo "couldn't ingest a second time" + exit 1 +fi