apache/druid · error · IllegalArgumentException

expected optimized path

Error message

expected optimized path

What it means

Assertion guard in compareTo(o, expectOptimized): the caller asserted that mixed-scale values never reach the slow BigDecimal-conversion path (e.g. a buffer aggregator guarantees uniform scale); it fired because two values with different scales were compared.

Solutions

  1. Ensure all compared values share the same scale (use Utils.objToCompressedBigDecimalWithScale).
  2. If mixed scales are legitimate, call compareTo(o, false) instead of asserting the optimized path.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at extensions-contrib/compressed-bigdecimal/src/main/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimal.java:386 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/b9a62dd7176aba58. Report an issue: GitHub.

Appendix: source

Thrown at extensions-contrib/compressed-bigdecimal/src/main/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimal.java:386

      }
    }
  }

  @Override
  public int compareTo(CompressedBigDecimal o)
  {
    return compareTo(o, false);
  }

  public int compareTo(CompressedBigDecimal o, boolean expectOptimized)
  {
    if (super.equals(o)) {
      return 0;
    } else if (getScale() == o.getScale()) {
      return directCompareCompressedBigDecimal(this, o);
    } else {
      if (expectOptimized) {
        throw new IAE("expected optimized path");
      }

      return this.toBigDecimal().compareTo(o.toBigDecimal());
    }
  }

  /**
   * performs a subtraction of lhs - rhs to compare elements
   *
   * @param lhs
   * @param rhs
   * @return
   */
  private static int directCompareCompressedBigDecimal(CompressedBigDecimal lhs, CompressedBigDecimal rhs)
  {
    // this short-circuit serves two functions: 1. it speeds up comparison in +/- cases 2. it avoids the case of
    // overflow of positive - negative and negative - positive. p - p and n - n both fit in the given allotment of ints
    if (lhs.isNonNegative() && rhs.isNegative()) {

View on GitHub (pinned to 9b90983fd2)