Skip to content

Commit

Permalink
Rename StaticHashCode to StaticMapKey
Browse files Browse the repository at this point in the history
  • Loading branch information
stoewer committed Jun 19, 2024
1 parent 7d2b051 commit e08abdb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
45 changes: 23 additions & 22 deletions pkg/traceql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ func (p Pipeline) evaluate(input []*Spanset) (result []*Spanset, err error) {
type GroupOperation struct {
Expression FieldExpression

groupBuffer map[StaticHashCode]*Spanset
groupBuffer map[StaticMapKey]*Spanset
}

func newGroupOperation(e FieldExpression) GroupOperation {
return GroupOperation{
Expression: e,
groupBuffer: make(map[StaticHashCode]*Spanset),
groupBuffer: make(map[StaticMapKey]*Spanset),
}
}

Expand Down Expand Up @@ -481,17 +481,18 @@ type Static interface {

AsAnyValue() *common_v1.AnyValue
EncodeToString(quotes bool) string
HashCode() StaticHashCode
MapKey() StaticMapKey
equals(o Static) bool
compare(o Static) int
asFloat() float64
add(o Static) Static
divide(f float64) Static
}

type StaticHashCode struct {
// StaticMapKey is a comparable key that corresponds to a given Static value.
type StaticMapKey struct {
Type StaticType
Hash uint64
Code uint64
Str string
}

Expand Down Expand Up @@ -548,8 +549,8 @@ func (StaticNil) divide(_ float64) Static {
return NewStaticNil()
}

func (StaticNil) HashCode() StaticHashCode {
return StaticHashCode{Type: TypeNil}
func (StaticNil) MapKey() StaticMapKey {
return StaticMapKey{Type: TypeNil}
}

// StaticInt represents a Static implementation based on int
Expand Down Expand Up @@ -614,8 +615,8 @@ func (s StaticInt) asFloat() float64 {
return float64(s.Int)
}

func (s StaticInt) HashCode() StaticHashCode {
return StaticHashCode{Type: TypeInt, Hash: uint64(s.Int)}
func (s StaticInt) MapKey() StaticMapKey {
return StaticMapKey{Type: TypeInt, Code: uint64(s.Int)}
}

// StaticFloat represents a Static implementation based on float64
Expand Down Expand Up @@ -677,8 +678,8 @@ func (s StaticFloat) divide(f float64) Static {
return s
}

func (s StaticFloat) HashCode() StaticHashCode {
return StaticHashCode{Type: TypeFloat, Hash: math.Float64bits(s.Float)}
func (s StaticFloat) MapKey() StaticMapKey {
return StaticMapKey{Type: TypeFloat, Code: math.Float64bits(s.Float)}
}

// StaticString represents a Static implementation based on string
Expand Down Expand Up @@ -721,8 +722,8 @@ func (s StaticString) divide(_ float64) Static {
return s
}

func (s StaticString) HashCode() StaticHashCode {
return StaticHashCode{Type: TypeString, Str: s.Str}
func (s StaticString) MapKey() StaticMapKey {
return StaticMapKey{Type: TypeString, Str: s.Str}
}

// StaticBool represents a Static implementation based on bool
Expand Down Expand Up @@ -770,11 +771,11 @@ func (s StaticBool) divide(_ float64) Static {
return s
}

func (s StaticBool) HashCode() StaticHashCode {
func (s StaticBool) MapKey() StaticMapKey {
if s.Bool {
return StaticHashCode{Type: TypeBoolean, Hash: 1}
return StaticMapKey{Type: TypeBoolean, Code: 1}
}
return StaticHashCode{Type: TypeBoolean, Hash: 0}
return StaticMapKey{Type: TypeBoolean, Code: 0}
}

// StaticDuration represents a Static implementation based on time.Duration
Expand Down Expand Up @@ -836,8 +837,8 @@ func (s StaticDuration) divide(f float64) Static {
return NewStaticDuration(d)
}

func (s StaticDuration) HashCode() StaticHashCode {
return StaticHashCode{Type: TypeDuration, Hash: uint64(s.Duration)}
func (s StaticDuration) MapKey() StaticMapKey {
return StaticMapKey{Type: TypeDuration, Code: uint64(s.Duration)}
}

// StaticStatus represents a Static implementation based on Status
Expand Down Expand Up @@ -886,8 +887,8 @@ func (s StaticStatus) divide(_ float64) Static {
return s
}

func (s StaticStatus) HashCode() StaticHashCode {
return StaticHashCode{Type: TypeStatus, Hash: uint64(s.Status)}
func (s StaticStatus) MapKey() StaticMapKey {
return StaticMapKey{Type: TypeStatus, Code: uint64(s.Status)}
}

// StaticKind represents a Static implementation based on Kind
Expand Down Expand Up @@ -930,8 +931,8 @@ func (s StaticKind) divide(_ float64) Static {
return s
}

func (s StaticKind) HashCode() StaticHashCode {
return StaticHashCode{Type: TypeKind, Hash: uint64(s.Kind)}
func (s StaticKind) MapKey() StaticMapKey {
return StaticMapKey{Type: TypeKind, Code: uint64(s.Kind)}
}

// **********************
Expand Down
12 changes: 6 additions & 6 deletions pkg/traceql/engine_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ const maxGroupBys = 5 // TODO - This isn't ideal but see comment below.
// the maximum number of values.

type (
FastStatic1 [1]StaticHashCode
FastStatic2 [2]StaticHashCode
FastStatic3 [3]StaticHashCode
FastStatic4 [4]StaticHashCode
FastStatic5 [5]StaticHashCode
FastStatic1 [1]StaticMapKey
FastStatic2 [2]StaticMapKey
FastStatic3 [3]StaticMapKey
FastStatic4 [4]StaticMapKey
FastStatic5 [5]StaticMapKey
)

type FastStatic interface {
Expand Down Expand Up @@ -361,7 +361,7 @@ func (g *GroupingAggregator[F, S]) Observe(span Span) {
for i, lookups := range g.byLookups {
val := lookup(lookups, span)
g.buf.vals[i] = val
g.buf.fast[i] = val.HashCode()
g.buf.fast[i] = val.MapKey()
}

// If dynamic label exists calculate and append it
Expand Down
10 changes: 5 additions & 5 deletions tempodb/encoding/vparquet3/block_autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,13 @@ var _ parquetquery.GroupPredicate = (*distinctAttrCollector)(nil)
type distinctAttrCollector struct {
scope traceql.AttributeScope

sentVals map[traceql.StaticHashCode]struct{}
sentVals map[traceql.StaticMapKey]struct{}
}

func newDistinctAttrCollector(scope traceql.AttributeScope) *distinctAttrCollector {
return &distinctAttrCollector{
scope: scope,
sentVals: make(map[traceql.StaticHashCode]struct{}),
sentVals: make(map[traceql.StaticMapKey]struct{}),
}
}

Expand Down Expand Up @@ -609,7 +609,7 @@ func (d *distinctAttrCollector) KeepGroup(result *parquetquery.IteratorResult) b
}

if val != nil {
if _, ok := d.sentVals[val.HashCode()]; !ok {
if _, ok := d.sentVals[val.MapKey()]; !ok {
result.AppendOtherValue("", val)
d.sentVals[val.HashCode()] = struct{}{}
}
Expand All @@ -629,13 +629,13 @@ var _ parquetquery.GroupPredicate = (*distinctValueCollector)(nil)

type distinctValueCollector struct {
mapToStatic func(entry) traceql.Static
sentVals map[traceql.StaticHashCode]struct{}
sentVals map[traceql.StaticMapKey]struct{}
}

func newDistinctValueCollector(mapToStatic func(entry) traceql.Static) *distinctValueCollector {
return &distinctValueCollector{
mapToStatic: mapToStatic,
sentVals: make(map[traceql.StaticHashCode]struct{}),
sentVals: make(map[traceql.StaticMapKey]struct{}),
}
}

Expand Down
12 changes: 6 additions & 6 deletions tempodb/encoding/vparquet4/block_autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,13 @@ var _ parquetquery.GroupPredicate = (*distinctAttrCollector)(nil)
type distinctAttrCollector struct {
scope traceql.AttributeScope

sentVals map[traceql.StaticHashCode]struct{}
sentVals map[traceql.StaticMapKey]struct{}
}

func newDistinctAttrCollector(scope traceql.AttributeScope) *distinctAttrCollector {
return &distinctAttrCollector{
scope: scope,
sentVals: make(map[traceql.StaticHashCode]struct{}),
sentVals: make(map[traceql.StaticMapKey]struct{}),
}
}

Expand Down Expand Up @@ -609,9 +609,9 @@ func (d *distinctAttrCollector) KeepGroup(result *parquetquery.IteratorResult) b
}

if val != nil {
if _, ok := d.sentVals[val.HashCode()]; !ok {
if _, ok := d.sentVals[val.MapKey()]; !ok {
result.AppendOtherValue("", val)
d.sentVals[val.HashCode()] = struct{}{}
d.sentVals[val.MapKey()] = struct{}{}
}
}

Expand All @@ -629,13 +629,13 @@ var _ parquetquery.GroupPredicate = (*distinctValueCollector)(nil)

type distinctValueCollector struct {
mapToStatic func(entry) traceql.Static
sentVals map[traceql.StaticHashCode]struct{}
sentVals map[traceql.StaticMapKey]struct{}
}

func newDistinctValueCollector(mapToStatic func(entry) traceql.Static) *distinctValueCollector {
return &distinctValueCollector{
mapToStatic: mapToStatic,
sentVals: make(map[traceql.StaticHashCode]struct{}),
sentVals: make(map[traceql.StaticMapKey]struct{}),
}
}

Expand Down

0 comments on commit e08abdb

Please sign in to comment.