Skip to content

Commit

Permalink
process Enum min-max in existing loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonkers committed Jan 7, 2025
1 parent 4cd4d3c commit 92a353c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/column/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ package column
import (
"bytes"
"errors"
"github.com/ClickHouse/ch-go/proto"
"golang.org/x/exp/maps"
"math"
"slices"
"strconv"

"github.com/ClickHouse/ch-go/proto"
"golang.org/x/exp/maps"
)

func Enum(chType Type, name string) (Interface, error) {
Expand Down Expand Up @@ -58,14 +59,22 @@ func Enum(chType Type, name string) (Interface, error) {
vi: make(map[proto.Enum16]string, len(values)),
chType: chType,
name: name,
// to be updated below, when ranging over all index/enum values
minEnum: math.MaxInt16,
maxEnum: math.MinInt16,
}

for i := range values {
enum.iv[values[i]] = proto.Enum16(indexes[i])
enum.vi[proto.Enum16(indexes[i])] = values[i]
k := int16(indexes[i])
enum.iv[values[i]] = proto.Enum16(k)
enum.vi[proto.Enum16(k)] = values[i]
if k < enum.minEnum {
enum.minEnum = k
}
if k > enum.maxEnum {
enum.maxEnum = k
}
}
enum.minEnum = int16(slices.Min(maps.Keys(enum.vi)))
enum.maxEnum = int16(slices.Max(maps.Keys(enum.vi)))
enum.continuous = (enum.maxEnum-enum.minEnum)+1 == int16(len(enum.vi))
return &enum, nil
}
Expand Down

0 comments on commit 92a353c

Please sign in to comment.