/** * Generate the hashCode for this TypeInfo. */ @Override public int hashCode() { return getLength(); }
public int getMaxLength() { VarcharTypeInfo ti = (VarcharTypeInfo) typeInfo; return ti.getLength(); }
public int getMaxLength() { return ((VarcharTypeInfo)typeInfo).getLength(); }
public LazyHiveVarchar(LazyHiveVarcharObjectInspector oi) { super(oi); maxLength = ((VarcharTypeInfo)oi.getTypeInfo()).getLength(); data = new HiveVarcharWritable(); }
LazyBinaryHiveVarchar(WritableHiveVarcharObjectInspector oi) { super(oi); maxLength = ((VarcharTypeInfo)oi.getTypeInfo()).getLength(); data = new HiveVarcharWritable(); }
private static int getVarcharLength(TypeInfo hiveType) { int length = -1; if (hiveType instanceof PrimitiveTypeInfo) { PrimitiveTypeInfo hivePrimitiveType = (PrimitiveTypeInfo) hiveType; switch (hivePrimitiveType.getPrimitiveCategory()) { case CHAR: length = ((CharTypeInfo) hivePrimitiveType).getLength(); break; case VARCHAR: length = ((VarcharTypeInfo) hivePrimitiveType).getLength(); break; default: break; } } return length; } }
private Field allocatePrimitiveField(TypeInfo sourceTypeInfo, DataTypePhysicalVariation dataTypePhysicalVariation) { final PrimitiveTypeInfo sourcePrimitiveTypeInfo = (PrimitiveTypeInfo) sourceTypeInfo; final PrimitiveCategory sourcePrimitiveCategory = sourcePrimitiveTypeInfo.getPrimitiveCategory(); final int maxLength; switch (sourcePrimitiveCategory) { case CHAR: maxLength = ((CharTypeInfo) sourcePrimitiveTypeInfo).getLength(); break; case VARCHAR: maxLength = ((VarcharTypeInfo) sourcePrimitiveTypeInfo).getLength(); break; default: // No additional data type specific setting. maxLength = 0; break; } return new Field(sourcePrimitiveCategory, dataTypePhysicalVariation, maxLength); }
@Override public HiveVarchar getPrimitiveJavaObject(Object o) { // check input object's length, if it doesn't match // then output a new primitive with the correct params. if (o == null) { return null; } if ((o instanceof Text) || (o instanceof TimestampWritableV2) || (o instanceof HiveDecimalWritable) || (o instanceof DoubleWritable) || (o instanceof FloatWritable) || (o instanceof LongWritable) || (o instanceof IntWritable) || (o instanceof BooleanWritable)) { String str = o.toString(); return new HiveVarchar(str, ((VarcharTypeInfo)typeInfo).getLength()); } HiveVarcharWritable writable = ((HiveVarcharWritable)o); if (doesWritableMatchTypeParams(writable)) { return writable.getHiveVarchar(); } return getPrimitiveWithParams(writable); }
private void initTargetEntry(int logicalColumnIndex, int projectionColumnNum, TypeInfo typeInfo) { isConvert[logicalColumnIndex] = false; projectionColumnNums[logicalColumnIndex] = projectionColumnNum; targetTypeInfos[logicalColumnIndex] = typeInfo; if (typeInfo.getCategory() == Category.PRIMITIVE) { final PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo) typeInfo; final PrimitiveCategory primitiveCategory = primitiveTypeInfo.getPrimitiveCategory(); switch (primitiveCategory) { case CHAR: maxLengths[logicalColumnIndex] = ((CharTypeInfo) primitiveTypeInfo).getLength(); break; case VARCHAR: maxLengths[logicalColumnIndex] = ((VarcharTypeInfo) primitiveTypeInfo).getLength(); break; default: // No additional data type specific setting. break; } } }
@Override public HiveVarcharWritable getPrimitiveWritableObject(Object o) { // check input object's length, if it doesn't match // then output new writable with correct params. if (o == null) { return null; } if ((o instanceof Text) || (o instanceof TimestampWritableV2) || (o instanceof HiveDecimalWritable) || (o instanceof DoubleWritable) || (o instanceof FloatWritable) || (o instanceof LongWritable) || (o instanceof IntWritable) || (o instanceof BooleanWritable)) { String str = o.toString(); HiveVarcharWritable hcw = new HiveVarcharWritable(); hcw.set(str, ((VarcharTypeInfo)typeInfo).getLength()); return hcw; } HiveVarcharWritable writable = ((HiveVarcharWritable)o); if (doesWritableMatchTypeParams((HiveVarcharWritable)o)) { return writable; } return getWritableWithParams(writable); }
@Override public HiveVarchar getPrimitiveJavaObject(Object o) { if (o == null) { return null; } HiveVarchar ret = ((LazyHiveVarchar) o).getWritableObject().getHiveVarchar(); if (!BaseCharUtils.doesPrimitiveMatchTypeParams( ret, (VarcharTypeInfo)typeInfo)) { HiveVarchar newValue = new HiveVarchar(ret, ((VarcharTypeInfo)typeInfo).getLength()); return newValue; } return ret; }
public static HiveVarchar getRandHiveVarchar(Random r, VarcharTypeInfo varcharTypeInfo, boolean isUnicodeOk) { final int maxLength = 1 + r.nextInt(varcharTypeInfo.getLength()); final String randomString = getRandString(r, 100, isUnicodeOk); return new HiveVarchar(randomString, maxLength); }
@Override public Object copyObject(Object o) { if (o == null) { return null; } if (o instanceof Text) { String str = ((Text)o).toString(); HiveVarcharWritable hcw = new HiveVarcharWritable(); hcw.set(str, ((VarcharTypeInfo)typeInfo).getLength()); return hcw; } HiveVarcharWritable writable = (HiveVarcharWritable)o; if (doesWritableMatchTypeParams((HiveVarcharWritable)o)) { return new HiveVarcharWritable(writable); } return getWritableWithParams(writable); }
private void initTargetEntry(int logicalColumnIndex, int projectionColumnNum, TypeInfo typeInfo) { isConvert[logicalColumnIndex] = false; projectionColumnNums[logicalColumnIndex] = projectionColumnNum; Category category = typeInfo.getCategory(); targetCategories[logicalColumnIndex] = category; if (category == Category.PRIMITIVE) { PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo) typeInfo; PrimitiveCategory primitiveCategory = primitiveTypeInfo.getPrimitiveCategory(); targetPrimitiveCategories[logicalColumnIndex] = primitiveCategory; switch (primitiveCategory) { case CHAR: maxLengths[logicalColumnIndex] = ((CharTypeInfo) primitiveTypeInfo).getLength(); break; case VARCHAR: maxLengths[logicalColumnIndex] = ((VarcharTypeInfo) primitiveTypeInfo).getLength(); break; default: // No additional data type specific setting. break; } } }
private void initEntry(int logicalColumnIndex, int projectionColumnNum, TypeInfo typeInfo) { projectionColumnNums[logicalColumnIndex] = projectionColumnNum; Category category = typeInfo.getCategory(); categories[logicalColumnIndex] = category; if (category == Category.PRIMITIVE) { PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo) typeInfo; PrimitiveCategory primitiveCategory = primitiveTypeInfo.getPrimitiveCategory(); primitiveCategories[logicalColumnIndex] = primitiveCategory; switch (primitiveCategory) { case CHAR: maxLengths[logicalColumnIndex] = ((CharTypeInfo) primitiveTypeInfo).getLength(); break; case VARCHAR: maxLengths[logicalColumnIndex] = ((VarcharTypeInfo) primitiveTypeInfo).getLength(); break; default: // No additional data type specific setting. break; } primitiveWritables[logicalColumnIndex] = VectorizedBatchUtil.getPrimitiveWritable(primitiveCategory); } }
private void initSourceEntry(int logicalColumnIndex, int projectionColumnNum, TypeInfo sourceTypeInfo) { isConvert[logicalColumnIndex] = false; projectionColumnNums[logicalColumnIndex] = projectionColumnNum; Category sourceCategory = sourceTypeInfo.getCategory(); sourceCategories[logicalColumnIndex] = sourceCategory; if (sourceCategory == Category.PRIMITIVE) { PrimitiveTypeInfo sourcePrimitiveTypeInfo = (PrimitiveTypeInfo) sourceTypeInfo; PrimitiveCategory sourcePrimitiveCategory = sourcePrimitiveTypeInfo.getPrimitiveCategory(); sourcePrimitiveCategories[logicalColumnIndex] = sourcePrimitiveCategory; switch (sourcePrimitiveCategory) { case CHAR: maxLengths[logicalColumnIndex] = ((CharTypeInfo) sourcePrimitiveTypeInfo).getLength(); break; case VARCHAR: maxLengths[logicalColumnIndex] = ((VarcharTypeInfo) sourcePrimitiveTypeInfo).getLength(); break; default: // No additional data type specific setting. break; } } else { // We don't currently support complex types. Preconditions.checkState(false); } }
return createUnboundedVarcharType(); case VARCHAR: return createVarcharType(((VarcharTypeInfo) typeInfo).getLength()); case CHAR: return createCharType(((CharTypeInfo) typeInfo).getLength());
public static TypeQualifiers fromTypeInfo(PrimitiveTypeInfo pti) { TypeQualifiers result = null; if (pti instanceof VarcharTypeInfo) { result = new TypeQualifiers(); result.setCharacterMaximumLength(((VarcharTypeInfo)pti).getLength()); } else if (pti instanceof CharTypeInfo) { result = new TypeQualifiers(); result.setCharacterMaximumLength(((CharTypeInfo)pti).getLength()); } else if (pti instanceof DecimalTypeInfo) { result = new TypeQualifiers(); result.setPrecision(((DecimalTypeInfo)pti).precision()); result.setScale(((DecimalTypeInfo)pti).scale()); } return result; }
private void addTopLevelConversion(int logicalColumnIndex, TypeInfo targetTypeInfo) { final Field field = topLevelFields[logicalColumnIndex]; field.setIsConvert(true); if (field.getIsPrimitive()) { PrimitiveTypeInfo targetPrimitiveTypeInfo = (PrimitiveTypeInfo) targetTypeInfo; switch (targetPrimitiveTypeInfo.getPrimitiveCategory()) { case CHAR: field.setMaxLength(((CharTypeInfo) targetPrimitiveTypeInfo).getLength()); break; case VARCHAR: field.setMaxLength(((VarcharTypeInfo) targetPrimitiveTypeInfo).getLength()); break; default: // No additional data type specific setting. break; } field.setConversionWritable( VectorizedBatchUtil.getPrimitiveWritable(field.getPrimitiveCategory())); } }