{"record":{"id":"73c46095b063a139","repo":"prestodb/presto","slug":"can-not-grow-array-beyond-s-73c460","errorCode":null,"errorMessage":"Can not grow array beyond '%s'","messagePattern":"Can not grow array beyond '(.+?)'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/unnest/UnnestOperatorBlockUtil.java","lineNumber":39,"sourceCode":"\n    private static final int DEFAULT_CAPACITY = 64;\n    // See java.util.ArrayList for an explanation\n    static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;\n\n    // Copied from io.prestosql.spi.block.BlockUtil#calculateNewArraySize\n    static int calculateNewArraySize(int currentSize)\n    {\n        // grow array by 50%\n        long newSize = (long) currentSize + (currentSize >> 1);\n\n        // verify new size is within reasonable bounds\n        if (newSize < DEFAULT_CAPACITY) {\n            newSize = DEFAULT_CAPACITY;\n        }\n        else if (newSize > MAX_ARRAY_SIZE) {\n            newSize = MAX_ARRAY_SIZE;\n            if (newSize == currentSize) {\n                throw new IllegalArgumentException(format(\"Can not grow array beyond '%s'\", MAX_ARRAY_SIZE));\n            }\n        }\n        return (int) newSize;\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":45,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/unnest/UnnestOperatorBlockUtil.java#L21-L45","documentation":"UnnestOperatorBlockUtil.calculateNewArraySize grows internal block builder arrays geometrically, capping growth at MAX_ARRAY_SIZE. If the current array is already at the cap and a larger size is still requested, growth is impossible and an IllegalArgumentException is thrown.","triggerScenarios":"Unnesting extremely large collections such that an internal block builder array already at MAX_ARRAY_SIZE (~2^30-ish elements) is asked to grow further — e.g. unnesting billions of total replicated elements in one operator.","commonSituations":"Cross-joining many rows with huge arrays/maps, amplifying total element counts past the array cap; queries with missing LIMIT or heavy fan-out.","solutions":["Reduce unnest fan-out: add a LIMIT, filter rows, or unnest smaller arrays.","Split the work into multiple smaller queries/batches instead of one giant unnest.","Increase query max memory limits so results can be spooled differently, or restructure to aggregate instead of replicate."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"-- bound unnest fan-out before running:\n-- SELECT count(*) * max(cardinality(arr)) over () FROM t;  ensure far below 2^30","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid cross-joins with huge arrays; add LIMIT or filters.","Estimate total replicated element count before unnesting.","Break oversized workloads into batches."],"tags":["unnest","memory","capacity-limit"],"backgroundTag":"array-capacity-exceeded","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}