yihua commented on code in PR #5470:
URL: https://github.com/apache/hudi/pull/5470#discussion_r925017068
##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/io/storage/row/HoodieRowParquetWriteSupport.java:
##########
@@ -73,18 +75,15 @@ public WriteSupport.FinalizedWriteContext finalizeWrite() {
return new WriteSupport.FinalizedWriteContext(extraMetaData);
}
- public void add(String recordKey) {
- this.bloomFilter.add(recordKey);
- if (minRecordKey != null) {
- minRecordKey = minRecordKey.compareTo(recordKey) <= 0 ? minRecordKey :
recordKey;
- } else {
- minRecordKey = recordKey;
+ public void add(UTF8String recordKey) {
+ this.bloomFilter.add(recordKey.getBytes());
+
+ if (minRecordKey == null || minRecordKey.compareTo(recordKey) < 0) {
+ minRecordKey = recordKey.copy();
}
- if (maxRecordKey != null) {
- maxRecordKey = maxRecordKey.compareTo(recordKey) >= 0 ? maxRecordKey :
recordKey;
- } else {
- maxRecordKey = recordKey;
+ if (maxRecordKey == null || maxRecordKey.compareTo(recordKey) > 0) {
+ maxRecordKey = recordKey.copy();
Review Comment:
So looking at the UTF8String implementation, should we actually use `copy()`
instead since `clone()` may reference the same byte array:
```
@Override
public UTF8String clone() {
return fromBytes(getBytes());
}
public UTF8String copy() {
byte[] bytes = new byte[numBytes];
copyMemory(base, offset, bytes, BYTE_ARRAY_OFFSET, numBytes);
return fromBytes(bytes);
}
/**
* Creates an UTF8String from byte array, which should be encoded in UTF-8.
*
* Note: `bytes` will be hold by returned UTF8String.
*/
public static UTF8String fromBytes(byte[] bytes) {
if (bytes != null) {
return new UTF8String(bytes, BYTE_ARRAY_OFFSET, bytes.length);
} else {
return null;
}
}
/**
* Returns the underline bytes, will be a copy of it if it's part of
another array.
*/
public byte[] getBytes() {
// avoid copy if `base` is `byte[]`
if (offset == BYTE_ARRAY_OFFSET && base instanceof byte[]
&& ((byte[]) base).length == numBytes) {
return (byte[]) base;
} else {
byte[] bytes = new byte[numBytes];
copyMemory(base, offset, bytes, BYTE_ARRAY_OFFSET, numBytes);
return bytes;
}
}
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]