add error message for invalid type

This commit is contained in:
Maxton Huff 2021-03-25 16:57:08 -05:00
parent 61beef7e5a
commit 8746444cdb
2 changed files with 5 additions and 16 deletions

View file

@ -20,6 +20,7 @@ import (
"fmt"
"math"
"math/bits"
"reflect"
"sort"
"strings"
"sync"
@ -1309,10 +1310,12 @@ func (e *executor) executePercentile(ctx context.Context, qcx *Qcx, index string
case pql.Decimal:
nthFloat = nthArg.Float64()
case int64:
nthFloat = float64(nthArg.Int64())
nthFloat = float64(nthArg.ToInt64(0))
default:
return ValCount{}, errors.Errorf("Percentile(): invalid nth type (%f), should be int64 or pql.Decimal", reflect.TypeOf(nthArg))
}
if nthFloat < 0 || nthFloat > 100.0 {
return ValCount{}, errors.Errorf("Percentile(): invalid nth value(%f), should be >= 0 and <= 100", nthFloat)
return ValCount{}, errors.Errorf("Percentile(): invalid nth value (%f), should be >= 0 and <= 100", nthFloat)
}
} else {
return ValCount{}, errors.New("Percentile(): nth required")

View file

@ -245,20 +245,6 @@ func (d Decimal) Float64() float64 {
return ret
}
// Int64 returns d as a int64.
// TODO: this could very easily lose precision; we should audit
// its use and protect against unexpected results.
func (d Decimal) Int64() int64 {
var ret int64
if d.Scale == 0 {
ret = int64(d.Value)
} else {
temp := float64(d.Value) / math.Pow10(int(d.Scale))
ret = int64(temp)
}
return ret
}
// String returns the string representation of the decimal.
func (d Decimal) String() string {
var s string