diff --git a/executor.go b/executor.go index 6523ce925..686379609 100644 --- a/executor.go +++ b/executor.go @@ -3064,10 +3064,11 @@ func applyLimitAndOffsetToGroupByResult(c *pql.Call, results []GroupCount) ([]Gr // FieldRow is used to distinguish rows in a group by result. type FieldRow struct { - Field string `json:"field"` - RowID uint64 `json:"rowID"` - RowKey string `json:"rowKey,omitempty"` - Value *int64 `json:"value,omitempty"` + Field string `json:"field"` + RowID uint64 `json:"rowID"` + RowKey string `json:"rowKey,omitempty"` + Value *int64 `json:"value,omitempty"` + FieldOptions *FieldOptions `json:"-"` } func (fr *FieldRow) Clone() (clone *FieldRow) { @@ -3081,6 +3082,11 @@ func (fr *FieldRow) Clone() (clone *FieldRow) { v := *fr.Value clone.Value = &v } + if fr.FieldOptions != nil { + // deep copy, for Extra Safety + v := *fr.FieldOptions + clone.FieldOptions = &v + } return } @@ -7738,6 +7744,8 @@ func newGroupByIterator(executor *executor, qcx *Qcx, rowIDs []RowIDs, children return nil, newNotFoundError(ErrFieldNotFound, fieldName) } gbi.fields[i].Field = fieldName + options := field.Options() + gbi.fields[i].FieldOptions = &options switch field.Type() { case FieldTypeSet, FieldTypeMutex, FieldTypeBool: @@ -7971,7 +7979,6 @@ func (gbi *groupByIterator) Next(ctx context.Context) (ret GroupCount, done bool ret.Group = make([]FieldRow, len(gbi.rows)) copy(ret.Group, gbi.fields) for i, r := range gbi.rows { - ret.Group[i].RowID = r.id ret.Group[i].Value = r.value } diff --git a/server/pg.go b/server/pg.go index 2a55bc3e1..da6dfd633 100644 --- a/server/pg.go +++ b/server/pg.go @@ -331,7 +331,11 @@ func pgWriteGroupCount(w pg.QueryResultWriter, counts *pilosa.GroupCounts) error var v string switch { case g.Value != nil: - v = strconv.FormatInt(*g.Value, 10) + if g.FieldOptions.Type == pilosa.FieldTypeTimestamp { + v = time.Unix(0, (int64(*g.Value)+int64(g.FieldOptions.Base))*pilosa.TimeUnitNanos(g.FieldOptions.TimeUnit)).UTC().Format(time.RFC3339Nano) + } else { + v = strconv.FormatInt(*g.Value, 10) + } case g.RowKey != "": v = g.RowKey default: