siddharthteotia commented on code in PR #9278: URL: https://github.com/apache/pinot/pull/9278#discussion_r954569284
########## pinot-core/src/main/java/org/apache/pinot/core/common/ObjectSerDeUtils.java: ########## @@ -540,39 +538,38 @@ public byte[] serialize(Map<Object, Object> map) { return new byte[Integer.BYTES]; } - // No need to close these 2 streams - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); - - try { - // Write the size of the map - dataOutputStream.writeInt(size); - - // Write the serialized key-value pairs - Iterator<Map.Entry<Object, Object>> iterator = map.entrySet().iterator(); - // First write the key type and value type - Map.Entry<Object, Object> firstEntry = iterator.next(); - Object firstKey = firstEntry.getKey(); - Object firstValue = firstEntry.getValue(); - int keyTypeValue = ObjectType.getObjectType(firstKey).getValue(); - int valueTypeValue = ObjectType.getObjectType(firstValue).getValue(); - dataOutputStream.writeInt(keyTypeValue); - dataOutputStream.writeInt(valueTypeValue); - // Then write each key-value pair - for (Map.Entry<Object, Object> entry : map.entrySet()) { - byte[] keyBytes = ObjectSerDeUtils.serialize(entry.getKey(), keyTypeValue); - dataOutputStream.writeInt(keyBytes.length); - dataOutputStream.write(keyBytes); - - byte[] valueBytes = ObjectSerDeUtils.serialize(entry.getValue(), valueTypeValue); - dataOutputStream.writeInt(valueBytes.length); - dataOutputStream.write(valueBytes); - } - } catch (IOException e) { - throw new RuntimeException("Caught exception while serializing Map", e); + long bufferSize = (3 + 2 * (long) size) * Integer.BYTES; Review Comment: (nit) suggest giving a brief comment (for future readers) on what 3 and 2 means or may be use static final constant -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org