public boolean accept(TypeInfo other) { return this.equals(other); }
@Override public Class<? extends UDAFEvaluator> getEvaluatorClass( List<TypeInfo> argTypeInfos) throws UDFArgumentException { // Go through the argClasses and for any string, void or date time, start // looking for doubles ArrayList<TypeInfo> args = new ArrayList<TypeInfo>(); for (TypeInfo arg : argTypeInfos) { if (arg.equals(TypeInfoFactory.voidTypeInfo) || arg.equals(TypeInfoFactory.stringTypeInfo)) { args.add(TypeInfoFactory.doubleTypeInfo); } else { args.add(arg); } } return super.getEvaluatorClass(args); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ArrayWritableObjectInspector that = (ArrayWritableObjectInspector) o; if (isRoot != that.isRoot || (typeInfo != null ? !typeInfo.equals(that.typeInfo) : that.typeInfo != null) || (fieldInfos != null ? !fieldInfos.equals(that.fieldInfos) : that.fieldInfos != null) || (fieldNames != null ? !fieldNames.equals(that.fieldNames) : that.fieldNames != null) || (fields != null ? !fields.equals(that.fields) : that.fields != null)) { return false; } return fieldsByName != null ? fieldsByName.equals(that.fieldsByName) : that.fieldsByName == null; }
/** * Given two types, determine whether conversion needs to occur to compare the two types. * This is needed for cases like varchar, where the TypeInfo for varchar(10) != varchar(5), * but there would be no need to have to convert to compare these values. * @param typeA * @param typeB * @return */ public static boolean isConversionRequiredForComparison(TypeInfo typeA, TypeInfo typeB) { if (typeA.equals(typeB)) { return false; } if (TypeInfoUtils.doPrimitiveCategoriesMatch(typeA, typeB)) { return false; } return true; }
@Override public boolean isSame(Object o) { if (!(o instanceof ExprNodeColumnDesc)) { return false; } ExprNodeColumnDesc dest = (ExprNodeColumnDesc) o; if (!column.equals(dest.getColumn())) { return false; } if (!typeInfo.equals(dest.getTypeInfo())) { return false; } if ( tabAlias != null && dest.tabAlias != null ) { if ( !tabAlias.equals(dest.tabAlias) ) { return false; } } return true; }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof ListTypeInfo)) { return false; } return getListElementTypeInfo().equals( ((ListTypeInfo) other).getListElementTypeInfo()); }
private Writable getWritableValue(TypeInfo ti, byte[] value) { if (ti.equals(TypeInfoFactory.stringTypeInfo)) { return new Text(value); } else if (ti.equals(TypeInfoFactory.varcharTypeInfo)) { return new HiveVarcharWritable( new HiveVarchar(new Text(value).toString(), -1)); } else if (ti.equals(TypeInfoFactory.binaryTypeInfo)) { return new BytesWritable(value); } return null; }
@Override public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException { if (parameters.length > 2) { throw new UDFArgumentTypeException(2, "At most 2 arguments expected"); } if (parameters.length > 1 && !parameters[1].equals(TypeInfoFactory.booleanTypeInfo)) { throw new UDFArgumentTypeException(1, "second argument must be a boolean expression"); } return createEvaluator(); }
@Override public boolean isSame(Object o) { if (!(o instanceof ExprNodeConstantDesc)) { return false; } ExprNodeConstantDesc dest = (ExprNodeConstantDesc) o; if (!typeInfo.equals(dest.getTypeInfo())) { return false; } if (value == null) { if (dest.getValue() != null) { return false; } } else if (!value.equals(dest.getValue())) { return false; } return true; }
@Override public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException { if (parameters.length > 2) { throw new UDFArgumentTypeException(2, "At most 2 arguments expected"); } if (parameters.length > 1 && !parameters[1].equals(TypeInfoFactory.booleanTypeInfo)) { throw new UDFArgumentTypeException(1, "second argument must be a boolean expression"); } return createEvaluator(); }
@Override public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException { if (parameters.length > 2) { throw new UDFArgumentTypeException(2, "At most 2 arguments expected"); } if (parameters.length > 1 && !parameters[1].equals(TypeInfoFactory.booleanTypeInfo)) { throw new UDFArgumentTypeException(1, "second argument must be a boolean expression"); } return createEvaluator(); }
@Override public boolean isSame(Object o) { if (!(o instanceof ExprNodeFieldDesc)) { return false; } ExprNodeFieldDesc dest = (ExprNodeFieldDesc) o; if (!typeInfo.equals(dest.getTypeInfo())) { return false; } if (!fieldName.equals(dest.getFieldName()) || !isList.equals(dest.getIsList()) || !desc.isSame(dest.getDesc())) { return false; } return true; }
@Override public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException { if (parameters.length > 2) { throw new UDFArgumentTypeException(2, "At most 2 arguments expected"); } if (parameters.length > 1 && !parameters[1].equals(TypeInfoFactory.booleanTypeInfo)) { throw new UDFArgumentTypeException(1, "second argument must be a boolean expression"); } return createEvaluator(); }
public KeyWrapper getKeyWrapper() { if (keyFields.length == 1 && TypeInfoUtils.getTypeInfoFromObjectInspector(keyObjectInspectors[0]).equals( TypeInfoFactory.stringTypeInfo)) { assert(TypeInfoUtils.getTypeInfoFromObjectInspector(currentKeyObjectInspectors[0]).equals( TypeInfoFactory.stringTypeInfo)); soi_new = (StringObjectInspector) keyObjectInspectors[0]; soi_copy = (StringObjectInspector) currentKeyObjectInspectors[0]; return new TextKeyWrapper(false); } else { currentStructEqualComparer = new ListObjectsEqualComparer(currentKeyObjectInspectors, currentKeyObjectInspectors); newKeyStructEqualComparer = new ListObjectsEqualComparer(currentKeyObjectInspectors, keyObjectInspectors); return new ListKeyWrapper(false); } }
public KeyWrapper getKeyWrapper() { if (keyFields.length == 1 && TypeInfoUtils.getTypeInfoFromObjectInspector(keyObjectInspectors[0]).equals( TypeInfoFactory.stringTypeInfo)) { assert(TypeInfoUtils.getTypeInfoFromObjectInspector(currentKeyObjectInspectors[0]).equals( TypeInfoFactory.stringTypeInfo)); soi_new = (StringObjectInspector) keyObjectInspectors[0]; soi_copy = (StringObjectInspector) currentKeyObjectInspectors[0]; return new TextKeyWrapper(false); } else { currentStructEqualComparer = new ListObjectsEqualComparer(currentKeyObjectInspectors, currentKeyObjectInspectors); newKeyStructEqualComparer = new ListObjectsEqualComparer(currentKeyObjectInspectors, keyObjectInspectors); return new ListKeyWrapper(false); } }
private static boolean sameTypeIndexSearchConditions(List<IndexSearchCondition> searchConditions) { for (IndexSearchCondition isc : searchConditions) { if (!isc.getColumnDesc().getTypeInfo().equals(isc.getConstantDesc().getTypeInfo())) { return false; } } return true; } }
/** * Returns whether it is possible to implicitly convert an object of Class * from to Class to. */ public static boolean implicitConvertible(TypeInfo from, TypeInfo to) { if (from.equals(to)) { return true; } // Reimplemented to use PrimitiveCategory rather than TypeInfo, because // 2 TypeInfos from the same qualified type (varchar, decimal) should still be // seen as equivalent. if (from.getCategory() == Category.PRIMITIVE && to.getCategory() == Category.PRIMITIVE) { return implicitConvertible( ((PrimitiveTypeInfo) from).getPrimitiveCategory(), ((PrimitiveTypeInfo) to).getPrimitiveCategory()); } return false; } }
@Test public void testFloatInExpressions() throws HiveException { ExprNodeColumnDesc col1Expr = new ExprNodeColumnDesc(Float.class, "col1", "table", false); ExprNodeConstantDesc constDesc = new ExprNodeConstantDesc(new Integer(10)); GenericUDFOPPlus udf = new GenericUDFOPPlus(); List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>(2); children1.add(col1Expr); children1.add(constDesc); ExprNodeGenericFuncDesc exprDesc = new ExprNodeGenericFuncDesc(TypeInfoFactory.doubleTypeInfo, udf, children1); List<String> columns = new ArrayList<String>(); columns.add("col1"); VectorizationContext vc = new VectorizationContext("name", columns); VectorExpression ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.PROJECTION); assertTrue(ve.getOutputTypeInfo().equals(TypeInfoFactory.doubleTypeInfo)); }