From a2afdd0c9f8606a5b66afdb3987d4953243df6b4 Mon Sep 17 00:00:00 2001 From: Oscar Torreno Date: Thu, 25 Jul 2024 23:17:56 +0200 Subject: [PATCH] Fix supportVectoredIO for bad hadoop version string There are cases where the hadoop version info may not be respecting the semantic versioning. It is the case for the hadoop version provided in some of the AWS managed services. This causes a ExceptionInInitializerError while trying to instantiate and ORC file reader. Fixing this by defaulting to non vectored IO in case the semantic versioning is not respected --- .../apache/orc/impl/RecordReaderUtils.java | 3 +- .../java/org/apache/orc/impl/HadoopShims.java | 20 +++++---- .../orc/impl/TestHadoopShimsPost3_3_4.java | 41 +++++++++++++++++++ 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 java/shims/src/test/org/apache/orc/impl/TestHadoopShimsPost3_3_4.java diff --git a/java/core/src/java/org/apache/orc/impl/RecordReaderUtils.java b/java/core/src/java/org/apache/orc/impl/RecordReaderUtils.java index 0eabb421e01..100303b238d 100644 --- a/java/core/src/java/org/apache/orc/impl/RecordReaderUtils.java +++ b/java/core/src/java/org/apache/orc/impl/RecordReaderUtils.java @@ -23,6 +23,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.common.io.DiskRangeList; +import org.apache.hadoop.util.VersionInfo; import org.apache.orc.CompressionCodec; import org.apache.orc.DataReader; import org.apache.orc.OrcProto; @@ -48,7 +49,7 @@ */ public class RecordReaderUtils { private static final HadoopShims SHIMS = HadoopShimsFactory.get(); - private static final boolean supportVectoredIO = SHIMS.supportVectoredIO(); + private static final boolean supportVectoredIO = SHIMS.supportVectoredIO(VersionInfo.getVersion()); private static final Logger LOG = LoggerFactory.getLogger(RecordReaderUtils.class); private static class DefaultDataReader implements DataReader { diff --git a/java/shims/src/java/org/apache/orc/impl/HadoopShims.java b/java/shims/src/java/org/apache/orc/impl/HadoopShims.java index 2ae0364f25e..292785df74d 100644 --- a/java/shims/src/java/org/apache/orc/impl/HadoopShims.java +++ b/java/shims/src/java/org/apache/orc/impl/HadoopShims.java @@ -132,13 +132,19 @@ ByteBuffer readBuffer(int maxLength, */ boolean endVariableLengthBlock(OutputStream output) throws IOException; - default boolean supportVectoredIO() { - // HADOOP-18103 is available since Apache Hadoop 3.3.5+ - String[] versionParts = VersionInfo.getVersion().split("[.]"); - int major = Integer.parseInt(versionParts[0]); - int minor = Integer.parseInt(versionParts[1]); - int patch = Integer.parseInt(versionParts[2]); - return major == 3 && (minor > 3 || (minor == 3 && patch > 4)); + default boolean supportVectoredIO(String version) { + try { + // HADOOP-18103 is available since Apache Hadoop 3.3.5+ + String[] versionParts = version.split("[.]"); + int major = Integer.parseInt(versionParts[0]); + int minor = Integer.parseInt(versionParts[1]); + int patch = Integer.parseInt(versionParts[2]); + return major == 3 && (minor > 3 || (minor == 3 && patch > 4)); + } catch (final NumberFormatException e) { + // There could be cases where we are not able to parse the version + // Here we are defaulting to the non vectoredIO if that is the case + return false; + } } /** diff --git a/java/shims/src/test/org/apache/orc/impl/TestHadoopShimsPost3_3_4.java b/java/shims/src/test/org/apache/orc/impl/TestHadoopShimsPost3_3_4.java new file mode 100644 index 00000000000..e6a7c47b3b5 --- /dev/null +++ b/java/shims/src/test/org/apache/orc/impl/TestHadoopShimsPost3_3_4.java @@ -0,0 +1,41 @@ +/* + * 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.orc.impl; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class TestHadoopShimsPost3_3_4 { + + @Test + public void testWrongVersionForSupportVectoredIO() { + assertFalse(new HadoopShimsCurrent().supportVectoredIO("3.3.6-co-3")); + } + + @Test + public void testOlderVersionForSupportVectoredIO() { + assertFalse(new HadoopShimsCurrent().supportVectoredIO("3.3.4")); + } + + @Test + public void testSupportedVersionForSupportVectoredIO() { + assertTrue(new HadoopShimsCurrent().supportVectoredIO("3.3.5")); + } +}