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

Function createSpanIterator

tempodb/encoding/vparquet5/block_traceql.go:1986–2317  ·  view source on GitHub ↗

createSpanIterator iterates through all span-level columns, groups them into rows representing one span each. Spans are returned that match any of the given conditions.

(makeIter, makeNilIter makeIterFn, innerIterators []parquetquery.Iterator, conditions []traceql.Condition, allConditions bool, dedicatedColumns backend.DedicatedColumns, selectAll bool,
	sampler traceql.Sampler,
)

Source from the content-addressed store, hash-verified

1984// createSpanIterator iterates through all span-level columns, groups them into rows representing
1985// one span each. Spans are returned that match any of the given conditions.
1986func createSpanIterator(makeIter, makeNilIter makeIterFn, innerIterators []parquetquery.Iterator, conditions []traceql.Condition, allConditions bool, dedicatedColumns backend.DedicatedColumns, selectAll bool,
1987 sampler traceql.Sampler,
1988) (parquetquery.Iterator, error) {
1989 var (
1990 columnSelectAs = map[string]string{}
1991 columnPredicates = map[string][]parquetquery.Predicate{}
1992 iters []parquetquery.Iterator
1993 genericConditions []traceql.Condition
1994 columnMapping = dedicatedColumnsToColumnMapping(dedicatedColumns, backend.DedicatedColumnScopeSpan)
1995 nestedSetLeftExplicit = false
1996 nestedSetRightExplicit = false
1997 nestedSetParentExplicit = false
1998 )
1999
2000 // todo: improve these methods. if addPredicate gets a nil predicate shouldn't it just wipe out the existing predicates instead of appending?
2001 // nil predicate matches everything. what's the point of also evaluating a "real" predicate?
2002 addPredicate := func(columnPath string, p parquetquery.Predicate) {
2003 columnPredicates[columnPath] = append(columnPredicates[columnPath], p)
2004 }
2005
2006 addNilPredicateIfNotAlready := func(path string) {
2007 preds := columnPredicates[path]
2008 foundOpNone := false
2009
2010 // check to see if there is a nil predicate and only add if it doesn't exist
2011 for _, pred := range preds {
2012 if pred == nil {
2013 foundOpNone = true
2014 break
2015 }
2016 }
2017
2018 if !foundOpNone {
2019 addPredicate(path, nil)
2020 columnSelectAs[path] = path
2021 }
2022 }
2023
2024 specialCase := func(cond traceql.Condition, columnPath string) (handled bool) {
2025 // Operands that need special handling.
2026 switch cond.Op {
2027 case traceql.OpNone:
2028 addPredicate(columnPath, nil) // No filtering
2029 columnSelectAs[columnPath] = cond.Attribute.Name
2030 return true
2031 case traceql.OpExists:
2032 addPredicate(columnPath, &parquetquery.SkipNilsPredicate{})
2033 columnSelectAs[columnPath] = cond.Attribute.Name
2034 return true
2035 case traceql.OpNotExists:
2036 iters = append(iters, makeIter(columnPath, parquetquery.NewNilValuePredicate(), cond.Attribute.Name))
2037 return true
2038 default:
2039 return false
2040 }
2041 }
2042
2043 for _, cond := range conditions {

Callers 1

createAllIteratorFunction · 0.70

Calls 15

NewNilValuePredicateFunction · 0.92
NewLeftJoinIteratorFunction · 0.92
WithPoolFunction · 0.92
ToStaticTypeMethod · 0.80
createBytesPredicateFunction · 0.70
createIntPredicateFunction · 0.70
newSamplingPredicateFunction · 0.70
createStringPredicateFunction · 0.70
createDurationPredicateFunction · 0.70

Tested by

no test coverage detected