[NO ISSUE] Cleanup / refactor upgrade code

Change-Id: Ic81e87e70eecf49b71f9d96b1ac7c7180a314564
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3174
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/LogicalComparatorUtil.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/LogicalComparatorUtil.java
index ddbabb2..29c6758 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/LogicalComparatorUtil.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/LogicalComparatorUtil.java
@@ -52,10 +52,6 @@
     }
 
     public static ILogicalBinaryComparator createLogicalComparator(IAType left, IAType right, boolean isEquality) {
-        // this should never happen, but for back-compat where types are missing and would be defaulted to null
-        if (left == null || right == null) {
-            return new LogicalScalarBinaryComparator(isEquality);
-        }
         IAType leftType = TypeComputeUtils.getActualType(left);
         IAType rightType = TypeComputeUtils.getActualType(right);
 
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java
index 6d8db59..2e48127 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java
@@ -19,7 +19,6 @@
 package org.apache.asterix.om.types;
 
 import org.apache.asterix.om.base.IAObject;
-import org.apache.hyracks.util.CompatibilityUtil;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -66,11 +65,7 @@
         public ObjectNode toJSON() {
             ObjectMapper om = new ObjectMapper();
             ObjectNode type = om.createObjectNode();
-            if (CompatibilityUtil.isAtLeast035()) {
-                type.put("type", "ALL_TYPE");
-            } else {
-                type.put("type", "ASTERIX_TYPE");
-            }
+            type.put("type", "ALL_TYPE");
             return type;
         }
     };
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/LSMBTreeLocalResource.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/LSMBTreeLocalResource.java
index cdd3ea2..3074e9e 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/LSMBTreeLocalResource.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/LSMBTreeLocalResource.java
@@ -43,7 +43,7 @@
 import org.apache.hyracks.storage.am.lsm.common.dataflow.LsmResource;
 import org.apache.hyracks.storage.common.IStorageManager;
 import org.apache.hyracks.storage.common.compression.NoOpCompressorDecompressorFactory;
-import org.apache.hyracks.util.CompatibilityUtil;
+import org.apache.hyracks.util.ReflectionUtils;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -141,7 +141,7 @@
 
         // compat w/ 0.3.4
         if (compressorDecompressorFactory == null) {
-            CompatibilityUtil.writeField(this, "compressorDecompressorFactory",
+            ReflectionUtils.writeField(this, "compressorDecompressorFactory",
                     NoOpCompressorDecompressorFactory.INSTANCE);
         }
     }
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/LSMBTreeLocalResourceFactory.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/LSMBTreeLocalResourceFactory.java
index 740b3d7..b3d61e8 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/LSMBTreeLocalResourceFactory.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/LSMBTreeLocalResourceFactory.java
@@ -35,7 +35,7 @@
 import org.apache.hyracks.storage.am.lsm.common.dataflow.LsmResourceFactory;
 import org.apache.hyracks.storage.common.IStorageManager;
 import org.apache.hyracks.storage.common.compression.NoOpCompressorDecompressorFactory;
-import org.apache.hyracks.util.CompatibilityUtil;
+import org.apache.hyracks.util.ReflectionUtils;
 
 public class LSMBTreeLocalResourceFactory extends LsmResourceFactory {
 
@@ -78,7 +78,7 @@
 
         // compat w/ 0.3.4
         if (compressorDecompressorFactory == null) {
-            CompatibilityUtil.writeField(this, "compressorDecompressorFactory",
+            ReflectionUtils.writeField(this, "compressorDecompressorFactory",
                     NoOpCompressorDecompressorFactory.INSTANCE);
         }
     }
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityLevel.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityLevel.java
deleted file mode 100644
index 2d0c8aa..0000000
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityLevel.java
+++ /dev/null
@@ -1,97 +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.hyracks.util;
-
-import java.io.ObjectStreamException;
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Objects;
-import java.util.stream.IntStream;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-public final class CompatibilityLevel implements Serializable, Comparable {
-    public static final CompatibilityLevel V_0_3_4 = fromSegments(0, 3, 4);
-    public static final CompatibilityLevel V_0_3_5 = fromSegments(0, 3, 5);
-
-    public static final CompatibilityLevel DEFAULT = V_0_3_5;
-
-    private final int level;
-
-    private CompatibilityLevel(int level) {
-        this.level = level;
-    }
-
-    public static CompatibilityLevel fromInt(int version) {
-        return new CompatibilityLevel(version);
-    }
-
-    public static CompatibilityLevel fromSegments(int... versionSegments) {
-        if (versionSegments.length > 4) {
-            throw new IllegalArgumentException(
-                    "a maximum of four version segments is supported; (was: " + Arrays.toString(versionSegments) + ")");
-        }
-        if (IntStream.of(versionSegments).anyMatch(i -> i > 0xff)) {
-            throw new IllegalArgumentException(
-                    "a version segment cannot exceed 255 (was: " + Arrays.toString(versionSegments) + ")");
-        }
-        int version = (versionSegments[0] & 0xff) << 24;
-        if (versionSegments.length > 1) {
-            version |= (versionSegments[1] & 0xff) << 16;
-        }
-        if (versionSegments.length > 2) {
-            version |= (versionSegments[2] & 0xff) << 8;
-        }
-        if (versionSegments.length > 3) {
-            version |= versionSegments[3] & 0xff;
-        }
-        return fromInt(version);
-    }
-
-    @Override
-    public int compareTo(Object o) {
-        return Integer.compareUnsigned(level, ((CompatibilityLevel) o).level);
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-        CompatibilityLevel that = (CompatibilityLevel) o;
-        return level == that.level;
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(level);
-    }
-
-    private Object writeReplace() throws ObjectStreamException {
-        return this;
-    }
-
-    public int intValue() {
-        return level;
-    }
-}
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java
deleted file mode 100644
index 8e77ef5..0000000
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java
+++ /dev/null
@@ -1,109 +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.hyracks.util;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-public class CompatibilityUtil {
-    private static final Logger LOGGER = LogManager.getLogger();
-    private static CompatibilityLevel compatLevel = CompatibilityLevel.DEFAULT;
-
-    private CompatibilityUtil() {
-    }
-
-    public static CompatibilityLevel getCompatibilityLevel() {
-        return compatLevel;
-    }
-
-    public static CompatibilityLevel setCompatibilityLevel(CompatibilityLevel newLevel) {
-        CompatibilityLevel prevLevel = compatLevel;
-        compatLevel = newLevel;
-        return prevLevel;
-    }
-
-    public static Field getAccessibleField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
-        Field f = clazz.getDeclaredField(fieldName);
-        f.setAccessible(true);
-        return f;
-    }
-
-    public static Field getAccessibleField(Object obj, String fieldName) throws NoSuchFieldException {
-        Class<?> cl = obj.getClass();
-        while (true) {
-            Field f = null;
-            try {
-                f = getAccessibleField(cl, fieldName);
-                return f;
-            } catch (NoSuchFieldException e) {
-                cl = cl.getSuperclass();
-                if (cl == null) {
-                    throw new NoSuchFieldException(
-                            "field: '" + fieldName + "' not found in (hierarchy of) " + obj.getClass());
-                }
-            }
-        }
-    }
-
-    public static Object readField(Object obj, String fieldName) throws IOException {
-        try {
-            return readField(obj, getAccessibleField(obj, fieldName));
-        } catch (NoSuchFieldException e) {
-            throw new IOException(e);
-        }
-    }
-
-    public static Object readField(Object obj, Field f) throws IOException {
-        Class<?> objClass = obj.getClass();
-        LOGGER.debug("reading field '{}' on object of type {}", f::getName, objClass::toString);
-        try {
-            return f.get(obj);
-        } catch (IllegalAccessException e) {
-            LOGGER.warn("exception reading field '{}' on object of type {}", f.getName(), objClass, e);
-            throw new IOException(e);
-        }
-    }
-
-    public static void writeField(Object obj, String fieldName, Object newValue) throws IOException {
-        try {
-            writeField(obj, getAccessibleField(obj, fieldName), newValue);
-        } catch (NoSuchFieldException e) {
-            throw new IOException(e);
-        }
-    }
-
-    public static void writeField(Object obj, Field f, Object newValue) throws IOException {
-        Class<?> objClass = obj.getClass();
-        LOGGER.debug("updating field '{}' on object of type {} to {}", f::getName, objClass::toString,
-                newValue::toString);
-        try {
-            f.set(obj, newValue);
-        } catch (IllegalAccessException e) {
-            LOGGER.warn("exception updating field '{}' object of type {} to {}", f.getName(), objClass, newValue, e);
-            throw new IOException(e);
-        }
-    }
-
-    public static boolean isAtLeast035() {
-        return getCompatibilityLevel().intValue() >= CompatibilityLevel.V_0_3_5.intValue();
-    }
-}
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ReflectionUtils.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ReflectionUtils.java
index 408d67f..a5c83f0 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ReflectionUtils.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ReflectionUtils.java
@@ -18,7 +18,18 @@
  */
 package org.apache.hyracks.util;
 
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
 public class ReflectionUtils {
+    private static final Logger LOGGER = LogManager.getLogger();
+
+    private ReflectionUtils() {
+    }
+
     public static <T> T createInstance(Class<? extends T> klass) {
         T instance = null;
         try {
@@ -30,4 +41,66 @@
         }
         return instance;
     }
+
+    public static Field getAccessibleField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
+        Field f = clazz.getDeclaredField(fieldName);
+        f.setAccessible(true);
+        return f;
+    }
+
+    public static Field getAccessibleField(Object obj, String fieldName) throws NoSuchFieldException {
+        Class<?> cl = obj.getClass();
+        while (true) {
+            Field f = null;
+            try {
+                f = getAccessibleField(cl, fieldName);
+                return f;
+            } catch (NoSuchFieldException e) {
+                cl = cl.getSuperclass();
+                if (cl == null) {
+                    throw new NoSuchFieldException(
+                            "field: '" + fieldName + "' not found in (hierarchy of) " + obj.getClass());
+                }
+            }
+        }
+    }
+
+    public static Object readField(Object obj, String fieldName) throws IOException {
+        try {
+            return readField(obj, getAccessibleField(obj, fieldName));
+        } catch (NoSuchFieldException e) {
+            throw new IOException(e);
+        }
+    }
+
+    public static Object readField(Object obj, Field f) throws IOException {
+        Class<?> objClass = obj.getClass();
+        LOGGER.debug("reading field '{}' on object of type {}", f::getName, objClass::toString);
+        try {
+            return f.get(obj);
+        } catch (IllegalAccessException e) {
+            LOGGER.warn("exception reading field '{}' on object of type {}", f.getName(), objClass, e);
+            throw new IOException(e);
+        }
+    }
+
+    public static void writeField(Object obj, String fieldName, Object newValue) throws IOException {
+        try {
+            writeField(obj, getAccessibleField(obj, fieldName), newValue);
+        } catch (NoSuchFieldException e) {
+            throw new IOException(e);
+        }
+    }
+
+    public static void writeField(Object obj, Field f, Object newValue) throws IOException {
+        Class<?> objClass = obj.getClass();
+        LOGGER.debug("updating field '{}' on object of type {} to {}", f::getName, objClass::toString,
+                newValue::toString);
+        try {
+            f.set(obj, newValue);
+        } catch (IllegalAccessException e) {
+            LOGGER.warn("exception updating field '{}' object of type {} to {}", f.getName(), objClass, newValue, e);
+            throw new IOException(e);
+        }
+    }
 }