This is an automated email from the ASF dual-hosted git repository.
danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new 60caf5f42398 fix: Avoid relocated protobuf linkage in ORC footer reads
(#20150)
60caf5f42398 is described below
commit 60caf5f423989ff6d07136407bc8b0c20ee04c65
Author: Xinyao Zhang <[email protected]>
AuthorDate: Fri Oct 2 23:09:37 2026 -0400
fix: Avoid relocated protobuf linkage in ORC footer reads (#20150)
---
.../java/org/apache/hudi/common/util/OrcUtils.java | 10 ++-------
.../hudi/gcp/bundle/ITGcpBundleCompatibility.java | 26 ++++++++++++++++++++++
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git
a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/OrcUtils.java
b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/OrcUtils.java
index d80d7829894f..c85e00978ee0 100644
--- a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/OrcUtils.java
+++ b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/util/OrcUtils.java
@@ -44,7 +44,6 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
import org.apache.orc.OrcFile;
-import org.apache.orc.OrcProto.UserMetadataItem;
import org.apache.orc.Reader;
import org.apache.orc.Reader.Options;
import org.apache.orc.RecordReader;
@@ -64,7 +63,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
-import java.util.stream.Collectors;
import static org.apache.hudi.common.util.BinaryUtil.toBytes;
import static org.apache.hudi.common.util.StringUtils.fromUTF8Bytes;
@@ -207,13 +205,9 @@ public class OrcUtils extends FileFormatUtils {
try (Reader reader = OrcFile.createReader(
convertToHadoopPath(filePath),
OrcFile.readerOptions(storage.getConf().unwrapAs(Configuration.class)))) {
Map<String, String> footerVals = new HashMap<>();
- List<UserMetadataItem> metadataItemList =
reader.getFileTail().getFooter().getMetadataList();
- Map<String, String> metadata =
metadataItemList.stream().collect(Collectors.toMap(
- UserMetadataItem::getName,
- metadataItem -> metadataItem.getValue().toStringUtf8()));
for (String footerName : footerNames) {
- if (metadata.containsKey(footerName)) {
- footerVals.put(footerName, metadata.get(footerName));
+ if (reader.hasMetadataValue(footerName)) {
+ footerVals.put(footerName,
fromUTF8Bytes(toBytes(reader.getMetadataValue(footerName))));
} else if (required) {
throw new MetadataNotFoundException(
"Could not find index in ORC footer. Looked for key " +
footerName + " in " + filePath);
diff --git
a/packaging/hudi-gcp-bundle/src/test/java/org/apache/hudi/gcp/bundle/ITGcpBundleCompatibility.java
b/packaging/hudi-gcp-bundle/src/test/java/org/apache/hudi/gcp/bundle/ITGcpBundleCompatibility.java
index 45a2ff18b53b..3b5a799f4ff1 100644
---
a/packaging/hudi-gcp-bundle/src/test/java/org/apache/hudi/gcp/bundle/ITGcpBundleCompatibility.java
+++
b/packaging/hudi-gcp-bundle/src/test/java/org/apache/hudi/gcp/bundle/ITGcpBundleCompatibility.java
@@ -23,12 +23,19 @@ import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.storage.StorageOptions;
import org.junit.jupiter.api.Test;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.InputStream;
import java.lang.reflect.Method;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
class ITGcpBundleCompatibility {
@@ -47,6 +54,25 @@ class ITGcpBundleCompatibility {
runSmokeTest(ClasspathOrder.BUNDLE_FIRST);
}
+ @Test
+ void testOrcUtilsDoesNotLinkToShadedProtobuf() throws Exception {
+ try (JarFile bundle = new JarFile(System.getProperty("gcp.bundle.jar"))) {
+ JarEntry entry =
bundle.getJarEntry("org/apache/hudi/common/util/OrcUtils.class");
+ assertNotNull(entry);
+ try (InputStream input = bundle.getInputStream(entry);
+ ByteArrayOutputStream output = new ByteArrayOutputStream()) {
+ byte[] buffer = new byte[4096];
+ int count;
+ while ((count = input.read(buffer)) != -1) {
+ output.write(buffer, 0, count);
+ }
+ String bytecode = new String(output.toByteArray(),
StandardCharsets.ISO_8859_1);
+
assertFalse(bytecode.contains("org/apache/hudi/gcp/shaded/com/google/protobuf/"),
+ "OrcUtils must not link to protobuf types relocated by the GCP
bundle");
+ }
+ }
+ }
+
private static void runSmokeTest(ClasspathOrder order) throws Exception {
String bundleJar = System.getProperty("gcp.bundle.jar");
String testClasses = System.getProperty("gcp.test.classes");