Skip to content

Commit

Permalink
Optimize bucketing
Browse files Browse the repository at this point in the history
  • Loading branch information
zix99 committed Sep 16, 2022
1 parent af6436c commit a6418a6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/usage/expressions.md
Expand Up @@ -88,7 +88,7 @@ Evaluates arguments in-order, chosing the first non-empty result.

### Bucket

Syntax: `{bucket intVal bucketSize}`
Syntax: `{bucket intVal "bucketSize"}`

Given a value, create equal-sized buckets and place each value in those buckets

Expand Down
11 changes: 6 additions & 5 deletions pkg/expressions/stdlib/funcsCommon.go
Expand Up @@ -23,17 +23,18 @@ func kfBucket(args []KeyBuilderStage) KeyBuilderStage {
if len(args) != 2 {
return stageLiteral(ErrorArgCount)
}

bucketSize, err := strconv.Atoi(EvalStageOrDefault(args[1], ""))
if err != nil {
return stageLiteral(ErrorType)
}

return KeyBuilderStage(func(context KeyBuilderContext) string {
val, err := strconv.Atoi(args[0](context))
if err != nil {
return ErrorType
}

bucketSize, err := strconv.Atoi(args[1](context))
if err != nil {
return ErrorType
}

return strconv.Itoa((val / bucketSize) * bucketSize)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/expressions/stdlib/funcsTime.go
Expand Up @@ -260,7 +260,7 @@ func kfTimeAttr(args []KeyBuilderStage) KeyBuilderStage {

attrName, hasAttrName := EvalStaticStage(args[1])
if !hasAttrName {
return stageLiteral(ErrorType)
return stageLiteral(ErrorConst)
}
tz, tzOk := parseTimezoneLocation(EvalStageIndexOrDefault(args, 2, ""))
if !tzOk {
Expand Down

0 comments on commit a6418a6

Please sign in to comment.