-
Notifications
You must be signed in to change notification settings - Fork 0
/
delta_config.go
115 lines (99 loc) · 2.56 KB
/
delta_config.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package delta
import (
"fmt"
"strconv"
"strings"
"time"
)
var (
CONFIG_CHECKPOINT_INTERVAL = Config{
Key: "checkpointInterval",
Default: "10",
}
CONFIG_TOMBSTONE_RETENTION = Config{
Key: "deletedFileRetentionDuration",
Default: "interval 1 week",
}
CONFIG_LOG_RETENTION = Config{
Key: "logRetentionDuration",
Default: "interval 30 day",
}
CONFIG_ENABLE_EXPIRED_LOG_CLEANUP = Config{
Key: "enableExpiredLogCleanup",
Default: "true",
}
)
// Delta table's `metadata.configuration` entry.
type Config struct {
// The configuration name
Key string
// The default value if `key` is not set in `metadata.configuration`.
Default string
}
func (d *Config) GetRawFromMetadata(metadata *TableMetadata) string {
v, ok := metadata.Configuration[d.Key]
if ok {
return v
}
return d.Default
}
func (d *Config) GetIntFromMetadata(metadata *TableMetadata) (int32, error) {
v := d.GetRawFromMetadata(metadata)
c, err := strconv.ParseInt(v, 10, 32)
if err != nil {
return 0, fmt.Errorf("unable to parse int32 from metadata: %w", err)
}
return int32(c), nil
}
func (d *Config) GetLongFromMetadata(metadata *TableMetadata) (int64, error) {
v := d.GetRawFromMetadata(metadata)
c, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return 0, fmt.Errorf("unable to parse int32 from metadata: %w", err)
}
return c, nil
}
func (d *Config) GetBoolFromMetadata(metadata *TableMetadata) (bool, error) {
v := d.GetRawFromMetadata(metadata)
c, err := strconv.ParseBool(v)
if err != nil {
return false, fmt.Errorf("unable to parse int32 from metadata: %w", err)
}
return c, nil
}
func (d *Config) GetDurationFromMetadata(metadata *TableMetadata) (time.Duration, error) {
v := d.GetRawFromMetadata(metadata)
words := strings.Split(v, " ")
if len(words) != 3 {
return 0, fmt.Errorf("invalid input for GetDurationFromMetadata: %s", v)
}
quantity, err := strconv.Atoi(words[1])
if err != nil {
return 0, fmt.Errorf("unable to parse int from metadata: %w", err)
}
var unit time.Duration
switch words[2] {
case "nanosecond":
unit = time.Nanosecond
case "microsecond":
unit = time.Microsecond
case "millisecond":
unit = time.Millisecond
case "second":
unit = time.Second
case "minute":
unit = time.Minute
case "hour":
unit = time.Hour
case "day":
unit = 24 * time.Hour
case "week":
unit = 24 * 7 * time.Hour
default:
return 0, fmt.Errorf("unknown time unit: %s", words[1])
}
return unit * time.Duration(quantity), nil
}
func (d *Config) Apply(metadata *TableMetadata, value string) {
metadata.Configuration[d.Key] = value
}