Skip to content

Commit

Permalink
fields: add Lead and Lag fields to ItemAggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
smyrman committed Oct 26, 2023
1 parent 0a8e25f commit 6711ddc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion fields/data_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func DataAnd(filters ...DataFilter) DataFilter {
// Use greatest non-zero times.$gte value.
switch {
case f.filter.Times.GreaterOrEqual.IsZero():
//pass
// pass
case result.filter.Times.GreaterOrEqual.IsZero(), f.filter.Times.GreaterOrEqual.After(result.filter.Times.GreaterOrEqual):
result.filter.Times.GreaterOrEqual = f.filter.Times.GreaterOrEqual
}
Expand Down
16 changes: 10 additions & 6 deletions fields/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ func (m *AggregateMethod) UnmarshalText(data []byte) error {
}

type ItemAggregation struct {
Alias string `json:"alias"`
ID string `json:"id"`
Aggregation AggregateMethod `json:"aggregation"`
Alias string `json:"alias,omitempty"`
ID string `json:"id,omitempty"`
Aggregation AggregateMethod `json:"aggregation,omitempty"`
State int `json:"state"`
Lead int `json:"lead,omitempty"`
Lag int `json:"lag,omitempty"`
}

var _ json.Marshaler = ItemAggregation{}
Expand All @@ -114,10 +116,12 @@ func (ia ItemAggregation) MarshalJSON() ([]byte, error) {
v = encType(ia)
default:
type encType struct {
Alias string `json:"alias"`
ID string `json:"id"`
Aggregation AggregateMethod `json:"aggregation"`
Alias string `json:"alias,omitempty"`
ID string `json:"id,omitempty"`
Aggregation AggregateMethod `json:"aggregation,omitempty"`
State int `json:"-"`
Lead int `json:"lead,omitempty"`
Lag int `json:"lag,omitempty"`
}
v = encType(ia)
}
Expand Down
6 changes: 3 additions & 3 deletions fields/timestamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func TestOriginTime(t *testing.T) {
expectTime := time.Date(2000, 01, 03, 0, 0, 0, 0, time.UTC)
expectTime := time.Date(2000, 0o1, 0o3, 0, 0, 0, 0, time.UTC)
if result := fields.OriginTime.Time(); !result.Equal(expectTime) {
t.Errorf("expected OriginZeroTime.Time() equal %v, got %v", expectTime, result)
}
Expand All @@ -34,7 +34,7 @@ func TestOriginTime(t *testing.T) {
}

func TestZeroTime(t *testing.T) {
expectTime := time.Date(1970, 01, 01, 0, 0, 0, 0, time.UTC)
expectTime := time.Date(1970, 0o1, 0o1, 0, 0, 0, 0, time.UTC)
if result := fields.Timestamp(0).Time(); !result.Equal(expectTime) {
t.Errorf("expected Timestamp(0).Time() equal %v, got %v", expectTime, result)
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestTimestampTruncate(t *testing.T) {
}

func FuzzTimestampTruncate(f *testing.F) {
//origTime := time.Date(2000, 01, 03, 0, 0, 0, 0, time.UTC)
// origTime := time.Date(2000, 01, 03, 0, 0, 0, 0, time.UTC)
f.Fuzz(func(t *testing.T, msec, dMsec int64) {
ts := fields.Timestamp(msec)
d := time.Duration(dMsec) * time.Microsecond
Expand Down

0 comments on commit 6711ddc

Please sign in to comment.