mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-06 00:25:55 +00:00
Merge pull request #2008 from molecula/FB-1332
Timestamp FieldOptions should include Min and Max when marshalled to …
This commit is contained in:
commit
8fc70e6494
4 changed files with 121 additions and 5 deletions
12
field.go
12
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:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
57
qa/testcases/bug-repros/fb-1332-datagen.yaml
Normal file
57
qa/testcases/bug-repros/fb-1332-datagen.yaml
Normal file
|
|
@ -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"
|
||||
36
qa/testcases/bug-repros/fb-1332.sh
Normal file
36
qa/testcases/bug-repros/fb-1332.sh
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue