mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 20:07:51 +00:00
ensure provided min/max are valid on int fields
This commit is contained in:
parent
739fd9b04b
commit
8c3c774492
2 changed files with 26 additions and 11 deletions
|
|
@ -1563,14 +1563,21 @@ func fieldOptionsToFunctionalOpts(opt fieldOptions) []FieldOption {
|
|||
case FieldTypeSet:
|
||||
fos = append(fos, OptFieldTypeSet(*opt.CacheType, *opt.CacheSize))
|
||||
case FieldTypeInt:
|
||||
if opt.Min == nil {
|
||||
min := pql.NewDecimal(int64(math.MinInt64), 0)
|
||||
opt.Min = &min
|
||||
min, max := pql.MinMax(0)
|
||||
// ensure the provided bounds are valid
|
||||
if opt.Max != nil && max.LessThan(*opt.Max) {
|
||||
opt.Max = &max
|
||||
}
|
||||
if opt.Max == nil {
|
||||
max := pql.NewDecimal(int64(math.MaxInt64), 0)
|
||||
opt.Max = &max
|
||||
}
|
||||
|
||||
if opt.Min != nil && min.GreaterThan(*opt.Min) {
|
||||
opt.Min = &min
|
||||
}
|
||||
if opt.Min == nil {
|
||||
opt.Min = &min
|
||||
}
|
||||
fos = append(fos, OptFieldTypeInt(opt.Min.ToInt64(0), opt.Max.ToInt64(0)))
|
||||
case FieldTypeDecimal:
|
||||
scale := int64(0)
|
||||
|
|
|
|||
22
index.go
22
index.go
|
|
@ -4,7 +4,6 @@ package pilosa
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
|
@ -618,14 +617,23 @@ func (i *Index) CreateFieldIfNotExistsWithOptions(name string, opt *FieldOptions
|
|||
// added for backward compatablity with old schemas
|
||||
if opt != nil && opt.Type == FieldTypeDecimal {
|
||||
min, max := pql.MinMax(opt.Scale)
|
||||
opt.Max = max
|
||||
opt.Min = min
|
||||
// ensure the provided bounds are valid
|
||||
if max.LessThan(opt.Max) {
|
||||
opt.Max = max
|
||||
}
|
||||
if min.GreaterThan(opt.Min) {
|
||||
opt.Min = min
|
||||
}
|
||||
}
|
||||
if opt != nil && opt.Type == FieldTypeDecimal {
|
||||
min := pql.NewDecimal(int64(math.MinInt64), 0)
|
||||
max := pql.NewDecimal(int64(math.MaxInt64), 0)
|
||||
opt.Max = max
|
||||
opt.Min = min
|
||||
min, max := pql.MinMax(0)
|
||||
// ensure the provided bounds are valid
|
||||
if max.LessThan(opt.Max) {
|
||||
opt.Max = max
|
||||
}
|
||||
if min.GreaterThan(opt.Min) {
|
||||
opt.Min = min
|
||||
}
|
||||
}
|
||||
|
||||
cfm := &CreateFieldMessage{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue