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

Function createIntPredicateFromFloat

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

2837//
2838// Note: If returning nil, no column-level filtering is applied for this condition.
2839func createIntPredicateFromFloat(op traceql.Operator, operands traceql.Operands) (parquetquery.Predicate, error) {
2840 if pred, handled := createExistencePredicate(op); handled {
2841 return pred, nil
2842 }
2843
2844 if len(operands) == 0 {
2845 return nil, fmt.Errorf("operands cannot be empty")
2846 }
2847
2848 switch operands[0].Type {
2849 case traceql.TypeFloat:
2850 f := operands[0].Float()
2851
2852 if math.IsNaN(f) {
2853 return nil, nil
2854 }
2855
2856 // Check if it's in [MinInt64, MaxInt64) range, and if so, see if it's an integer.
2857 if float64(math.MinInt64) <= f && f < float64(math.MaxInt64) {
2858 if intPart, frac := math.Modf(f); frac == 0 {
2859 intOperands := traceql.Operands{traceql.NewStaticInt(int(intPart))}
2860 return createIntPredicate(op, intOperands)
2861 }
2862 }
2863
2864 switch op {
2865 case traceql.OpEqual:
2866 return nil, nil
2867 case traceql.OpNotEqual:
2868 return parquetquery.NewCallbackPredicate(func() bool { return true }), nil
2869 case traceql.OpGreater, traceql.OpGreaterEqual:
2870 switch {
2871 case f < float64(math.MinInt64):
2872 return parquetquery.NewCallbackPredicate(func() bool { return true }), nil
2873 case float64(math.MaxInt64) <= f:
2874 return nil, nil
2875 case 0 < f:
2876 // "x > 10.3" -> "x >= 11"
2877 return parquetquery.NewIntGreaterEqualPredicate(int64(f) + 1), nil
2878 default:
2879 // "x > -2.7" -> "x >= -2"
2880 return parquetquery.NewIntGreaterEqualPredicate(int64(f)), nil
2881 }
2882 case traceql.OpLess, traceql.OpLessEqual:
2883 switch {
2884 case f < float64(math.MinInt64):
2885 return nil, nil
2886 case float64(math.MaxInt64) <= f:
2887 return parquetquery.NewCallbackPredicate(func() bool { return true }), nil
2888 case f < 0:
2889 // "x < -2.7" -> "x <= -3"
2890 return parquetquery.NewIntLessEqualPredicate(int64(f) - 1), nil
2891 default:
2892 // "x < 10.3" -> "x <= 10"
2893 return parquetquery.NewIntLessEqualPredicate(int64(f)), nil
2894 }
2895 default:
2896 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