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

Function createSpanIterator

tempodb/encoding/vparquet4/block_traceql.go:1907–2236  ·  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

1905// createSpanIterator iterates through all span-level columns, groups them into rows representing
1906// one span each. Spans are returned that match any of the given conditions.
1907func createSpanIterator(makeIter, makeNilIter makeIterFn, innerIterators []parquetquery.Iterator, conditions []traceql.Condition, allConditions bool, dedicatedColumns backend.DedicatedColumns, selectAll bool,
1908 sampler traceql.Sampler,
1909) (parquetquery.Iterator, error) {
1910 var (
1911 columnSelectAs = map[string]string{}
1912 columnPredicates = map[string][]parquetquery.Predicate{}
1913 iters []parquetquery.Iterator
1914 genericConditions []traceql.Condition
1915 columnMapping = dedicatedColumnsToColumnMapping(dedicatedColumns, backend.DedicatedColumnScopeSpan)
1916 nestedSetLeftExplicit = false
1917 nestedSetRightExplicit = false
1918 nestedSetParentExplicit = false
1919 )
1920
1921 // todo: improve these methods. if addPredicate gets a nil predicate shouldn't it just wipe out the existing predicates instead of appending?
1922 // nil predicate matches everything. what's the point of also evaluating a "real" predicate?
1923 addPredicate := func(columnPath string, p parquetquery.Predicate) {
1924 columnPredicates[columnPath] = append(columnPredicates[columnPath], p)
1925 }
1926
1927 addNilPredicateIfNotAlready := func(path string) {
1928 preds := columnPredicates[path]
1929 foundOpNone := false
1930
1931 // check to see if there is a nil predicate and only add if it doesn't exist
1932 for _, pred := range preds {
1933 if pred == nil {
1934 foundOpNone = true
1935 break
1936 }
1937 }
1938
1939 if !foundOpNone {
1940 addPredicate(path, nil)
1941 columnSelectAs[path] = path
1942 }
1943 }
1944
1945 specialCase := func(cond traceql.Condition, columnPath string) (handled bool) {
1946 // Operands that need special handling.
1947 switch cond.Op {
1948 case traceql.OpNone:
1949 addPredicate(columnPath, nil) // No filtering
1950 columnSelectAs[columnPath] = cond.Attribute.Name
1951 return true
1952 case traceql.OpExists:
1953 addPredicate(columnPath, &parquetquery.SkipNilsPredicate{})
1954 columnSelectAs[columnPath] = cond.Attribute.Name
1955 return true
1956 case traceql.OpNotExists:
1957 iters = append(iters, makeIter(columnPath, parquetquery.NewNilValuePredicate(), cond.Attribute.Name))
1958 return true
1959 default:
1960 return false
1961 }
1962 }
1963
1964 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
isMatchingColumnTypeFunction · 0.70

Tested by

no test coverage detected