Merge branch 'master' into paginate

This commit is contained in:
Samir Patel 2022-04-11 14:53:31 -04:00 committed by GitHub
commit 9e69ee3534
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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)
}
}
}