Skip to content

Commit

Permalink
MINOR: Make ColumnPath immutable (#1380)
Browse files Browse the repository at this point in the history
Similar to `ColumnPath.toArray`, but avoids copying the path.
  • Loading branch information
findepi authored Jul 9, 2024
1 parent 0876679 commit 515ed4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

public final class ColumnPath implements Iterable<String>, Serializable {
Expand Down Expand Up @@ -48,6 +50,8 @@ public static ColumnPath get(String... path) {
private final String[] p;

private ColumnPath(String[] path) {
// No need to copy the array here as the only published ColumnPath instances are created by the toCanonical
// method
this.p = path;
}

Expand Down Expand Up @@ -83,6 +87,10 @@ public int size() {
}

public String[] toArray() {
return p;
return p.clone();
}

public List<String> toList() {
return Collections.unmodifiableList(Arrays.asList(p));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.apache.parquet.crypto;

import java.util.Arrays;
import org.apache.parquet.format.BlockCipher;
import org.apache.parquet.format.ColumnCryptoMetaData;
import org.apache.parquet.format.EncryptionWithColumnKey;
Expand Down Expand Up @@ -48,7 +47,7 @@ public class InternalColumnEncryptionSetup {
columnCryptoMetaData = ColumnCryptoMetaData.ENCRYPTION_WITH_FOOTER_KEY(new EncryptionWithFooterKey());
} else {
EncryptionWithColumnKey withColumnKeyStruct = new EncryptionWithColumnKey(
Arrays.asList(encryptionProperties.getPath().toArray()));
encryptionProperties.getPath().toList());
if (null != encryptionProperties.getKeyMetaData()) {
withColumnKeyStruct.setKey_metadata(encryptionProperties.getKeyMetaData());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ private void addRowGroup(
ColumnMetaData metaData = new ColumnMetaData(
getType(columnMetaData.getType()),
toFormatEncodings(columnMetaData.getEncodings()),
Arrays.asList(columnMetaData.getPath().toArray()),
columnMetaData.getPath().toList(),
toFormatCodec(columnMetaData.getCodec()),
columnMetaData.getValueCount(),
columnMetaData.getTotalUncompressedSize(),
Expand Down

0 comments on commit 515ed4c

Please sign in to comment.