{"record":{"id":"1507a33ef807b773","repo":"apache/druid","slug":"possible-data-truncation-param-f-is-out-of-lon","errorCode":null,"errorMessage":"Possible data truncation, param [%f] is out of LONG value range","messagePattern":"Possible data truncation, param \\[(.+?)\\] is out of LONG value range","errorType":"validation","errorClass":"ExpressionValidationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/vector/VectorMathProcessors.java","lineNumber":827,"sourceCode":"\n    public Ulp()\n    {\n      super(l -> Math.ulp((double) l), Math::ulp);\n    }\n  }\n\n\n  public static final class BitwiseComplement extends SimpleVectorMathUnivariateLongProcessorFactory\n  {\n    private static final BitwiseComplement INSTANCE = new BitwiseComplement();\n\n    public BitwiseComplement()\n    {\n      super(\n          input -> ~input,\n          input -> {\n            if (input < Long.MIN_VALUE || input > Long.MAX_VALUE) {\n              throw new ExpressionValidationException(\n                  Function.BitwiseComplement.NAME,\n                  \"Possible data truncation, param [%f] is out of LONG value range\",\n                  input\n              );\n            }\n            return ~((long) input);\n          }\n      );\n    }\n  }\n\n  public static class BitwiseConvertDoubleToLongBits extends SimpleVectorMathUnivariateLongProcessorFactory\n  {\n    private static final BitwiseConvertDoubleToLongBits INSTANCE = new BitwiseConvertDoubleToLongBits();\n\n    public BitwiseConvertDoubleToLongBits()\n    {\n      super(Double::doubleToLongBits, Double::doubleToLongBits);","sourceCodeStart":809,"sourceCodeEnd":845,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/vector/VectorMathProcessors.java#L809-L845","documentation":"Thrown by the BitwiseComplement (~) vector expression processor when its double-typed input is outside the range of a Java long. Applying bitwise complement to a value that cannot be losslessly narrowed to a long would silently truncate the data, so Druid fails fast with an ExpressionValidationException naming the offending parameter value.","triggerScenarios":"Evaluating a Druid expression like `~x` (BitwiseComplement) in a vectorized query where the input column or expression yields a double outside [Long.MIN_VALUE, Long.MAX_VALUE] (e.g. values >= 2^63 or <= -2^63, including from large numeric columns or division results).","commonSituations":"Bitwise operators applied to double-valued columns that contain very large magnitudes; ingesting numbers as 'double' but then using `~` on them; comparing timestamps stored as doubles since epoch millis; passing floats where longs are expected.","solutions":["Cast or round the input to a long before applying `~` in the expression (e.g. use CAST(x AS BIGINT) or explicit long math).","Change the column's SQL type in the ingestion spec to 'long' if the underlying data is integral, so the vector processor receives long inputs directly.","Clamp or validate the data upstream so values stay within [-9223372036854775808, 9223372036854775807].","If the value legitimately exceeds long range, drop the bitwise operation; `~` is not meaningful for such magnitudes."],"exampleFix":"// before: ~x on a double column with huge values -> ExpressionValidationException\n// after\n\"expression\": \"~CAST(x AS BIGINT)\"  // or store x as a long column in the ingestion spec","handlingStrategy":"validation","validationCode":"// validate before building the expression\nif (value < Long.MIN_VALUE || value > Long.MAX_VALUE) {\n  throw new IllegalArgumentException(\"~ requires value within LONG range, got: \" + value);\n}","typeGuard":"boolean inLongRange(double v) {\n  return v >= (double) Long.MIN_VALUE && v <= (double) Long.MAX_VALUE;\n}","tryCatchPattern":"try {\n  result = expr.eval(bindings);\n} catch (ExpressionValidationException e) {\n  if (e.getMessage().contains(\"out of LONG value range\")) {\n    result = null; // or clamp/coerce\n  } else {\n    throw e;\n  }\n}","preventionTips":["Store integral data as 'long' columns, not 'double', when bitwise operators will be used.","CAST to BIGINT in expressions before applying ~ or other bitwise functions.","Validate upstream data ranges at ingestion time for columns feeding bitwise expressions."],"tags":["expression","numeric-range","vectorized-query","bitwise"],"backgroundTag":"value-out-of-range","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}