Skip to content

Commit

Permalink
[vParquet2] Optimize duration queries and remove extra duration logic
Browse files Browse the repository at this point in the history
Since there is now a dedicated duration column, queries for duration can
be treated more like any other integer column
  • Loading branch information
stoewer committed Apr 3, 2023
1 parent 11ca1fe commit f8cd5ac
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions tempodb/encoding/vparquet2/block_traceql.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ func createSpanIterator(makeIter makeIterFn, conditions []traceql.Condition, req
columnPredicates = map[string][]parquetquery.Predicate{}
iters []parquetquery.Iterator
genericConditions []traceql.Condition
durationPredicates []*parquetquery.GenericPredicate[int64]
spanDurationRetrieved bool
)

Expand Down Expand Up @@ -544,12 +543,7 @@ func createSpanIterator(makeIter makeIterFn, conditions []traceql.Condition, req
if err != nil {
return nil, false, err
}
if pred, ok := pred.(*parquetquery.GenericPredicate[int64]); ok {
durationPredicates = append(durationPredicates, pred)
} else {
durationPredicates = append(durationPredicates, nil)
}
addPredicate(columnPathSpanDuration, nil)
addPredicate(columnPathSpanDuration, pred)
columnSelectAs[columnPathSpanDuration] = columnPathSpanDuration
continue

Expand Down Expand Up @@ -615,8 +609,7 @@ func createSpanIterator(makeIter makeIterFn, conditions []traceql.Condition, req
minCount = len(distinct)
}
spanCol := &spanCollector{
minCount,
durationPredicates,
minAttributes: minCount,
}

// This is an optimization for when all of the span conditions must be met.
Expand All @@ -631,7 +624,7 @@ func createSpanIterator(makeIter makeIterFn, conditions []traceql.Condition, req
// Wrap up the individual conditions with a union and move it into the required list.
// This skips over static columns like ID that are omnipresent. This is also only
// possible when there isn't a duration filter because it's computed from start/end.
if requireAtLeastOneMatch && len(iters) > 0 && len(durationPredicates) == 0 {
if requireAtLeastOneMatch && len(iters) > 0 {
required = append(required, parquetquery.NewUnionIterator(DefinitionLevelResourceSpansILSSpan, iters, nil))
iters = nil
}
Expand Down Expand Up @@ -1038,14 +1031,13 @@ func createAttributeIterator(makeIter makeIterFn, conditions []traceql.Condition

// This turns groups of span values into Span objects
type spanCollector struct {
minAttributes int
durationFilters []*parquetquery.GenericPredicate[int64]
minAttributes int
}

var _ parquetquery.GroupPredicate = (*spanCollector)(nil)

func (c *spanCollector) String() string {
return fmt.Sprintf("spanCollector(%d, %v)", c.minAttributes, c.durationFilters)
return fmt.Sprintf("spanCollector(%d)", c.minAttributes)
}

func (c *spanCollector) KeepGroup(res *parquetquery.IteratorResult) bool {
Expand All @@ -1066,10 +1058,9 @@ func (c *spanCollector) KeepGroup(res *parquetquery.IteratorResult) bool {
case columnPathSpanDuration:
durationNanos = kv.Value.Uint64()
span.durationNanos = durationNanos
span.attributes[traceql.NewIntrinsic(traceql.IntrinsicDuration)] = traceql.NewStaticDuration(time.Duration(durationNanos))
case columnPathSpanName:
span.attributes[traceql.NewIntrinsic(traceql.IntrinsicName)] = traceql.NewStaticString(kv.Value.String())
//case columnPathSpanDuration:
// span.Attributes[traceql.NewIntrinsic(traceql.IntrinsicDuration)] = traceql.NewStaticDuration(time.Duration(kv.Value.Uint64()))
case columnPathSpanStatusCode:
// Map OTLP status code back to TraceQL enum.
// For other values, use the raw integer.
Expand Down Expand Up @@ -1120,16 +1111,6 @@ func (c *spanCollector) KeepGroup(res *parquetquery.IteratorResult) bool {
}
}

// Save computed duration if any filters present and at least one is passed.
if len(c.durationFilters) > 0 {
for _, f := range c.durationFilters {
if f == nil || f.Fn(int64(durationNanos)) {
span.attributes[traceql.NewIntrinsic(traceql.IntrinsicDuration)] = traceql.NewStaticDuration(time.Duration(durationNanos))
break
}
}
}

if c.minAttributes > 0 {
count := 0
for _, v := range span.attributes {
Expand Down

0 comments on commit f8cd5ac

Please sign in to comment.