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

Function createAllIterator

tempodb/encoding/vparquet5/block_traceql.go:1701–1771  ·  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

1699}
1700
1701func createAllIterator(ctx context.Context, primaryIter parquetquery.Iterator, conditions []traceql.Condition, allConditions bool, start, end uint64, rgs []parquet.RowGroup,
1702 pf *parquet.File, dc backend.DedicatedColumns, selectAll bool,
1703 traceSampler traceql.Sampler,
1704 spanSampler traceql.Sampler,
1705) (parquetquery.Iterator, error) {
1706 // categorize conditions by scope
1707 catConditions, mingledConditions, err := categorizeConditions(conditions)
1708 if err != nil {
1709 return nil, err
1710 }
1711
1712 makeIter := makeIterFunc(ctx, rgs, pf)
1713 makeNilIter := makeNilIterFunc(ctx, rgs, pf)
1714
1715 // Global state
1716 // Span-filtering behavior changes depending on the resource-filtering in effect,
1717 // and vice-versa. For example consider the query { span.a=1 }. If no spans have a=1
1718 // then it generate the empty spanset.
1719 // However once we add a resource condition: { span.a=1 || resource.b=2 }, now the span
1720 // filtering must return all spans, even if no spans have a=1, because they might be
1721 // matched upstream to a resource.
1722 // TODO - After introducing AllConditions it seems like some of this logic overlaps.
1723 // Determine if it can be generalized or simplified.
1724
1725 // Don't return the final spanset upstream unless it matched at least 1 condition
1726 // anywhere, except in the case of the empty query: {}
1727 batchRequireAtLeastOneMatchOverall := len(conditions) > 0 && len(catConditions.trace) == 0
1728
1729 // Optimization for queries like {resource.x... && span.y ...}
1730 // Requires no mingled scopes like .foo=x, which could be satisfied
1731 // one either resource or span.
1732 allConditions = allConditions && !mingledConditions
1733
1734 innerIterators := make([]parquetquery.Iterator, 0, 3)
1735 if primaryIter != nil {
1736 innerIterators = append(innerIterators, primaryIter)
1737 }
1738
1739 eventIter, err := createEventIterator(makeIter, makeNilIter, catConditions.event, allConditions, dc, selectAll)
1740 if err != nil {
1741 return nil, fmt.Errorf("creating event iterator: %w", err)
1742 }
1743 if eventIter != nil {
1744 innerIterators = append(innerIterators, eventIter)
1745 }
1746
1747 linkIter, err := createLinkIterator(makeIter, makeNilIter, catConditions.link, allConditions, selectAll)
1748 if err != nil {
1749 return nil, fmt.Errorf("creating link iterator: %w", err)
1750 }
1751 if linkIter != nil {
1752 innerIterators = append(innerIterators, linkIter)
1753 }
1754
1755 spanIter, err := createSpanIterator(makeIter, makeNilIter, innerIterators, catConditions.span, allConditions, dc, selectAll, spanSampler)
1756 if err != nil {
1757 return nil, fmt.Errorf("creating span iterator: %w", err)
1758 }

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