This repository was archived by the owner on Feb 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathhack.go
82 lines (74 loc) · 2.04 KB
/
hack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2022 Molecula Corp. (DBA FeatureBase).
// SPDX-License-Identifier: Apache-2.0
package pilosa
import (
"math"
"time"
"github.com/featurebasedb/featurebase/v3/pb"
"github.com/featurebasedb/featurebase/v3/pql"
"github.com/gogo/protobuf/proto"
)
func UnmarshalIndexOptions(name string, createdAt int64, buf []byte) (*IndexOptions, error) {
var io pb.IndexMeta
// Read data from meta file.
if err := proto.Unmarshal(buf, &io); err != nil {
return nil, err
}
return &IndexOptions{
Keys: io.Keys,
TrackExistence: io.TrackExistence,
}, nil
}
func UnmarshalFieldOptions(name string, createdAt int64, buf []byte) (*FieldInfo, error) {
var pbi pb.FieldOptions
// Read data from meta file.
if err := proto.Unmarshal(buf, &pbi); err != nil {
return nil, err
}
fi := &FieldInfo{}
fi.Name = name
fi.CreatedAt = createdAt
fi.Options = FieldOptions{}
// Initialize "base" to "min" when upgrading from v1 BSI format.
if pbi.BitDepth == 0 {
pbi.Base = bsiBase(pbi.OldMin, pbi.OldMax)
pbi.BitDepth = uint64(bitDepthInt64(pbi.OldMax - pbi.OldMin))
if pbi.BitDepth == 0 {
pbi.BitDepth = 1
}
}
// Copy metadata fields.
fi.Options.Type = pbi.Type
if pbi.Type == "decimal" {
fi.Options.Scale = 3
}
fi.Options.CacheType = pbi.CacheType
fi.Options.CacheSize = pbi.CacheSize
fi.Options.Base = pbi.Base
fi.Options.BitDepth = pbi.BitDepth
fi.Options.TimeQuantum = TimeQuantum(pbi.TimeQuantum)
ttlValue, err := time.ParseDuration(pbi.TTL)
if err != nil {
ttlValue = 0
}
fi.Options.TTL = ttlValue
fi.Options.Keys = pbi.Keys
fi.Options.NoStandardView = pbi.NoStandardView
// hard code for the unmarshal go broken with a version change
switch fi.Options.Type {
case "int":
min := int64(math.MinInt64)
max := int64(math.MaxInt64)
fi.Options.Min = pql.NewDecimal(min, 0)
fi.Options.Max = pql.NewDecimal(max, 0)
fi.Options.Base = 0
case "decimal":
scale := int64(3)
min, max := pql.MinMax(scale)
fi.Options.Min = min
fi.Options.Max = max
fi.Options.Base = 0
fi.Options.Scale = scale
}
return fi, nil
}