-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.go
79 lines (65 loc) · 1.59 KB
/
main.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
// advanced example shows an advanced setup of baker.Components
package main
import (
"hash/fnv"
"log"
"github.com/AdRoll/baker"
"github.com/AdRoll/baker/filter"
"github.com/AdRoll/baker/input"
"github.com/AdRoll/baker/output"
"github.com/AdRoll/baker/upload"
)
func main() {
if err := baker.MainCLI(components); err != nil {
log.Fatal(err)
}
}
// Some example fields
const (
Timestamp baker.FieldIndex = 0
Source baker.FieldIndex = 1
Target baker.FieldIndex = 2
)
// And their respective names
var fieldNames = []string{"timestamp", "source", "target"}
var components = baker.Components{
Inputs: input.All,
Filters: filter.All,
Outputs: output.All,
Uploads: upload.All,
ShardingFuncs: shardingFuncs,
Validate: validateLogLine,
FieldByName: fieldByName,
FieldNames: fieldNames,
}
var shardingFuncs = map[baker.FieldIndex]baker.ShardingFunc{
Timestamp: timestampToInt,
Source: sourceToInt,
Target: targetToInt,
}
func timestampToInt(r baker.Record) uint64 {
return simpleHash(r, Timestamp)
}
func sourceToInt(r baker.Record) uint64 {
return simpleHash(r, Source)
}
func targetToInt(r baker.Record) uint64 {
return simpleHash(r, Target)
}
func simpleHash(r baker.Record, idx baker.FieldIndex) uint64 {
f := fnv.New64()
f.Write(r.Get(idx))
return f.Sum64()
}
func validateLogLine(baker.Record) (bool, baker.FieldIndex) {
// All records are valid...
return true, 0
}
func fieldByName(name string) (baker.FieldIndex, bool) {
for idx, n := range fieldNames {
if n == name {
return baker.FieldIndex(idx), true
}
}
return 0, false
}