prestodb/presto · error · IllegalArgumentException

Total rows is larger than 2^64

Error message

Total rows is larger than 2^64

What it means

TpchMetadata.calculateTotalRows computes a table's row count as scaleBase * scaleFactor. Because the result must fit in a Java long, any product exceeding Long.MAX_VALUE (~9.2e18) throws this IllegalArgumentException. It guards TpchTable row-count generation (e.g. getTableLayoutForConstraint computing row counts for statistics).

Source

Thrown at presto-tpch/src/main/java/com/facebook/presto/tpch/TpchMetadata.java:559

            case IDENTIFIER:
                return BIGINT;
            case INTEGER:
                return INTEGER;
            case DATE:
                return DATE;
            case DOUBLE:
                return DOUBLE;
            case VARCHAR:
                return createVarcharType((int) (long) tpchType.getPrecision().get());
        }
        throw new IllegalArgumentException("Unsupported type " + tpchType);
    }

    private long calculateTotalRows(int scaleBase, double scaleFactor)
    {
        double totalRows = scaleBase * scaleFactor;
        if (totalRows > Long.MAX_VALUE) {
            throw new IllegalArgumentException("Total rows is larger than 2^64");
        }
        return (long) totalRows;
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Reduce the configured TPC-H scale factor to a supported value (e.g. sf1–sf10000).
  2. Verify the scale factor configuration/property is parsed with the correct units (no accidental multiplication).
  3. If larger datasets are genuinely needed, split the workload or use a different connector designed for huge scale.

Example fix

// before
properties.put("tpch.scale-factor", 100000000.0); // overflows row counts
// after
properties.put("tpch.scale-factor", 100.0);
Defensive patterns

Strategy: validation

Validate before calling

double totalRows = scaleBase * scaleFactor;
if (totalRows > (double) Long.MAX_VALUE) {
    throw new IllegalArgumentException("Scale factor too large: " + scaleFactor);
}

Try / catch

try {
    layout = metadata.getTableLayoutForConstraint(...);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("Total rows")) {
        // lower the scale factor and retry
    }
}

Prevention

When it happens

Trigger: Calling getTableLayoutForConstraint (or any caller of calculateTotalRows) with a scale factor so large that scaleBase * scaleFactor overflows Long.MAX_VALUE — practically, TPC-H scale factors far beyond the supported range.

Common situations: Configuring the TPCH connector with an enormous scale factor (e.g. sf1000000+) or misconfigured scale properties where a percentage/factor string is parsed incorrectly, producing an astronomically large multiplier.

Related errors


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