Skip to content

Commit

Permalink
sql: add an aggregate test for smaller integers.
Browse files Browse the repository at this point in the history
  • Loading branch information
knz committed Aug 20, 2016
1 parent 4eed37e commit e4892bf
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions sql/parser/aggregate_builtins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ func makeIntTestDatum(count int) []Datum {
return vals
}

// makeSmallIntTestDatum creates integers that are sufficiently
// smaller than 2^64-1 that they can be added to each other for a
// significant part of the test without overflow. This is meant to
// test the implementation of aggregates that can use an int64 to
// optimize computations small decimal values.
func makeSmallIntTestDatum(count int) []Datum {
rng, _ := randutil.NewPseudoRand()

vals := make([]Datum, count)
for i := range vals {
sign := int32(1)
if 0 == rng.Int31()&1 {
sign = -1
}
vals[i] = NewDInt(DInt(rng.Int31() * sign))
}
return vals
}

func makeFloatTestDatum(count int) []Datum {
rng, _ := randutil.NewPseudoRand()

Expand Down Expand Up @@ -72,6 +91,10 @@ func BenchmarkAvgAggregateInt1K(b *testing.B) {
runBenchmarkAggregate(b, newAvgAggregate, makeIntTestDatum(1000))
}

func BenchmarkAvgAggregateSmallInt1K(b *testing.B) {
runBenchmarkAggregate(b, newAvgAggregate, makeSmallIntTestDatum(1000))
}

func BenchmarkAvgAggregateFloat1K(b *testing.B) {
runBenchmarkAggregate(b, newAvgAggregate, makeFloatTestDatum(1000))
}
Expand All @@ -88,6 +111,10 @@ func BenchmarkSumAggregateInt1K(b *testing.B) {
runBenchmarkAggregate(b, newSumAggregate, makeIntTestDatum(1000))
}

func BenchmarkSumAggregateSmallInt1K(b *testing.B) {
runBenchmarkAggregate(b, newSumAggregate, makeSmallIntTestDatum(1000))
}

func BenchmarkSumAggregateFloat1K(b *testing.B) {
runBenchmarkAggregate(b, newSumAggregate, makeFloatTestDatum(1000))
}
Expand Down

0 comments on commit e4892bf

Please sign in to comment.