mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
decimal wowes
This commit is contained in:
parent
12f931d635
commit
f7fb9f386e
3 changed files with 34 additions and 6 deletions
|
|
@ -19,8 +19,10 @@ import (
|
|||
|
||||
pilosa "github.com/molecula/featurebase/v3"
|
||||
"github.com/molecula/featurebase/v3/logger"
|
||||
"github.com/molecula/featurebase/v3/pql"
|
||||
"github.com/molecula/featurebase/v3/server"
|
||||
"github.com/molecula/featurebase/v3/topology"
|
||||
"github.com/molecula/featurebase/v3/vprint"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
|
@ -192,6 +194,13 @@ func (cmd *RestoreCommand) restoreSchema(ctx context.Context, primary *topology.
|
|||
}
|
||||
for _, field := range index.Fields {
|
||||
logger.Printf("Create Field %v", field.Name)
|
||||
if field.Options.Type == pilosa.FieldTypeDecimal {
|
||||
min, max := pql.MinMax(field.Options.Scale)
|
||||
scale := field.Options.Scale
|
||||
vprint.VV("setting MinMax %v %s %s", scale, min, max)
|
||||
field.Options.Max = max
|
||||
field.Options.Min = min
|
||||
}
|
||||
err = cmd.client.CreateFieldWithOptions(ctx, index.Name, field.Name, field.Options)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -1576,14 +1576,19 @@ func fieldOptionsToFunctionalOpts(opt fieldOptions) []FieldOption {
|
|||
scale := int64(0)
|
||||
if opt.Scale != nil {
|
||||
scale = *opt.Scale
|
||||
}
|
||||
if opt.Min == nil {
|
||||
min := pql.NewDecimal(int64(math.MinInt64), scale)
|
||||
min, max := pql.MinMax(scale)
|
||||
opt.Min = &min
|
||||
}
|
||||
if opt.Max == nil {
|
||||
max := pql.NewDecimal(int64(math.MaxInt64), scale)
|
||||
opt.Max = &max
|
||||
} else {
|
||||
|
||||
if opt.Min == nil {
|
||||
min := pql.NewDecimal(int64(math.MinInt64), scale)
|
||||
opt.Min = &min
|
||||
}
|
||||
if opt.Max == nil {
|
||||
max := pql.NewDecimal(int64(math.MaxInt64), scale)
|
||||
opt.Max = &max
|
||||
}
|
||||
}
|
||||
var minmax []pql.Decimal
|
||||
if opt.Min != nil {
|
||||
|
|
|
|||
14
index.go
14
index.go
|
|
@ -4,6 +4,7 @@ package pilosa
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
|
@ -11,6 +12,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/molecula/featurebase/v3/disco"
|
||||
"github.com/molecula/featurebase/v3/pql"
|
||||
"github.com/molecula/featurebase/v3/roaring"
|
||||
"github.com/molecula/featurebase/v3/stats"
|
||||
"github.com/molecula/featurebase/v3/testhook"
|
||||
|
|
@ -613,6 +615,18 @@ func (i *Index) CreateFieldIfNotExistsWithOptions(name string, opt *FieldOptions
|
|||
if f := i.fields[name]; f != nil {
|
||||
return f, nil
|
||||
}
|
||||
// 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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
cfm := &CreateFieldMessage{
|
||||
Index: i.name,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue