apache/cassandra · error · ArithmeticException
Natural log of number zero or less
Error message
Natural log of number zero or less
What it means
IntegerType.log(Number) computes the natural log of a varint by first converting the input to a BigInteger; if the value is zero or negative it throws ArithmeticException with this message, mirroring Math.log's domain restriction. This is a mathematical domain error: log is only defined for strictly positive inputs.
Solutions
- Guard the input and only call log(x) when x > 0 (e.g. log(x + 1) or filter WHERE x > 0 first)
- Handle negative/zero domain needs explicitly in the query (CASE/IF expressions)
- Fix upstream data producing non-positive values
- Catch ArithmeticException around the function invocation if input cannot be pre-validated
Example fix
// before SELECT log(delta) FROM events; // delta can be 0 or negative // after SELECT CASE WHEN delta > 0 THEN log(delta) ELSE NULL END FROM events;
Defensive patterns
Strategy: try-catch
Validate before calling
BigInteger bi = toBigInteger(input);
if (bi.signum() <= 0) throw new IllegalArgumentException("log() requires a positive value, got: " + bi); Type guard
static boolean isLogSafe(Number n) { return toBigInteger(n).signum() > 0; } Try / catch
try { ByteBuffer r = IntegerType.instance.log(input); } catch (ArithmeticException e) { /* non-positive input; return NULL or default */ } Prevention
- Filter or CASE-guard non-positive operands in queries using log()
- Validate column data domains (positivity) before using math functions
- Prefer log(x + 1) when zero values are legitimate
- Add data-quality checks for sign-sensitive columns
When it happens
Trigger: Calling IntegerType.instance.log(number) (e.g. via the log() CQL native function) with 0 or a negative varint argument; toBigInteger(input).compareTo(BigInteger.ZERO) <= 0 triggers the throw.
Common situations: User-supplied function arguments of 0 or negative values in SELECT log(x); data columns that unexpectedly contain zero/negative values (sensor dropouts, accounting deltas); sign errors in computed expressions.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Log10 of number zero or less
- A maximum number of tokens per node is supported
- A NaN cannot be converted into a decimal
- A repair_session_space of
- A repair_session_space of
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/10af7452f9386fca.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/db/marshal/IntegerType.java:573
{
return decompose(toBigInteger(input).abs());
}
@Override
public ByteBuffer exp(Number input)
{
BigInteger bi = toBigInteger(input);
BigDecimal bd = new BigDecimal(bi);
BigDecimal result = DecimalType.instance.exp(bd);
BigInteger out = result.toBigInteger();
return IntegerType.instance.decompose(out);
}
@Override
public ByteBuffer log(Number input)
{
BigInteger bi = toBigInteger(input);
if (bi.compareTo(BigInteger.ZERO) <= 0) throw new ArithmeticException("Natural log of number zero or less");
BigDecimal bd = new BigDecimal(bi);
BigDecimal result = DecimalType.instance.log(bd);
BigInteger out = result.toBigInteger();
return IntegerType.instance.decompose(out);
}
@Override
public ByteBuffer log10(Number input)
{
BigInteger bi = toBigInteger(input);
if (bi.compareTo(BigInteger.ZERO) <= 0) throw new ArithmeticException("Log10 of number zero or less");
BigDecimal bd = new BigDecimal(bi);
BigDecimal result = DecimalType.instance.log10(bd);
BigInteger out = result.toBigInteger();
return IntegerType.instance.decompose(out);
}
@OverrideView on GitHub (pinned to 88fd0f6a0e)