public static String getTypeName(TypeInfo typeInfo, DataTypePhysicalVariation dataTypePhysicalVariation) { if (typeInfo == null) { return "<input type is null>"; } if (dataTypePhysicalVariation != null && dataTypePhysicalVariation != DataTypePhysicalVariation.NONE) { return typeInfo.toString() + "/" + dataTypePhysicalVariation; } else { return typeInfo.toString(); } }
@Override public String toString() { return "Const " + typeInfo.toString() + " " + value; }
public String getTypeString() { return outputTypeInfo.toString(); }
@Override public String toString() { return "Const " + typeInfo.toString() + " " + value; }
public List<String> outputColumnsAndTypesToStringList(int[] outputColumns, TypeInfo[] typeInfos) { final int size = outputColumns.length; ArrayList<String> result = new ArrayList<String>(size); for (int i = 0; i < size; i++) { result.add(outputColumns[i] + ":" + typeInfos[i].toString()); } return result; }
@Override public void write(DataOutput out) throws IOException { out.writeUTF(name); out.writeUTF(typeInfo.toString()); }
public static List<String> getTypeStringsFromTypeInfo(List<TypeInfo> typeInfos) { if (typeInfos == null) { return null; } List<String> result = new ArrayList<>(typeInfos.size()); for (TypeInfo typeInfo : typeInfos) { result.add(typeInfo.toString()); } return result; }
public String toString() { StringBuilder sb = new StringBuilder(); sb.append("(value column: " + valueColumn); sb.append(", type info: " + typeInfo.toString() + ")"); return sb.toString(); } }
public String toString() { StringBuilder sb = new StringBuilder(); sb.append("(value column: " + valueColumn); sb.append(", type info: " + typeInfo.toString() + ")"); return sb.toString(); } }
public static boolean lazyCompareMap(MapTypeInfo mapTypeInfo, Map<Object, Object> map, Map<Object, Object> expectedMap) { TypeInfo keyTypeInfo = mapTypeInfo.getMapKeyTypeInfo(); TypeInfo valueTypeInfo = mapTypeInfo.getMapValueTypeInfo(); if (map.size() != expectedMap.size()) { throw new RuntimeException("Map key/value deserialized map.size() " + map.size() + " map " + map.toString() + " expectedMap.size() " + expectedMap.size() + " expectedMap " + expectedMap.toString() + " does not match keyTypeInfo " + keyTypeInfo.toString() + " valueTypeInfo " + valueTypeInfo.toString()); } return true; }
public static boolean lazyCompareList(ListTypeInfo listTypeInfo, List<Object> list, List<Object> expectedList) { TypeInfo elementTypeInfo = listTypeInfo.getListElementTypeInfo(); final int size = list.size(); for (int i = 0; i < size; i++) { Object lazyEleObj = list.get(i); Object expectedEleObj = expectedList.get(i); if (!lazyCompare(elementTypeInfo, lazyEleObj, expectedEleObj)) { throw new RuntimeException("List element deserialized value does not match elementTypeInfo " + elementTypeInfo.toString()); } } return true; }
public void add(int orderedColumn, int valueColumn, TypeInfo typeInfo) { if (orderedTreeMap.containsKey(orderedColumn)) { throw new RuntimeException( name + " duplicate column " + orderedColumn + " in ordered column map " + orderedTreeMap.toString() + " when adding value column " + valueColumn + ", type into " + typeInfo.toString()); } orderedTreeMap.put(orderedColumn, new Value(valueColumn, typeInfo)); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getName()); sb.append("("); boolean isfirst = true; for (TypeInfo cls : getTypeArray()) { if (!isfirst) { sb.append(","); } sb.append(cls.toString()); isfirst = false; } sb.append(")"); return sb.toString(); } }
public void add(int orderedColumn, int valueColumn, TypeInfo typeInfo) { if (orderedTreeMap.containsKey(orderedColumn)) { throw new RuntimeException( name + " duplicate column " + orderedColumn + " in ordered column map " + orderedTreeMap.toString() + " when adding value column " + valueColumn + ", type into " + typeInfo.toString()); } orderedTreeMap.put(orderedColumn, new Value(valueColumn, typeInfo)); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getName()); sb.append("("); boolean isfirst = true; for (TypeInfo cls : getTypeArray()) { if (!isfirst) { sb.append(","); } sb.append(cls.toString()); isfirst = false; } sb.append(")"); return sb.toString(); } }
public static long getDecimal64AbsMaxFromDecimalTypeString(String typeString) { TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(typeString); if (!(typeInfo instanceof DecimalTypeInfo)) { throw new RuntimeException( "Expected decimal type but found " + typeInfo.toString()); } DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) typeInfo; final int precision = decimalTypeInfo.precision(); if (!HiveDecimalWritable.isPrecisionDecimal64(precision)) { throw new RuntimeException( "Expected decimal type " + typeInfo.toString() + " to have a decimal64 precision (i.e. <= " + HiveDecimalWritable.DECIMAL64_DECIMAL_DIGITS + ")"); } return HiveDecimalWritable.getDecimal64AbsMax(precision); } }
@Override public String toString() { return getName() + ":" + getTypeInfo().toString(); }
protected AbstractSerDe initSerDe(Configuration conf) throws SerDeException { Properties props = new Properties(); StringBuilder columnsBuffer = new StringBuilder(); StringBuilder typesBuffer = new StringBuilder(); boolean isFirst = true; for (FieldDesc colDesc : schema.getColumns()) { if (!isFirst) { columnsBuffer.append(','); typesBuffer.append(','); } columnsBuffer.append(colDesc.getName()); typesBuffer.append(colDesc.getTypeInfo().toString()); isFirst = false; } String columns = columnsBuffer.toString(); String types = typesBuffer.toString(); props.put(serdeConstants.LIST_COLUMNS, columns); props.put(serdeConstants.LIST_COLUMN_TYPES, types); props.put(serdeConstants.ESCAPE_CHAR, "\\"); AbstractSerDe createdSerDe = createSerDe(); createdSerDe.initialize(conf, props); return createdSerDe; } }
private Schema createAvroRecord(TypeInfo typeInfo) { List<Schema.Field> childFields = new ArrayList<Schema.Field>(); final List<String> allStructFieldNames = ((StructTypeInfo) typeInfo).getAllStructFieldNames(); final List<TypeInfo> allStructFieldTypeInfos = ((StructTypeInfo) typeInfo).getAllStructFieldTypeInfos(); if (allStructFieldNames.size() != allStructFieldTypeInfos.size()) { throw new IllegalArgumentException("Failed to generate avro schema from hive schema. " + "name and column type differs. names = " + allStructFieldNames + ", types = " + allStructFieldTypeInfos); } for (int i = 0; i < allStructFieldNames.size(); ++i) { final TypeInfo childTypeInfo = allStructFieldTypeInfos.get(i); final Schema.Field grandChildSchemaField = createAvroField(allStructFieldNames.get(i), childTypeInfo, childTypeInfo.toString()); final List<Schema.Field> grandChildFields = getFields(grandChildSchemaField); childFields.addAll(grandChildFields); } Schema recordSchema = Schema.createRecord("record_" + recordCounter, typeInfo.toString(), null, false); ++recordCounter; recordSchema.setFields(childFields); return recordSchema; }
private VectorExpression getCastToBoolean(List<ExprNodeDesc> childExpr) throws HiveException { ExprNodeDesc child = childExpr.get(0); TypeInfo inputTypeInfo = child.getTypeInfo(); String inputType = inputTypeInfo.toString(); if (child instanceof ExprNodeConstantDesc) { if (null == ((ExprNodeConstantDesc)child).getValue()) { return getConstantVectorExpression(null, TypeInfoFactory.booleanTypeInfo, VectorExpressionDescriptor.Mode.PROJECTION); } // Don't do constant folding here. Wait until the optimizer is changed to do it. // Family of related JIRAs: HIVE-7421, HIVE-7422, and HIVE-7424. return null; } // Long and double are handled using descriptors, string needs to be specially handled. if (isStringFamily(inputType)) { return createVectorExpression(CastStringToBoolean.class, childExpr, VectorExpressionDescriptor.Mode.PROJECTION, TypeInfoFactory.booleanTypeInfo); } return null; }