Implement ToRowser interface for DistinctTimestamp

Because the ToRowser interface was not implemented for DistinctTimestamp, there was
a error when using the GRPC endpoint to call Distinct(All(), field=ts). Implementing
the ToRowser interface for DistinctTimestamp solves that problem.

Related to SUP-210: WebUI, Python - Distinct() does not work for Timestamp field
This commit is contained in:
reesporte 2022-04-08 10:32:02 -05:00
parent 4a155eba88
commit 66def7678c
2 changed files with 91 additions and 0 deletions

View file

@ -1587,6 +1587,34 @@ type DistinctTimestamp struct {
Name string
}
var _ proto.ToRowser = DistinctTimestamp{}
// ToRows implements the ToRowser interface.
func (d DistinctTimestamp) ToRows(callback func(*proto.RowResponse) error) error {
for _, ts := range d.Values {
row := &proto.RowResponse{
Headers: []*proto.ColumnInfo{
{
Name: d.Name,
Datatype: "timestamp",
},
},
Columns: []*proto.ColumnResponse{
{
ColumnVal: &proto.ColumnResponse_TimestampVal{
TimestampVal: ts,
},
},
},
}
if err := callback(row); err != nil {
return errors.Wrap(err, "calling callback")
}
}
return nil
}
// Union returns the union of the values of `d` and `other`
func (d *DistinctTimestamp) Union(other DistinctTimestamp) DistinctTimestamp {
both := map[string]string{}

View file

@ -8546,3 +8546,66 @@ func MinMaxTimestampNodeTester(t *testing.T, numNodes int) {
t.Fatalf("incorrect max timestamp val. expected: %v, got %v\n", expected, min)
}
}
// DistinctTimestamp ToRows should properly encode the timestamp
func TestDistinctTimestampToRows(t *testing.T) {
d := pilosa.DistinctTimestamp{
Values: []string{
"2022-03-24T12:08:37Z",
"2022-03-24T12:08:47Z",
"2022-03-24T12:08:57Z",
},
Name: "timestamp",
}
expectedHeaders := []*proto.ColumnInfo{
{
Name: d.Name,
Datatype: "timestamp",
},
}
expected := []*proto.RowResponse{
{
Headers: expectedHeaders,
Columns: []*proto.ColumnResponse{
{
ColumnVal: &proto.ColumnResponse_TimestampVal{
TimestampVal: "2022-03-24T12:08:37Z",
},
},
},
},
{
Headers: expectedHeaders,
Columns: []*proto.ColumnResponse{
{
ColumnVal: &proto.ColumnResponse_TimestampVal{
TimestampVal: "2022-03-24T12:08:47Z",
},
},
},
},
{
Headers: expectedHeaders,
Columns: []*proto.ColumnResponse{
{
ColumnVal: &proto.ColumnResponse_TimestampVal{
TimestampVal: "2022-03-24T12:08:57Z",
},
},
},
},
}
rows := []*proto.RowResponse{}
d.ToRows(func(r *proto.RowResponse) error {
rows = append(rows, r)
return nil
})
for i, row := range rows {
if !reflect.DeepEqual(row, expected[i]) {
t.Errorf("expected %v, got %v", expected[i], row)
}
}
}