apache/cassandra · error · ArithmeticException
Log10 of number zero or less
Error message
Log10 of number zero or less
What it means
IntegerType.log10 computes the base-10 logarithm of an integer value. Because log10 is mathematically undefined for zero and negative numbers, the method proactively throws ArithmeticException when the parsed BigInteger is <= 0 instead of letting BigDecimal math fail later.
Solutions
- Validate the input is strictly positive before calling log10 (e.g. WHERE col > 0 or application-side check).
- Use a CASE/IF expression in CQL to guard: log10(col) only when col > 0, else a fallback value.
- If negatives are expected, take abs() first or handle the domain explicitly in application code.
Example fix
// before SELECT log10(delta) FROM metrics; // after SELECT CASE WHEN delta > 0 THEN log10(delta) ELSE null END FROM metrics;
Defensive patterns
Strategy: validation
Validate before calling
if (value == null || value.signum() <= 0) throw new IllegalArgumentException("log10 requires a value > 0, got: " + value); Prevention
- Validate positivity at the application boundary before issuing log10 in a query.
- Use CASE WHEN in CQL to guard function arguments.
- Remember log10's domain excludes 0 and negatives; document that constraint for API consumers.
When it happens
Trigger: Calling log10() (via the log10 CQL native function or directly on IntegerType.instance) with a value of 0, a negative number, or a value that converts to BigInteger <= 0.
Common situations: CQL queries like SELECT log10(col) where col is 0 or negative; user-supplied function arguments not validated by the application; log math applied to counters or deltas that can be zero or negative.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Natural log of number zero or less
- A NaN cannot be converted into a decimal
- An infinite number cannot be converted into a decimal
- Invalid operation ( ) for non-numeric type
- Log10 of number zero or less
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/49b4e9603bac3f68.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/db/marshal/IntegerType.java:584
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);
}
@Override
public ByteBuffer round(Number input)
{
return decompose(toBigInteger(input));
}
@Override
public ByteBuffer getMaskedValue()
{
return MASKED_VALUE;
}
}View on GitHub (pinned to 88fd0f6a0e)