fix presentation of timestamps from a groupby pql call

This commit is contained in:
reesporte 2021-11-15 15:59:51 -06:00
parent 96dfe845d3
commit 9e570c9e84
2 changed files with 17 additions and 6 deletions

View file

@ -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
}

View file

@ -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: