prestodb/presto · error · ArithmeticException

Division by zero

Error message

Division by zero

What it means

throwDivisionByZeroException is the central helper raised whenever a DECIMAL division or modulo has a zero divisor; it fires from the unscaled-128 arithmetic paths when users execute decimal division by zero.

Solutions

  1. Filter or NULL out zero divisors before the division
  2. Use NULLIF(divisor, 0) in SQL to avoid the divide-by-zero path
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at presto-common/src/main/java/com/facebook/presto/common/type/UnscaledDecimal128Arithmetic.java:1579 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/41692ae64dae2ef8. Report an issue: GitHub.

Appendix: source

Thrown at presto-common/src/main/java/com/facebook/presto/common/type/UnscaledDecimal128Arithmetic.java:1579

        long remainder = getLong(decimal, 1);
        long high = remainder / divisor;
        remainder %= divisor;

        remainder = (getInt(decimal, 1) & LONG_MASK) + (remainder << 32);
        int z1 = (int) (remainder / divisor);
        remainder %= divisor;

        remainder = (getInt(decimal, 0) & LONG_MASK) + (remainder << 32);
        int z0 = (int) (remainder / divisor);

        pack(result, z0, z1, high, isNegative(decimal));
        return (int) (remainder % divisor);
    }

    private static void throwDivisionByZeroException()
    {
        throw new ArithmeticException("Division by zero");
    }

    private static void multiplyShiftDestructive(Slice decimal, Slice multiplier, int rightShifts)
    {
        int[] product = new int[NUMBER_OF_INTS * 2];
        Slice multiplicationResult = Slices.wrappedIntArray(product);
        multiply256(decimal, multiplier, multiplicationResult);
        shiftRightArray8(product, rightShifts, decimal);
    }

    private static void setNegative(Slice decimal, boolean negative)
    {
        setRawInt(decimal, SIGN_INT_INDEX, getInt(decimal, SIGN_INT_INDEX) | (negative ? SIGN_INT_MASK : 0));
    }

    private static void setNegativeInt(Slice decimal, int v3, boolean negative)
    {
        if (v3 < 0) {

View on GitHub (pinned to 55bb57d202)