Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions internal/storage/v1/cassandra/spanstore/dbmodel/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ package dbmodel
import (
"bytes"
"encoding/binary"
"encoding/hex"
"sort"
"strconv"
"strings"

"github.com/jaegertracing/jaeger-idl/model/v1"
)
Expand Down Expand Up @@ -53,6 +57,96 @@ type KeyValue struct {
ValueBinary []byte `cql:"value_binary"`
}

func (t *KeyValue) compareValues(that *KeyValue) int {
switch t.ValueType {
case stringType:
return strings.Compare(t.ValueString, that.ValueString)
case boolType:
if t.ValueBool != that.ValueBool {
if !t.ValueBool {
return -1
}
return 1
}
case int64Type:
return int(t.ValueInt64 - that.ValueInt64)
case float64Type:
if t.ValueFloat64 != that.ValueFloat64 {
if t.ValueFloat64 < that.ValueFloat64 {
return -1
}
return 1
}
case binaryType:
return bytes.Compare(t.ValueBinary, that.ValueBinary)
default:
return -1 // theoretical case, not stating them equal but placing the base pointer before other
}
return 0
}

func (t *KeyValue) Compare(that any) int {
if that == nil {
if t == nil {
return 0
}
return 1
}
that1, ok := that.(*KeyValue)
if !ok {
that2, ok := that.(KeyValue)
if !ok {
return 1
}
that1 = &that2
}
if that1 == nil {
if t == nil {
return 0
}
return 1
} else if t == nil {
return -1
}
if cmp := strings.Compare(t.Key, that1.Key); cmp != 0 {
return cmp
}
if cmp := strings.Compare(t.ValueType, that1.ValueType); cmp != 0 {
return cmp
}
return t.compareValues(that1)
}

func (t *KeyValue) Equal(that any) bool {
return t.Compare(that) == 0
}

func (t *KeyValue) AsString() string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TagInsertion accepts TagValue only in form of string

switch t.ValueType {
case stringType:
return t.ValueString
case boolType:
if t.ValueBool {
return "true"
}
return "false"
case int64Type:
return strconv.FormatInt(t.ValueInt64, 10)
case float64Type:
return strconv.FormatFloat(t.ValueFloat64, 'g', 10, 64)
case binaryType:
return hex.EncodeToString(t.ValueBinary)
default:
return "unknown type " + t.ValueType
}
}

func SortKVs(kvs []KeyValue) {
sort.Slice(kvs, func(i, j int) bool {
return kvs[i].Compare(kvs[j]) < 0
})
}

// Log is the UDT representation of a Jaeger Log.
type Log struct {
Timestamp int64 `cql:"ts"` // microseconds since epoch
Expand Down
Loading
Loading