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)
| 2195 | // |
| 2196 | // Note: If returning nil, no column-level filtering is applied for this condition. |
| 2197 | func createIntPredicateFromFloat(op traceql.Operator, operands traceql.Operands) (parquetquery.Predicate, error) { |
| 2198 | if pred, handled := createExistencePredicate(op); handled { |
| 2199 | return pred, nil |
| 2200 | } |
| 2201 | |
| 2202 | if len(operands) == 0 { |
| 2203 | return nil, fmt.Errorf("operands cannot be empty") |
| 2204 | } |
| 2205 | |
| 2206 | switch operands[0].Type { |
| 2207 | case traceql.TypeFloat: |
| 2208 | f := operands[0].Float() |
| 2209 | |
| 2210 | if math.IsNaN(f) { |
| 2211 | return nil, nil |
| 2212 | } |
| 2213 | |
| 2214 | // Check if it's in [MinInt64, MaxInt64) range, and if so, see if it's an integer. |
| 2215 | if float64(math.MinInt64) <= f && f < float64(math.MaxInt64) { |
| 2216 | if intPart, frac := math.Modf(f); frac == 0 { |
| 2217 | intOperands := traceql.Operands{traceql.NewStaticInt(int(intPart))} |
| 2218 | return createIntPredicate(op, intOperands) |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | switch op { |
| 2223 | case traceql.OpEqual: |
| 2224 | return nil, nil |
| 2225 | case traceql.OpNotEqual: |
| 2226 | return parquetquery.NewCallbackPredicate(func() bool { return true }), nil |
| 2227 | case traceql.OpGreater, traceql.OpGreaterEqual: |
| 2228 | switch { |
| 2229 | case f < float64(math.MinInt64): |
| 2230 | return parquetquery.NewCallbackPredicate(func() bool { return true }), nil |
| 2231 | case float64(math.MaxInt64) <= f: |
| 2232 | return nil, nil |
| 2233 | case 0 < f: |
| 2234 | // "x > 10.3" -> "x >= 11" |
| 2235 | return parquetquery.NewIntGreaterEqualPredicate(int64(f) + 1), nil |
| 2236 | default: |
| 2237 | // "x > -2.7" -> "x >= -2" |
| 2238 | return parquetquery.NewIntGreaterEqualPredicate(int64(f)), nil |
| 2239 | } |
| 2240 | case traceql.OpLess, traceql.OpLessEqual: |
| 2241 | switch { |
| 2242 | case f < float64(math.MinInt64): |
| 2243 | return nil, nil |
| 2244 | case float64(math.MaxInt64) <= f: |
| 2245 | return parquetquery.NewCallbackPredicate(func() bool { return true }), nil |
| 2246 | case f < 0: |
| 2247 | // "x < -2.7" -> "x <= -3" |
| 2248 | return parquetquery.NewIntLessEqualPredicate(int64(f) - 1), nil |
| 2249 | default: |
| 2250 | // "x < 10.3" -> "x <= 10" |
| 2251 | return parquetquery.NewIntLessEqualPredicate(int64(f)), nil |
| 2252 | } |
| 2253 | default: |
| 2254 | return nil, fmt.Errorf("operator not supported for floats: %+v", op) |