mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 03:47:51 +00:00
rework checks and reword incorrect type error message
This commit is contained in:
parent
4ce71eeddf
commit
377c3f3654
1 changed files with 13 additions and 18 deletions
31
executor.go
31
executor.go
|
|
@ -1304,26 +1304,21 @@ func (e *executor) executePercentile(ctx context.Context, qcx *Qcx, index string
|
|||
|
||||
// get nth
|
||||
var nthFloat float64
|
||||
OK := false
|
||||
switch c.Args["nth"].(type) {
|
||||
case pql.Decimal:
|
||||
nthArg, ok := c.Args["nth"].(pql.Decimal)
|
||||
nthFloat = nthArg.Float64()
|
||||
OK = ok
|
||||
case int64:
|
||||
nthArg, ok := c.Args["nth"].(int64)
|
||||
nthFloat = float64(nthArg)
|
||||
OK = ok
|
||||
default:
|
||||
return ValCount{}, errors.Errorf("Percentile(): invalid nth type (%T), should be int64 or pql.Decimal", c.Args["nth"])
|
||||
}
|
||||
if OK {
|
||||
if nthFloat < 0 || nthFloat > 100.0 {
|
||||
return ValCount{}, errors.Errorf("Percentile(): invalid nth value (%f), should be between 0 and 100 inclusive", nthFloat)
|
||||
}
|
||||
} else if c.Args["nth"] == nil {
|
||||
nthArg := c.Args["nth"]
|
||||
if nthArg == nil {
|
||||
return ValCount{}, errors.New("Percentile(): nth required")
|
||||
}
|
||||
switch nthArg.(type) {
|
||||
case pql.Decimal:
|
||||
nthFloat = nthArg.(pql.Decimal).Float64()
|
||||
case int64:
|
||||
nthFloat = float64(nthArg.(int64))
|
||||
default:
|
||||
return ValCount{}, errors.Errorf("Percentile(): invalid nth='%v' of type (%[1]T), should be int64 or pql.Decimal", c.Args["nth"])
|
||||
}
|
||||
if nthFloat < 0 || nthFloat > 100.0 {
|
||||
return ValCount{}, errors.Errorf("Percentile(): invalid nth value (%f), should be between 0 and 100 inclusive", nthFloat)
|
||||
}
|
||||
|
||||
// get field
|
||||
if fieldArg := c.Args["field"]; fieldArg == "" {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue