MCPcopy
hub / github.com/grafana/tempo / createAllIterator

Function createAllIterator

tempodb/encoding/vparquet4/block_traceql.go:1673–1743  ·  view source on GitHub ↗
(ctx context.Context, primaryIter parquetquery.Iterator, conditions []traceql.Condition, allConditions bool, start, end uint64, rgs []parquet.RowGroup,
	pf *parquet.File, dc backend.DedicatedColumns, selectAll bool,
	traceSampler traceql.Sampler,
	spanSampler traceql.Sampler,
)

Source from the content-addressed store, hash-verified

1671}
1672
1673func createAllIterator(ctx context.Context, primaryIter parquetquery.Iterator, conditions []traceql.Condition, allConditions bool, start, end uint64, rgs []parquet.RowGroup,
1674 pf *parquet.File, dc backend.DedicatedColumns, selectAll bool,
1675 traceSampler traceql.Sampler,
1676 spanSampler traceql.Sampler,
1677) (parquetquery.Iterator, error) {
1678 // categorize conditions by scope
1679 catConditions, mingledConditions, err := categorizeConditions(conditions)
1680 if err != nil {
1681 return nil, err
1682 }
1683
1684 makeIter := makeIterFunc(ctx, rgs, pf)
1685 makeNilIter := makeNilIterFunc(ctx, rgs, pf)
1686
1687 // Global state
1688 // Span-filtering behavior changes depending on the resource-filtering in effect,
1689 // and vice-versa. For example consider the query { span.a=1 }. If no spans have a=1
1690 // then it generate the empty spanset.
1691 // However once we add a resource condition: { span.a=1 || resource.b=2 }, now the span
1692 // filtering must return all spans, even if no spans have a=1, because they might be
1693 // matched upstream to a resource.
1694 // TODO - After introducing AllConditions it seems like some of this logic overlaps.
1695 // Determine if it can be generalized or simplified.
1696
1697 // Don't return the final spanset upstream unless it matched at least 1 condition
1698 // anywhere, except in the case of the empty query: {}
1699 batchRequireAtLeastOneMatchOverall := len(conditions) > 0 && len(catConditions.trace) == 0
1700
1701 // Optimization for queries like {resource.x... && span.y ...}
1702 // Requires no mingled scopes like .foo=x, which could be satisfied
1703 // one either resource or span.
1704 allConditions = allConditions && !mingledConditions
1705
1706 innerIterators := make([]parquetquery.Iterator, 0, 3)
1707 if primaryIter != nil {
1708 innerIterators = append(innerIterators, primaryIter)
1709 }
1710
1711 eventIter, err := createEventIterator(makeIter, makeNilIter, catConditions.event, allConditions, selectAll)
1712 if err != nil {
1713 return nil, fmt.Errorf("creating event iterator: %w", err)
1714 }
1715 if eventIter != nil {
1716 innerIterators = append(innerIterators, eventIter)
1717 }
1718
1719 linkIter, err := createLinkIterator(makeIter, makeNilIter, catConditions.link, allConditions, selectAll)
1720 if err != nil {
1721 return nil, fmt.Errorf("creating link iterator: %w", err)
1722 }
1723 if linkIter != nil {
1724 innerIterators = append(innerIterators, linkIter)
1725 }
1726
1727 spanIter, err := createSpanIterator(makeIter, makeNilIter, innerIterators, catConditions.span, allConditions, dc, selectAll, spanSampler)
1728 if err != nil {
1729 return nil, fmt.Errorf("creating span iterator: %w", err)
1730 }

Callers 1

fetchFunction · 0.70

Calls 9

categorizeConditionsFunction · 0.70
makeIterFuncFunction · 0.70
makeNilIterFuncFunction · 0.70
createEventIteratorFunction · 0.70
createLinkIteratorFunction · 0.70
createSpanIteratorFunction · 0.70
createResourceIteratorFunction · 0.70
createTraceIteratorFunction · 0.70

Tested by

no test coverage detected