diff --git ql/src/java/org/apache/hadoop/hive/ql/metadata/VirtualColumn.java ql/src/java/org/apache/hadoop/hive/ql/metadata/VirtualColumn.java index 3549143..55eaad5 100644 --- ql/src/java/org/apache/hadoop/hive/ql/metadata/VirtualColumn.java +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/VirtualColumn.java @@ -40,8 +40,11 @@ import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; +/** + * Note that instances of this class are immutable and each is a "singleton". Like an enum. + */ @InterfaceAudience.Private -public class VirtualColumn implements Serializable { +public final class VirtualColumn implements Serializable { private static final long serialVersionUID = 1L; @@ -73,6 +76,7 @@ private final TypeInfo typeInfo; private final boolean isHidden; private final ObjectInspector oi; + private final int hash; private VirtualColumn(String name, PrimitiveTypeInfo typeInfo) { this(name, typeInfo, true, @@ -84,6 +88,9 @@ private VirtualColumn(String name, TypeInfo typeInfo, boolean isHidden, ObjectIn this.typeInfo = typeInfo; this.isHidden = isHidden; this.oi = oi; + int c = 19; + c = 31 * name.hashCode() + c; + hash = 31 * typeInfo.getTypeName().hashCode() + c; } public static List getStatsRegistry(Configuration conf) { @@ -126,21 +133,11 @@ public ObjectInspector getObjectInspector() { @Override public boolean equals(Object o) { - if (this == o) { - return true; - } - if(!(o instanceof VirtualColumn)) { - return false; - } - VirtualColumn c = (VirtualColumn) o; - return this.name.equals(c.name) - && this.typeInfo.getTypeName().equals(c.getTypeInfo().getTypeName()); + return this == o; } @Override public int hashCode() { - int c = 19; - c = 31 * name.hashCode() + c; - return 31 * typeInfo.getTypeName().hashCode() + c; + return hash; } public static Collection removeVirtualColumns(final Collection columns) { Iterables.removeAll(columns, VIRTUAL_COLUMN_NAMES);