mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-11 15:21:02 +00:00
Merge pull request #1898 from molecula/sup-138
[SUP-138] add timestamp formatting to type FieldRow used in GroupBy
This commit is contained in:
commit
8816583cd3
2 changed files with 40 additions and 7 deletions
25
executor.go
25
executor.go
|
|
@ -3189,13 +3189,24 @@ func (fr *FieldRow) Clone() (clone *FieldRow) {
|
|||
// either a Key or an ID is included.
|
||||
func (fr FieldRow) MarshalJSON() ([]byte, error) {
|
||||
if fr.Value != nil {
|
||||
return json.Marshal(struct {
|
||||
Field string `json:"field"`
|
||||
Value int64 `json:"value"`
|
||||
}{
|
||||
Field: fr.Field,
|
||||
Value: *fr.Value,
|
||||
})
|
||||
if fr.FieldOptions.Type == FieldTypeTimestamp {
|
||||
ts := FormatTimestampNano(int64(*fr.Value), fr.FieldOptions.Base, fr.FieldOptions.TimeUnit)
|
||||
return json.Marshal(struct {
|
||||
Field string `json:"field"`
|
||||
Value string `json:"value"`
|
||||
}{
|
||||
Field: fr.Field,
|
||||
Value: ts,
|
||||
})
|
||||
} else {
|
||||
return json.Marshal(struct {
|
||||
Field string `json:"field"`
|
||||
Value int64 `json:"value"`
|
||||
}{
|
||||
Field: fr.Field,
|
||||
Value: *fr.Value,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if fr.RowKey != "" {
|
||||
|
|
|
|||
|
|
@ -3490,6 +3490,28 @@ func TestExecutor_Execute_Remote_Row(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("json format groupBy on timestamps", func(t *testing.T) {
|
||||
//SUP-138
|
||||
c.CreateField(t, "t", pilosa.IndexOptions{TrackExistence: true}, "timestamp", pilosa.OptFieldTypeTimestamp(pilosa.DefaultEpoch, pilosa.TimeUnitSeconds))
|
||||
c.Query(t, "t", `
|
||||
Set(8, timestamp='2021-01-27T08:00:00Z')
|
||||
Set(9, timestamp='2000-01-27T09:00:00Z')
|
||||
Set(10, timestamp='2000-01-27T10:00:00Z')
|
||||
`)
|
||||
if res, err := c.GetNode(0).API.Query(context.Background(), &pilosa.QueryRequest{
|
||||
Index: "t",
|
||||
Query: `GroupBy(Rows(timestamp))`,
|
||||
}); err != nil {
|
||||
t.Fatalf("GroupBy querying: %v", err)
|
||||
} else {
|
||||
b, _ := res.MarshalJSON()
|
||||
expected := `{"results":[[{"group":[{"field":"timestamp","value":"2000-01-27T09:00:00Z"}],"count":1},{"group":[{"field":"timestamp","value":"2000-01-27T10:00:00Z"}],"count":1},{"group":[{"field":"timestamp","value":"2021-01-27T08:00:00Z"}],"count":1}]]}`
|
||||
if string(b) != expected {
|
||||
t.Fatalf("JSON FORMAT not as expected: %v", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("remote groupBy on ints", func(t *testing.T) {
|
||||
_, err = c.GetPrimary().API.CreateField(context.Background(), "i", "fint", pilosa.OptFieldTypeInt(-1000, 1000))
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue