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

Function createIntPredicateFromFloat

tempodb/encoding/vparquet4/block_traceql.go:2758–2849  ·  view source on GitHub ↗

createIntPredicateFromFloat adapts a float-based query operand to an int column. If the float is exactly representable as an int64 (e.g. 42.0), we compare the column to that integer. Otherwise, if the float is non-integer or out of the int64 range, we return a "trivial" outcome: - "=" on a non-inte

(op traceql.Operator, operands traceql.Operands)

Source from the content-addressed store, hash-verified

2756//
2757// Note: If returning nil, no column-level filtering is applied for this condition.
2758func createIntPredicateFromFloat(op traceql.Operator, operands traceql.Operands) (parquetquery.Predicate, error) {
2759 if pred, handled := createExistencePredicate(op); handled {
2760 return pred, nil
2761 }
2762
2763 if len(operands) == 0 {
2764 return nil, fmt.Errorf("operands cannot be empty")
2765 }
2766
2767 switch operands[0].Type {
2768 case traceql.TypeFloat:
2769 f := operands[0].Float()
2770
2771 if math.IsNaN(f) {
2772 return nil, nil
2773 }
2774
2775 // Check if it's in [MinInt64, MaxInt64) range, and if so, see if it's an integer.
2776 if float64(math.MinInt64) <= f && f < float64(math.MaxInt64) {
2777 if intPart, frac := math.Modf(f); frac == 0 {
2778 intOperands := traceql.Operands{traceql.NewStaticInt(int(intPart))}
2779 return createIntPredicate(op, intOperands)
2780 }
2781 }
2782
2783 switch op {
2784 case traceql.OpEqual:
2785 return nil, nil
2786 case traceql.OpNotEqual:
2787 return parquetquery.NewCallbackPredicate(func() bool { return true }), nil
2788 case traceql.OpGreater, traceql.OpGreaterEqual:
2789 switch {
2790 case f < float64(math.MinInt64):
2791 return parquetquery.NewCallbackPredicate(func() bool { return true }), nil
2792 case float64(math.MaxInt64) <= f:
2793 return nil, nil
2794 case 0 < f:
2795 // "x > 10.3" -> "x >= 11"
2796 return parquetquery.NewIntGreaterEqualPredicate(int64(f) + 1), nil
2797 default:
2798 // "x > -2.7" -> "x >= -2"
2799 return parquetquery.NewIntGreaterEqualPredicate(int64(f)), nil
2800 }
2801 case traceql.OpLess, traceql.OpLessEqual:
2802 switch {
2803 case f < float64(math.MinInt64):
2804 return nil, nil
2805 case float64(math.MaxInt64) <= f:
2806 return parquetquery.NewCallbackPredicate(func() bool { return true }), nil
2807 case f < 0:
2808 // "x < -2.7" -> "x <= -3"
2809 return parquetquery.NewIntLessEqualPredicate(int64(f) - 1), nil
2810 default:
2811 // "x < 10.3" -> "x <= 10"
2812 return parquetquery.NewIntLessEqualPredicate(int64(f)), nil
2813 }
2814 default:
2815 return nil, fmt.Errorf("operator not supported for floats: %+v", op)

Callers 2

createDurationPredicateFunction · 0.70

Calls 11

NewStaticIntFunction · 0.92
NewCallbackPredicateFunction · 0.92
NewIntLessEqualPredicateFunction · 0.92
NewIntInPredicateFunction · 0.92
NewIntNotInPredicateFunction · 0.92
FloatMethod · 0.80
FloatArrayMethod · 0.80
EncodeToStringMethod · 0.80
createExistencePredicateFunction · 0.70
createIntPredicateFunction · 0.70

Tested by 1