apache/druid · error · IllegalArgumentException
Cartesian product too large; must have size at most…
Error message
Cartesian product too large; must have size at most Integer.MAX_VALUE
What it means
Druid's CartesianList builds a cartesian product of several lists and precomputes axis size products with IntMath.checkedMultiply. If the total product size would exceed Integer.MAX_VALUE, it throws IllegalArgumentException instead of overflowing silently.
Solutions
- Reduce the number of elements in the input lists so the product fits under Integer.MAX_VALUE
- Restructure the computation to iterate lazily/streaming instead of materializing the full cartesian product
- Split the operation into batched smaller cartesian products
Example fix
// before
CartesianList.create(List.of(largeListA, largeListB, hugeListC));
// after
// limit or chunk axes first
if ((long)a.size()*b.size()*c.size() > Integer.MAX_VALUE) { /* batch */ } Defensive patterns
Strategy: validation
Validate before calling
long total = 1;
for (List<?> axis : axes) { total *= axis.size(); }
if (total > Integer.MAX_VALUE) throw new IllegalArgumentException("cartesian product too large"); Try / catch
try {
list = CartesianList.create(axes);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("Cartesian product too large")) {
// batch the computation
} else { throw e; }
} Prevention
- Estimate product size with long math before creating the list
- Batch or stream large cross-product computations
- Keep input axis sizes small and bounded
When it happens
Trigger: Calling CartesianList.create(...) with axes whose sizes multiply to more than 2^31-1, e.g. many moderately sized lists combined.
Common situations: Expression/array expansion code producing join-like combinations of large arrays; generated test data or cross-join-style computations over many columns; accidental use of a giant nested-array input.
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
- Already closed
- argument should be an identifier expression. Use array()…
- buffer for list is too small, was
- Cannot apply limit[ ] with offset[ ] due to overflow
- Cannot cast [ ] to [ ] (Types.InvalidCastException from…
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/464242a9096d35f0.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/math/expr/CartesianList.java:68
return Collections.emptyList();
}
axesBuilder.add(new ArrayList<>(list));
}
return new CartesianList<>(axesBuilder);
}
CartesianList(List<List<? extends E>> axes)
{
this.axes = axes;
int[] axesSizeProduct = new int[axes.size() + 1];
axesSizeProduct[axes.size()] = 1;
try {
for (int i = axes.size() - 1; i >= 0; i--) {
axesSizeProduct[i] = IntMath.checkedMultiply(axesSizeProduct[i + 1], axes.get(i).size());
}
}
catch (ArithmeticException e) {
throw new IllegalArgumentException(
"Cartesian product too large; must have size at most Integer.MAX_VALUE");
}
this.axesSizeProduct = axesSizeProduct;
}
private int getAxisIndexForProductIndex(int index, int axis)
{
return (index / axesSizeProduct[axis + 1]) % axes.get(axis).size();
}
@Override
public int indexOf(Object o)
{
if (!(o instanceof List)) {
return -1;
}
List<?> list = (List<?>) o;
if (list.size() != axes.size()) {View on GitHub (pinned to 9b90983fd2)