From 19df3211f945a0c50766fea69b9e120e34ba5314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Podg=C3=B3rski?= Date: Wed, 6 May 2020 22:09:08 +0200 Subject: [PATCH] get rid of rowID from groupby on ints response --- encoding/proto/proto.go | 26 ++++++++++---------------- executor.go | 20 ++++++++++---------- executor_test.go | 8 ++++---- 3 files changed, 24 insertions(+), 30 deletions(-) diff --git a/encoding/proto/proto.go b/encoding/proto/proto.go index 678b2d04c..086b5101d 100644 --- a/encoding/proto/proto.go +++ b/encoding/proto/proto.go @@ -1398,14 +1398,13 @@ func decodeFieldRows(a []*internal.FieldRow) []pilosa.FieldRow { for i := range a { fr := a[i] other[i].Field = fr.Field - if fr.RowKey == "" { + if fr.Value != nil { + other[i].Value = &fr.Value.Value + } else if fr.RowKey == "" { other[i].RowID = fr.RowID } else { other[i].RowKey = fr.RowKey } - if fr.Value != nil { - other[i].Value = &fr.Value.Value - } } return other } @@ -1532,19 +1531,14 @@ func encodeFieldRows(a []pilosa.FieldRow) []*internal.FieldRow { other := make([]*internal.FieldRow, len(a)) for i := range a { fr := a[i] - if fr.RowKey == "" { - other[i] = &internal.FieldRow{ - Field: fr.Field, - RowID: fr.RowID, - } - if fr.Value != nil { - other[i].Value = &internal.Int64{Value: *fr.Value} - } + other[i] = &internal.FieldRow{Field: fr.Field} + + if fr.Value != nil { + other[i].Value = &internal.Int64{Value: *fr.Value} + } else if fr.RowKey == "" { + other[i].RowID = fr.RowID } else { - other[i] = &internal.FieldRow{ - Field: fr.Field, - RowKey: fr.RowKey, - } + other[i].RowKey = fr.RowKey } } return other diff --git a/executor.go b/executor.go index 5c882241a..538160cfd 100644 --- a/executor.go +++ b/executor.go @@ -1844,16 +1844,6 @@ type FieldRow struct { // MarshalJSON marshals FieldRow to JSON such that // either a Key or an ID is included. func (fr FieldRow) MarshalJSON() ([]byte, error) { - if fr.RowKey != "" { - return json.Marshal(struct { - Field string `json:"field"` - RowKey string `json:"rowKey"` - }{ - Field: fr.Field, - RowKey: fr.RowKey, - }) - } - if fr.Value != nil { return json.Marshal(struct { Field string `json:"field"` @@ -1864,6 +1854,16 @@ func (fr FieldRow) MarshalJSON() ([]byte, error) { }) } + if fr.RowKey != "" { + return json.Marshal(struct { + Field string `json:"field"` + RowKey string `json:"rowKey"` + }{ + Field: fr.Field, + RowKey: fr.RowKey, + }) + } + return json.Marshal(struct { Field string `json:"field"` RowID uint64 `json:"rowID"` diff --git a/executor_test.go b/executor_test.go index 781fb83e3..c434eaa75 100644 --- a/executor_test.go +++ b/executor_test.go @@ -2886,10 +2886,10 @@ func TestExecutor_Execute_Remote_Row(t *testing.T) { } else { var a, b, c, d int64 = -2, -1, 0, 4 expected := []pilosa.GroupCount{ - {Group: []pilosa.FieldRow{{Field: "fint", RowID: 0, Value: &a}}, Count: 1}, - {Group: []pilosa.FieldRow{{Field: "fint", RowID: 1, Value: &b}}, Count: 1}, - {Group: []pilosa.FieldRow{{Field: "fint", RowID: 2, Value: &c}}, Count: 5}, - {Group: []pilosa.FieldRow{{Field: "fint", RowID: 5, Value: &d}}, Count: 1}, + {Group: []pilosa.FieldRow{{Field: "fint", Value: &a}}, Count: 1}, + {Group: []pilosa.FieldRow{{Field: "fint", Value: &b}}, Count: 1}, + {Group: []pilosa.FieldRow{{Field: "fint", Value: &c}}, Count: 5}, + {Group: []pilosa.FieldRow{{Field: "fint", Value: &d}}, Count: 1}, } results := res.Results[0].([]pilosa.GroupCount)