Skip to content

Commit

Permalink
Revert "Dev measure aggregate function"
Browse files Browse the repository at this point in the history
  • Loading branch information
StLeoX committed Sep 5, 2024
1 parent 5bfbb47 commit d2f29ed
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 545 deletions.
24 changes: 0 additions & 24 deletions banyand/measure/aggregate/aggregate_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,8 @@ func NewFunction[A, B Input, R Output](kind modelv1.MeasureAggregate) (Function[
switch kind {
case modelv1.MeasureAggregate_MEASURE_AGGREGATE_MIN:
function = &Min[A, B, R]{minimum: maxValue[R]()}
case modelv1.MeasureAggregate_MEASURE_AGGREGATE_MAX:
function = &Max[A, B, R]{maximum: minValue[R]()}
case modelv1.MeasureAggregate_MEASURE_AGGREGATE_COUNT:
function = &Count[A, B, R]{count: 0}
case modelv1.MeasureAggregate_MEASURE_AGGREGATE_SUM:
function = &Sum[A, B, R]{summation: zeroValue[R]()}
case modelv1.MeasureAggregate_MEASURE_AGGREGATE_AVG:
function = &Avg[A, B, R]{summation: zeroValue[R](), count: 0}
case modelv1.MeasureAggregate_MEASURE_AGGREGATE_PERCENT:
function = &Percent[A, B, R]{total: 0, match: 0}
case modelv1.MeasureAggregate_MEASURE_AGGREGATE_RATE:
function = &Rate[A, B, R]{denominator: 0, numerator: 0}
default:
return nil, fmt.Errorf("MeasureAggregate unknown")
}
Expand All @@ -86,20 +76,6 @@ func zeroValue[R Output]() R {
return r
}

func minValue[R Output]() (r R) {
switch a := any(&r).(type) {
case *int64:
*a = math.MinInt64
case *float64:
*a = -math.MaxFloat64
case *string:
*a = ""
default:
panic("unreachable")
}
return
}

func maxValue[R Output]() (r R) {
switch a := any(&r).(type) {
case *int64:
Expand Down
18 changes: 9 additions & 9 deletions banyand/measure/aggregate/avg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ type Avg[A, B Input, R Output] struct {
}

// Combine takes elements to do the aggregation.
// Avg uses type parameter A.
func (f *Avg[A, B, R]) Combine(arguments Arguments[A, B]) error {
// Avg uses type parameter A and B.
func (a *Avg[A, B, R]) Combine(arguments Arguments[A, B]) error {
for _, arg0 := range arguments.arg0 {
switch arg0 := any(arg0).(type) {
case int64:
f.summation += R(arg0)
a.summation += R(arg0)
case float64:
f.summation += R(arg0)
a.summation += R(arg0)
default:
return errFieldValueType
}
Expand All @@ -40,7 +40,7 @@ func (f *Avg[A, B, R]) Combine(arguments Arguments[A, B]) error {
for _, arg1 := range arguments.arg1 {
switch arg1 := any(arg1).(type) {
case int64:
f.count += arg1
a.count += arg1
default:
return errFieldValueType
}
Expand All @@ -50,14 +50,14 @@ func (f *Avg[A, B, R]) Combine(arguments Arguments[A, B]) error {
}

// Result gives the result for the aggregation.
func (f *Avg[A, B, R]) Result() R {
func (a *Avg[A, B, R]) Result() R {
// In unusual situations it returns the zero value.
if f.count == 0 {
if a.count == 0 {
return zeroValue[R]()
}
// According to the semantics of GoLang, the division of one int by another int
// returns an int, instead of f float.
return f.summation / R(f.count)
// returns an int, instead of a float.
return a.summation / R(a.count)
}

// NewAvgArguments constructs arguments.
Expand Down
50 changes: 0 additions & 50 deletions banyand/measure/aggregate/count.go

This file was deleted.

39 changes: 0 additions & 39 deletions banyand/measure/aggregate/count_test.go

This file was deleted.

56 changes: 0 additions & 56 deletions banyand/measure/aggregate/max.go

This file was deleted.

47 changes: 0 additions & 47 deletions banyand/measure/aggregate/max_test.go

This file was deleted.

14 changes: 7 additions & 7 deletions banyand/measure/aggregate/min.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ type Min[A, B Input, R Output] struct {

// Combine takes elements to do the aggregation.
// Min uses type parameter A.
func (f *Min[A, B, R]) Combine(arguments Arguments[A, B]) error {
func (m *Min[A, B, R]) Combine(arguments Arguments[A, B]) error {
for _, arg0 := range arguments.arg0 {
switch arg0 := any(arg0).(type) {
case int64:
if R(arg0) < f.minimum {
f.minimum = R(arg0)
if R(arg0) < m.minimum {
m.minimum = R(arg0)
}
case float64:
if R(arg0) < f.minimum {
f.minimum = R(arg0)
if R(arg0) < m.minimum {
m.minimum = R(arg0)
}
default:
return errFieldValueType
Expand All @@ -43,8 +43,8 @@ func (f *Min[A, B, R]) Combine(arguments Arguments[A, B]) error {
}

// Result gives the result for the aggregation.
func (f *Min[A, B, R]) Result() R {
return f.minimum
func (m *Min[A, B, R]) Result() R {
return m.minimum
}

// NewMinArguments constructs arguments.
Expand Down
67 changes: 0 additions & 67 deletions banyand/measure/aggregate/percent.go

This file was deleted.

Loading

0 comments on commit d2f29ed

Please sign in to comment.