Skip to content

Commit

Permalink
Adjust use of traceql.Static in vp4
Browse files Browse the repository at this point in the history
  • Loading branch information
stoewer committed Jul 2, 2024
1 parent 2814940 commit 658b3a8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion tempodb/encoding/vparquet3/coalesce_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func operandsEqual(c1 traceql.Condition, c2 traceql.Condition) bool {

// todo: sort first?
for i := 0; i < len(c1.Operands); i++ {
if !c1.Operands[i].Equals(&c2.Operands[i]) {
if !c1.Operands[i].StrictEquals(&c2.Operands[i]) {
return false
}
}
Expand Down
21 changes: 11 additions & 10 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.Static]struct{}
sentVals map[traceql.StaticMapKey]struct{}
}

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

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

var empty traceql.Static
if val != empty {
if _, ok := d.sentVals[val]; !ok {
if val.Type != traceql.TypeNil {
mk := val.MapKey()
if _, ok := d.sentVals[mk]; !ok {
result.AppendOtherValue("", val)
d.sentVals[val] = struct{}{}
d.sentVals[mk] = struct{}{}
}
}

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

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

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

Expand All @@ -649,9 +649,10 @@ func (d distinctValueCollector) KeepGroup(result *parquetquery.IteratorResult) b
}
static := d.mapToStatic(e)

if _, ok := d.sentVals[static]; !ok {
mk := static.MapKey()
if _, ok := d.sentVals[mk]; !ok {
result.AppendOtherValue("", static)
d.sentVals[static] = struct{}{}
d.sentVals[mk] = struct{}{}
}
}
result.Entries = result.Entries[:0]
Expand Down
73 changes: 36 additions & 37 deletions tempodb/encoding/vparquet4/block_traceql.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ func (s *span) AttributeFor(a traceql.Attribute) (traceql.Static, bool) {

if a.Intrinsic != traceql.IntrinsicNone {
if a.Intrinsic == traceql.IntrinsicNestedSetLeft {
return traceql.Static{Type: traceql.TypeInt, N: int(s.nestedSetLeft)}, true
return traceql.NewStaticInt(int(s.nestedSetLeft)), true
}
if a.Intrinsic == traceql.IntrinsicNestedSetRight {
return traceql.Static{Type: traceql.TypeInt, N: int(s.nestedSetRight)}, true
return traceql.NewStaticInt(int(s.nestedSetRight)), true
}
if a.Intrinsic == traceql.IntrinsicNestedSetParent {
return traceql.Static{Type: traceql.TypeInt, N: int(s.nestedSetParent)}, true
return traceql.NewStaticInt(int(s.nestedSetParent)), true
}

// intrinsics are always on the span, trace, event, or link ... for now
Expand Down Expand Up @@ -2268,14 +2268,11 @@ func createStringPredicate(op traceql.Operator, operands traceql.Operands) (parq
return nil, nil
}

for _, op := range operands {
if op.Type != traceql.TypeString {
return nil, fmt.Errorf("operand is not string: %+v", op)
}
s := operands[0].EncodeToString(false)
if operands[0].Type != traceql.TypeString {
return nil, fmt.Errorf("operand is not string: %s", s)
}

s := operands[0].S

switch op {
case traceql.OpEqual:
return parquetquery.NewStringEqualPredicate([]byte(s)), nil
Expand All @@ -2294,7 +2291,7 @@ func createStringPredicate(op traceql.Operator, operands traceql.Operands) (parq
case traceql.OpLessEqual:
return parquetquery.NewStringLessEqualPredicate([]byte(s)), nil
default:
return nil, fmt.Errorf("operand not supported for strings: %+v", op)
return nil, fmt.Errorf("operator not supported for strings: %+v", op)
}
}

Expand All @@ -2303,14 +2300,11 @@ func createBytesPredicate(op traceql.Operator, operands traceql.Operands, isSpan
return nil, nil
}

for _, op := range operands {
if op.Type != traceql.TypeString {
return nil, fmt.Errorf("operand is not string: %+v", op)
}
s := operands[0].EncodeToString(false)
if operands[0].Type != traceql.TypeString {
return nil, fmt.Errorf("operand is not string: %s", s)
}

s := operands[0].S

var id []byte
id, err := util.HexStringToTraceID(s)
if isSpan {
Expand All @@ -2329,7 +2323,7 @@ func createBytesPredicate(op traceql.Operator, operands traceql.Operands, isSpan
case traceql.OpNotEqual:
return parquetquery.NewByteNotEqualPredicate(id), nil
default:
return nil, fmt.Errorf("operand not supported for IDs: %+v", op)
return nil, fmt.Errorf("operator not supported for IDs: %+v", op)
}
}

Expand All @@ -2341,15 +2335,19 @@ func createIntPredicate(op traceql.Operator, operands traceql.Operands) (parquet
var i int64
switch operands[0].Type {
case traceql.TypeInt:
i = int64(operands[0].N)
n, _ := operands[0].Int()
i = int64(n)
case traceql.TypeDuration:
i = operands[0].D.Nanoseconds()
d, _ := operands[0].Duration()
i = d.Nanoseconds()
case traceql.TypeStatus:
i = int64(StatusCodeMapping[operands[0].Status.String()])
st, _ := operands[0].Status()
i = int64(StatusCodeMapping[st.String()])
case traceql.TypeKind:
i = int64(KindMapping[operands[0].Kind.String()])
k, _ := operands[0].Kind()
i = int64(KindMapping[k.String()])
default:
return nil, fmt.Errorf("operand is not int, duration, status or kind: %+v", operands[0])
return nil, fmt.Errorf("operand is not int, duration, status or kind: %s", operands[0].EncodeToString(false))
}

switch op {
Expand All @@ -2366,7 +2364,7 @@ func createIntPredicate(op traceql.Operator, operands traceql.Operands) (parquet
case traceql.OpLessEqual:
return parquetquery.NewIntLessEqualPredicate(i), nil
default:
return nil, fmt.Errorf("operand not supported for integers: %+v", op)
return nil, fmt.Errorf("operator not supported for integers: %+v", op)
}
}

Expand All @@ -2377,26 +2375,26 @@ func createFloatPredicate(op traceql.Operator, operands traceql.Operands) (parqu

// Ensure operand is float
if operands[0].Type != traceql.TypeFloat {
return nil, fmt.Errorf("operand is not float: %+v", operands[0])
return nil, fmt.Errorf("operand is not float: %s", operands[0].EncodeToString(false))
}

i := operands[0].F
f := operands[0].Float()

switch op {
case traceql.OpEqual:
return parquetquery.NewFloatEqualPredicate(i), nil
return parquetquery.NewFloatEqualPredicate(f), nil
case traceql.OpNotEqual:
return parquetquery.NewFloatNotEqualPredicate(i), nil
return parquetquery.NewFloatNotEqualPredicate(f), nil
case traceql.OpGreater:
return parquetquery.NewFloatGreaterPredicate(i), nil
return parquetquery.NewFloatGreaterPredicate(f), nil
case traceql.OpGreaterEqual:
return parquetquery.NewFloatGreaterEqualPredicate(i), nil
return parquetquery.NewFloatGreaterEqualPredicate(f), nil
case traceql.OpLess:
return parquetquery.NewFloatLessPredicate(i), nil
return parquetquery.NewFloatLessPredicate(f), nil
case traceql.OpLessEqual:
return parquetquery.NewFloatLessEqualPredicate(i), nil
return parquetquery.NewFloatLessEqualPredicate(f), nil
default:
return nil, fmt.Errorf("operand not supported for floats: %+v", op)
return nil, fmt.Errorf("operator not supported for floats: %+v", op)
}
}

Expand All @@ -2406,17 +2404,18 @@ func createBoolPredicate(op traceql.Operator, operands traceql.Operands) (parque
}

// Ensure operand is bool
if operands[0].Type != traceql.TypeBoolean {
return nil, fmt.Errorf("operand is not bool: %+v", operands[0])
b, ok := operands[0].Bool()
if !ok {
return nil, fmt.Errorf("oparand is not bool: %+v", operands[0].EncodeToString(false))
}

switch op {
case traceql.OpEqual:
return parquetquery.NewBoolEqualPredicate(operands[0].B), nil
return parquetquery.NewBoolEqualPredicate(b), nil
case traceql.OpNotEqual:
return parquetquery.NewBoolNotEqualPredicate(operands[0].B), nil
return parquetquery.NewBoolNotEqualPredicate(b), nil
default:
return nil, fmt.Errorf("operand not supported for booleans: %+v", op)
return nil, fmt.Errorf("operator not supported for booleans: %+v", op)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tempodb/encoding/vparquet4/coalesce_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func operandsEqual(c1, c2 traceql.Condition) bool {

// todo: sort first?
for i := 0; i < len(c1.Operands); i++ {
if c1.Operands[i] != c2.Operands[i] {
if !c1.Operands[i].StrictEquals(&c2.Operands[i]) {
return false
}
}
Expand Down

0 comments on commit 658b3a8

Please sign in to comment.