public static ColumnDescriptor newPrimitiveColumnDescriptor(String name, String comment, Type type, int position) { // Current usage looks like it's only for metadata columns, but if that changes then // this method may need to require a type qualifiers aruments. return new ColumnDescriptor(name, comment, new TypeDescriptor(type), position); }
public Type getType() { return type.getType(); }
public String getTypeName() { return type.getTypeName(); } }
@Override public ColumnBasedSet addRow(Object[] fields) { if (isBlobBased) { this.blob = (byte[]) fields[0]; } else { for (int i = 0; i < fields.length; i++) { TypeDescriptor descriptor = descriptors[i]; Object field = fields[i]; if (field != null && descriptor.getType() == Type.DECIMAL_TYPE) { int scale = descriptor.getDecimalDigits(); field = ((HiveDecimal) field).toFormatString(scale); } columns.get(i).addValue(descriptor.getType(), field); } } return this; }
column.getTypeDescriptor().getColumnSize(), // COLUMN_SIZE column.getTypeDescriptor().getDecimalDigits(), // DECIMAL_DIGITS
/** * Gets the qualified type name. * * @param typeDesc the type desc * @return the qualified type name */ public static String getQualifiedTypeName(TypeDescriptor typeDesc) { if (typeDesc.getType().isQualifiedType()) { switch (typeDesc.getType()) { case VARCHAR_TYPE: return VarcharTypeInfo.getQualifiedName(typeDesc.getTypeName(), typeDesc.getTypeQualifiers().getCharacterMaximumLength()).toLowerCase(); case CHAR_TYPE: return CharTypeInfo.getQualifiedName(typeDesc.getTypeName(), typeDesc.getTypeQualifiers().getCharacterMaximumLength()).toLowerCase(); case DECIMAL_TYPE: return DecimalTypeInfo.getQualifiedName(typeDesc.getTypeQualifiers().getPrecision(), typeDesc.getTypeQualifiers().getScale()).toLowerCase(); } } else if (typeDesc.getType().isComplexType()) { switch (typeDesc.getType()) { case ARRAY_TYPE: case MAP_TYPE: case STRUCT_TYPE: return "string"; } } return typeDesc.getTypeName().toLowerCase(); }
public TypeDescriptor(TTypeDesc tTypeDesc) { List<TTypeEntry> tTypeEntries = tTypeDesc.getTypes(); TPrimitiveTypeEntry top = tTypeEntries.get(0).getPrimitiveEntry(); this.type = Type.getType(top.getType()); if (top.isSetTypeQualifiers()) { setTypeQualifiers(TypeQualifiers.fromTTypeQualifiers(top.getTypeQualifiers())); } }
public TTypeDesc toTTypeDesc() { TPrimitiveTypeEntry primitiveEntry = new TPrimitiveTypeEntry(type.toTType()); if (getTypeQualifiers() != null) { primitiveEntry.setTypeQualifiers(getTypeQualifiers().toTTypeQualifiers()); } TTypeEntry entry = TTypeEntry.primitiveEntry(primitiveEntry); TTypeDesc desc = new TTypeDesc(); desc.addToTypes(entry); return desc; }
public TColumnDesc toTColumnDesc() { TColumnDesc tColumnDesc = new TColumnDesc(); tColumnDesc.setColumnName(name); tColumnDesc.setComment(comment); tColumnDesc.setTypeDesc(type.toTTypeDesc()); tColumnDesc.setPosition(position); return tColumnDesc; }
/** * The column size for this type. * For numeric data this is the maximum precision. * For character data this is the length in characters. * For datetime types this is the length in characters of the String representation * (assuming the maximum allowed precision of the fractional seconds component). * For binary data this is the length in bytes. * Null is returned for for data types where the column size is not applicable. */ public Integer getColumnSize() { if (type.isNumericType()) { return getPrecision(); } switch (type) { case STRING_TYPE: case BINARY_TYPE: return Integer.MAX_VALUE; case CHAR_TYPE: case VARCHAR_TYPE: return typeQualifiers.getCharacterMaximumLength(); case DATE_TYPE: return 10; case TIMESTAMP_TYPE: return 29; case TIMESTAMPLOCALTZ_TYPE: return 31; default: return null; } }
private static TColumnValue stringValue(HiveDecimal value, TypeDescriptor typeDescriptor) { TStringValue tStrValue = new TStringValue(); if (value != null) { int scale = typeDescriptor.getDecimalDigits(); tStrValue.setValue(value.toFormatString(scale)); } return TColumnValue.stringVal(tStrValue); }
/** * Gets the qualified type name. * * @param typeDesc the type desc * @return the qualified type name */ public static String getQualifiedTypeName(TypeDescriptor typeDesc) { if (typeDesc.getType().isQualifiedType()) { switch (typeDesc.getType()) { case VARCHAR_TYPE: return VarcharTypeInfo.getQualifiedName(typeDesc.getTypeName(), typeDesc.getTypeQualifiers().getCharacterMaximumLength()).toLowerCase(); case CHAR_TYPE: return CharTypeInfo.getQualifiedName(typeDesc.getTypeName(), typeDesc.getTypeQualifiers().getCharacterMaximumLength()).toLowerCase(); case DECIMAL_TYPE: return DecimalTypeInfo.getQualifiedName(typeDesc.getTypeQualifiers().getPrecision(), typeDesc.getTypeQualifiers().getScale()).toLowerCase(); } } else if (typeDesc.getType().isComplexType()) { switch (typeDesc.getType()) { case ARRAY_TYPE: case MAP_TYPE: case STRUCT_TYPE: return "string"; } } return typeDesc.getTypeName().toLowerCase(); }
column.getTypeDescriptor().getColumnSize(), // COLUMN_SIZE column.getTypeDescriptor().getDecimalDigits(), // DECIMAL_DIGITS
public TypeDescriptor(String typeName) { this.type = Type.getType(typeName); if (this.type.isComplexType()) { this.typeName = typeName; } else if (this.type.isQualifiedType()) { PrimitiveTypeInfo pti = TypeInfoFactory.getPrimitiveTypeInfo(typeName); setTypeQualifiers(TypeQualifiers.fromTypeInfo(pti)); } }
@Override public ColumnBasedSet addRow(Object[] fields) { if (isBlobBased) { this.blob = (byte[]) fields[0]; } else { for (int i = 0; i < fields.length; i++) { TypeDescriptor descriptor = descriptors[i]; Object field = fields[i]; if (field != null && descriptor.getType() == Type.DECIMAL_TYPE) { int scale = descriptor.getDecimalDigits(); field = ((HiveDecimal) field).toFormatString(scale); } columns.get(i).addValue(descriptor.getType(), field); } } return this; }
public TTypeDesc toTTypeDesc() { TPrimitiveTypeEntry primitiveEntry = new TPrimitiveTypeEntry(type.toTType()); if (getTypeQualifiers() != null) { primitiveEntry.setTypeQualifiers(getTypeQualifiers().toTTypeQualifiers()); } TTypeEntry entry = TTypeEntry.primitiveEntry(primitiveEntry); TTypeDesc desc = new TTypeDesc(); desc.addToTypes(entry); return desc; }
public TColumnDesc toTColumnDesc() { TColumnDesc tColumnDesc = new TColumnDesc(); tColumnDesc.setColumnName(name); tColumnDesc.setComment(comment); tColumnDesc.setTypeDesc(type.toTTypeDesc()); tColumnDesc.setPosition(position); return tColumnDesc; }
/** * The column size for this type. * For numeric data this is the maximum precision. * For character data this is the length in characters. * For datetime types this is the length in characters of the String representation * (assuming the maximum allowed precision of the fractional seconds component). * For binary data this is the length in bytes. * Null is returned for data types where the column size is not applicable. */ public Integer getColumnSize() { if (type.isNumericType()) { return getPrecision(); } switch (type) { case STRING_TYPE: case BINARY_TYPE: return Integer.MAX_VALUE; case CHAR_TYPE: case VARCHAR_TYPE: return typeQualifiers.getCharacterMaximumLength(); case DATE_TYPE: return 10; case TIMESTAMP_TYPE: return 29; default: return null; } }
private static TColumnValue stringValue(HiveDecimal value, TypeDescriptor typeDescriptor) { TStringValue tStrValue = new TStringValue(); if (value != null) { int scale = typeDescriptor.getDecimalDigits(); tStrValue.setValue(value.toFormatString(scale)); } return TColumnValue.stringVal(tStrValue); }
public TableSchema(List<FieldSchema> fieldSchemas) { int pos = 1; for (FieldSchema field : fieldSchemas) { columns.add(new ColumnDescriptor(field.getName(), field.getComment(), new TypeDescriptor( field.getType()), pos++)); } }