diff --git a/core/src/main/java/org/apache/iceberg/LocationProviders.java b/core/src/main/java/org/apache/iceberg/LocationProviders.java index 661ae6f86da1..962aee63e4a3 100644 --- a/core/src/main/java/org/apache/iceberg/LocationProviders.java +++ b/core/src/main/java/org/apache/iceberg/LocationProviders.java @@ -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; @@ -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; @@ -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 { @@ -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(); + } } } diff --git a/core/src/main/java/org/apache/iceberg/util/HashUtils.java b/core/src/main/java/org/apache/iceberg/util/HashUtils.java deleted file mode 100644 index d774c18af633..000000000000 --- a/core/src/main/java/org/apache/iceberg/util/HashUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.iceberg.util; - -import java.nio.charset.StandardCharsets; -import org.apache.iceberg.relocated.com.google.common.base.Preconditions; -import org.apache.iceberg.relocated.com.google.common.hash.HashFunction; -import org.apache.iceberg.relocated.com.google.common.hash.Hashing; - -public class HashUtils { - - private HashUtils() {} - - private static final HashFunction hashFunction = Hashing.sha1(); - private static final String allChars = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - - /** - * Compute hash containing alphanumeric characters - * - * @param fileName name of the file - * @return hash generated - */ - public static String computeHash(String fileName) { - Preconditions.checkState(fileName != null, "fileName cannot be null"); - byte[] messageDigest = - hashFunction.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(); - } -}