Skip to content

Commit

Permalink
fix(proto): make Prepare for ColEnum and ColLowCardinality[T] idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Jul 8, 2022
1 parent 4a4267f commit 2eb44c7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
8 changes: 1 addition & 7 deletions otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (m MapPair[V]) Append(k []string, v []V) {

func NewMapPair[X comparable](v proto.ColumnOf[X]) MapPair[X] {
return MapPair[X]{
Keys: new(proto.ColStr).Array(),
Keys: new(proto.ColStr).LowCardinality().Array(),
Values: proto.NewArray(v),
}
}
Expand Down Expand Up @@ -169,12 +169,6 @@ func BenchmarkOTEL(b *testing.B) {
buf.Reset()
buf.PutString("")

// Important!
// Simulating "Reset" to new values.
v := data.SevText.Values
data.SevText.Reset()
data.SevText.Values = v

if err := block.EncodeBlock(buf, proto.Version, input); err != nil {
b.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions proto/col_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ func (e *ColEnum) Reset() {
}

func (e *ColEnum) Prepare() error {
if e.raw().Rows() != 0 {
return errors.New("already prepared")
}
e.raw8 = e.raw8[:0]
e.raw16 = e.raw16[:0]
for _, v := range e.Values {
raw, ok := e.strToRaw[v]
if !ok {
Expand Down
2 changes: 2 additions & 0 deletions proto/col_low_cardinality.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const sharedDictionariesWithAdditionalKeys keySerializationVersion = 1
//
// For example, ["Eko", "Eko", "Amadela", "Amadela", "Amadela", "Amadela"] can
// be encoded as:
//
// Index: ["Eko", "Amadela"] (String)
// Keys: [0, 0, 1, 1, 1, 1] (UInt8)
//
Expand Down Expand Up @@ -249,6 +250,7 @@ type cardinalityKeyValue interface {
}

func fillKeys[K cardinalityKeyValue](values []int, keys []K) []K {
keys = keys[:0]
for _, v := range values {
keys = append(keys, K(v))
}
Expand Down

0 comments on commit 2eb44c7

Please sign in to comment.