From 13b0fe436183b0c92bc1a9927cf1871e662805bd Mon Sep 17 00:00:00 2001 From: Raghav Aggarwal Date: Fri, 10 Jul 2026 02:11:45 +0530 Subject: [PATCH] HIVE-29719: NegativeArraySizeException in HybridGrace HashJoin due to integer overflow --- .../hive/ql/exec/persistence/HybridHashTableContainer.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/persistence/HybridHashTableContainer.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/persistence/HybridHashTableContainer.java index 53bf42dafbbe..4fe8794b7532 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/persistence/HybridHashTableContainer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/persistence/HybridHashTableContainer.java @@ -701,12 +701,17 @@ public static int calcNumPartitions(long memoryThreshold, long dataSize, int min int minWbSize) throws IOException { int numPartitions = minNumParts; - if (memoryThreshold < minNumParts * minWbSize) { + if (memoryThreshold < (long) minNumParts * minWbSize) { LOG.warn("Available memory is not enough to create a HybridHashTableContainer!"); } if (memoryThreshold / 2 < dataSize) { // The divided-by-2 logic is consistent to MapJoinOperator.reloadHashTable while (dataSize / numPartitions > memoryThreshold / 2) { + // Prevent integer overflow + if (numPartitions > Integer.MAX_VALUE / 2) { + throw new IOException("Cannot create a Hybrid Grace Hash Join with a table size this large (" + + dataSize + " bytes) against a memory threshold of " + memoryThreshold + " bytes"); + } numPartitions *= 2; } }