Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Prashant Singh committed Mar 17, 2023
1 parent dc5b0cf commit 89a7d66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 54 deletions.
23 changes: 21 additions & 2 deletions core/src/main/java/org/apache/iceberg/LocationProviders.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
*/
package org.apache.iceberg;

import java.nio.charset.StandardCharsets;
import java.util.Map;
import org.apache.hadoop.fs.Path;
import org.apache.iceberg.common.DynConstructors;
import org.apache.iceberg.io.LocationProvider;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.util.HashUtils;
import org.apache.iceberg.relocated.com.google.common.hash.HashFunction;
import org.apache.iceberg.relocated.com.google.common.hash.Hashing;
import org.apache.iceberg.util.LocationUtil;
import org.apache.iceberg.util.PropertyUtil;

Expand Down Expand Up @@ -103,6 +105,10 @@ public String newDataLocation(String filename) {

static class ObjectStoreLocationProvider implements LocationProvider {

private static final HashFunction HASH_FUNCTION = Hashing.sha1();

private static final String allChars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
private final String storageLocation;
private final String context;

Expand Down Expand Up @@ -139,7 +145,7 @@ public String newDataLocation(PartitionSpec spec, StructLike partitionData, Stri

@Override
public String newDataLocation(String filename) {
String hash = HashUtils.computeHash(filename);
String hash = computeHash(filename);
if (context != null) {
return String.format("%s/%s/%s/%s", storageLocation, hash, context, filename);
} else {
Expand All @@ -163,5 +169,18 @@ private static String pathContext(String tableLocation) {

return resolvedContext;
}

private static String computeHash(String fileName) {
Preconditions.checkState(fileName != null, "fileName cannot be null");
byte[] messageDigest =
HASH_FUNCTION.hashBytes(fileName.getBytes(StandardCharsets.UTF_8)).asBytes();

StringBuilder hash = new StringBuilder();
for (int i = 0; i < 8; ++i) {
hash.append(allChars.charAt((messageDigest[i] % 62 + 62) % 62));
}

return hash.toString();
}
}
}
52 changes: 0 additions & 52 deletions core/src/main/java/org/apache/iceberg/util/HashUtils.java

This file was deleted.

0 comments on commit 89a7d66

Please sign in to comment.