orc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject [1/2] orc git commit: ORC-360. Add Java error checking on the types when reading.
Date Mon, 07 May 2018 18:19:35 GMT
Repository: orc
Updated Branches:
  refs/heads/branch-1.4 7910fa968 -> ad33a70b1


ORC-360. Add Java error checking on the types when reading.

Fixes #266

Signed-off-by: Owen O'Malley <omalley@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/orc/repo
Commit: http://git-wip-us.apache.org/repos/asf/orc/commit/d5018d30
Tree: http://git-wip-us.apache.org/repos/asf/orc/tree/d5018d30
Diff: http://git-wip-us.apache.org/repos/asf/orc/diff/d5018d30

Branch: refs/heads/branch-1.4
Commit: d5018d309a8adc6b8e0567cb692a17371d16e108
Parents: 7910fa9
Author: Owen O'Malley <omalley@apache.org>
Authored: Mon May 7 09:19:17 2018 -0700
Committer: Owen O'Malley <omalley@apache.org>
Committed: Mon May 7 10:40:55 2018 -0700

----------------------------------------------------------------------
 java/core/src/java/org/apache/orc/OrcUtils.java | 56 +++++++++++++++++++-
 .../java/org/apache/orc/impl/ReaderImpl.java    |  1 +
 2 files changed, 55 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/orc/blob/d5018d30/java/core/src/java/org/apache/orc/OrcUtils.java
----------------------------------------------------------------------
diff --git a/java/core/src/java/org/apache/orc/OrcUtils.java b/java/core/src/java/org/apache/orc/OrcUtils.java
index 37e624c..361a177 100644
--- a/java/core/src/java/org/apache/orc/OrcUtils.java
+++ b/java/core/src/java/org/apache/orc/OrcUtils.java
@@ -19,6 +19,7 @@ package org.apache.orc;
 
 import org.apache.orc.impl.ReaderImpl;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -245,7 +246,7 @@ public class OrcUtils {
       {
         // Make room for MAP type.
         result.add(null);
-  
+
         // Add MAP type pair in order to determine their subtype values.
         appendOrcTypesRebuildSubtypes(result, children.get(0));
         int subtype2 = result.size();
@@ -383,7 +384,7 @@ public class OrcUtils {
       {
         // Make room for MAP type.
         result.add(null);
-  
+
         // Add MAP type pair in order to determine their subtype values.
         columnId = appendOrcTypesRebuildSubtypes(result, types, columnId);
         int subtype2 = result.size();
@@ -451,6 +452,57 @@ public class OrcUtils {
   }
 
   /**
+   * Checks whether the list of protobuf types from the file are valid or not.
+   * @param types the list of types from the protobuf
+   * @param root the top of the tree to check
+   * @return the next available id
+   * @throws java.io.IOException if the tree is invalid
+   */
+  public static int isValidTypeTree(List<OrcProto.Type> types,
+                                    int root) throws IOException  {
+    if (root < 0 || root >= types.size()) {
+      throw new IOException("Illegal type id " + root +
+          ". The valid range is 0 to " + (types.size() - 1));
+    }
+    OrcProto.Type rootType = types.get(root);
+    int current = root+1;
+    List<Integer> children = rootType.getSubtypesList();
+    if (!rootType.hasKind()) {
+      throw new IOException("Type " + root + " has an unknown kind.");
+    }
+    // ensure that we have the right number of children
+    switch(rootType.getKind()) {
+      case LIST:
+        if (children == null || children.size() != 1) {
+          throw new IOException("Wrong number of type children in list " + root);
+        }
+        break;
+      case MAP:
+        if (children == null || children.size() != 2) {
+          throw new IOException("Wrong number of type children in map " + root);
+        }
+        break;
+      case UNION:
+      case STRUCT:
+        break;
+      default:
+        if (children != null && children.size() != 0) {
+          throw new IOException("Type children under primitive type " + root);
+        }
+    }
+    // ensure the children are also correct
+    if (children != null) {
+      for(int child: children) {
+        if (child != current) {
+          throw new IOException("Unexpected child type id " + child + " when " +
+              current + " was expected.");
+        }
+        current = isValidTypeTree(types, current);
+      }
+    }
+    return current;
+  }
+  /**
    * Translate the given rootColumn from the list of types to a TypeDescription.
    * @param types all of the types
    * @param rootColumn translate this type

http://git-wip-us.apache.org/repos/asf/orc/blob/d5018d30/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
----------------------------------------------------------------------
diff --git a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
index 9146b23..80b7a60 100644
--- a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
+++ b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
@@ -381,6 +381,7 @@ public class ReaderImpl implements Reader {
       this.stripes = tail.getStripes();
       this.stripeStats = tail.getStripeStatisticsProto();
     }
+    OrcUtils.isValidTypeTree(this.types, 0);
     this.schema = OrcUtils.convertTypeFromProtobuf(this.types, 0);
   }
 


Mime
View raw message