mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 03:17:50 +00:00
add error message for invalid type
This commit is contained in:
parent
61beef7e5a
commit
8746444cdb
2 changed files with 5 additions and 16 deletions
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue