/** * The decimal precision and scale is filled into decimalColumnVector. If the data in * Parquet is in decimal, the precision and scale will come in from decimalMetadata. If parquet * is not in decimal, then this call is made because HMS shows the type as decimal. So, the * precision and scale are picked from hiveType. * * @param decimalMetadata * @param decimalColumnVector */ private void fillDecimalPrecisionScale(DecimalMetadata decimalMetadata, DecimalColumnVector decimalColumnVector) { if (decimalMetadata != null) { decimalColumnVector.precision = (short) type.asPrimitiveType().getDecimalMetadata().getPrecision(); decimalColumnVector.scale = (short) type.asPrimitiveType().getDecimalMetadata().getScale(); } else if (TypeInfoUtils.getBaseName(hiveType.getTypeName()) .equalsIgnoreCase(serdeConstants.DECIMAL_TYPE_NAME)) { decimalColumnVector.precision = (short) ((DecimalTypeInfo) hiveType).getPrecision(); decimalColumnVector.scale = (short) ((DecimalTypeInfo) hiveType).getScale(); } else { throw new UnsupportedOperationException( "The underlying Parquet type cannot be converted to Hive Decimal type: " + type); } } }
final short scale = (short) parquetType.asPrimitiveType().getDecimalMetadata().getScale(); return isDict ? new TypesFromDecimalPageReader(dictionary, length, scale, hivePrecision, hiveScale) : new TypesFromDecimalPageReader(valuesReader, length, scale, hivePrecision, hiveScale);
if (primitiveType == PrimitiveTypeName.INT32) { Preconditions.checkState( meta.getPrecision() <= MAX_PRECISION_INT32, "INT32 cannot store " + meta.getPrecision() + " digits " + "(max " + MAX_PRECISION_INT32 + ")"); } else if (primitiveType == PrimitiveTypeName.INT64) { Preconditions.checkState( meta.getPrecision() <= MAX_PRECISION_INT64, "INT64 cannot store " + meta.getPrecision() + " digits " + "(max " + MAX_PRECISION_INT64 + ")"); if (meta.getPrecision() <= MAX_PRECISION_INT32) { LOGGER.warn("Decimal with {} digits is stored in an INT64, but fits in an INT32. See {}.", precision, LOGICAL_TYPES_DOC_URL); meta.getPrecision() <= maxPrecision(length), "FIXED(" + length + ") cannot store " + meta.getPrecision() + " digits (max " + maxPrecision(length) + ")");
public static DecimalMetadata getDecimalMetadataForField(MajorType type) { switch(type.getMinorType()) { case DECIMAL: case DECIMAL9: case DECIMAL18: case DECIMAL28SPARSE: case DECIMAL28DENSE: case DECIMAL38SPARSE: case DECIMAL38DENSE: return new DecimalMetadata(type.getPrecision(), type.getScale()); default: return null; } }
/** * {@inheritDoc} */ @Override public int hashCode() { int hash = super.hashCode(); hash = hash * 31 + primitive.hashCode(); hash = hash * 31 + length; hash = hash * 31 + columnOrder.hashCode(); if (decimalMeta != null) { hash = hash * 31 + decimalMeta.hashCode(); } return hash; }
@Override PrimitiveStringifier stringifier(PrimitiveType type) { return PrimitiveStringifier.createDecimalStringifier(type.getDecimalMetadata().getScale()); } },
protected DecimalMetadata decimalMetadata() { DecimalMetadata meta = null; if (OriginalType.DECIMAL == originalType) { Preconditions.checkArgument(precision > 0, "Invalid DECIMAL precision: " + precision); Preconditions.checkArgument(scale >= 0, "Invalid DECIMAL scale: " + scale); Preconditions.checkArgument(scale <= precision, "Invalid DECIMAL scale: cannot be greater than precision"); meta = new DecimalMetadata(precision, scale); } return meta; } }
/** * {@inheritDoc} */ @Override public int hashCode() { int hash = super.hashCode(); hash = hash * 31 + primitive.hashCode(); hash = hash * 31 + length; hash = hash * 31 + columnOrder.hashCode(); if (decimalMeta != null) { hash = hash * 31 + decimalMeta.hashCode(); } return hash; }
case DECIMAL: decimalTypeCheck(type); int precision = type.asPrimitiveType().getDecimalMetadata().getPrecision(); int scale = type.asPrimitiveType().getDecimalMetadata().getScale(); lcv.child = new DecimalColumnVector(total, precision, scale); for (int i = 0; i < valueList.size(); i++) {
int scale = type.getDecimalMetadata().getScale(); switch (type.getPrimitiveTypeName()) { case INT32:
public static DecimalMetadata getDecimalMetadataForField(MaterializedField field) { switch(field.getType().getMinorType()) { case DECIMAL9: case DECIMAL18: case DECIMAL28SPARSE: case DECIMAL28DENSE: case DECIMAL38SPARSE: case DECIMAL38DENSE: case VARDECIMAL: return new DecimalMetadata(field.getPrecision(), field.getScale()); default: return null; } }
int precision = pt.asPrimitiveType().getDecimalMetadata().getPrecision(); int scale = pt.asPrimitiveType().getDecimalMetadata().getScale(); switch (pt.getPrimitiveTypeName()) { case INT32:
private PrimitiveConverter newConverter(int colIdx, byte vecType, PrimitiveType parquetType) { switch (vecType) { case Vec.T_BAD: case Vec.T_CAT: case Vec.T_STR: case Vec.T_UUID: case Vec.T_TIME: if (OriginalType.TIMESTAMP_MILLIS.equals(parquetType.getOriginalType()) || parquetType.getPrimitiveTypeName().equals(PrimitiveType.PrimitiveTypeName.INT96)) { return new TimestampConverter(colIdx, _writer); } else { boolean dictSupport = parquetType.getOriginalType() == OriginalType.UTF8 || parquetType.getOriginalType() == OriginalType.ENUM; return new StringConverter(_writer, colIdx, dictSupport); } case Vec.T_NUM: if (OriginalType.DECIMAL.equals(parquetType.getOriginalType())) return new DecimalConverter(colIdx, parquetType.getDecimalMetadata().getScale(), _writer); else return new NumberConverter(colIdx, _writer); default: throw new UnsupportedOperationException("Unsupported type " + vecType); } }
@Override public Statistics<T> visitVarDecimalConstant(ValueExpressions.VarDecimalExpression decExpr, Void value) throws RuntimeException { DecimalMetadata decimalMeta = new DecimalMetadata(decExpr.getMajorType().getPrecision(), decExpr.getMajorType().getScale()); return getStatistics(decExpr.getBigDecimal(), decimalMeta); }
private static Type createDecimalType(DecimalMetadata decimalMetadata) { return DecimalType.createDecimalType(decimalMetadata.getPrecision(), decimalMetadata.getScale()); }
switch (primitive.getPrimitiveTypeName()) { case BINARY: case FIXED_LEN_BYTE_ARRAY: return new BinaryAsDecimalReader(desc, decimal.getScale()); case INT32: return new IntegerAsDecimalReader(desc, decimal.getScale()); case INT64: return new LongAsDecimalReader(desc, decimal.getScale()); default: throw new UnsupportedOperationException(
PrimitiveType(Repetition repetition, PrimitiveTypeName primitive, int length, String name, LogicalTypeAnnotation logicalTypeAnnotation, ID id, ColumnOrder columnOrder) { super(name, repetition, logicalTypeAnnotation, id); this.primitive = primitive; this.length = length; if (logicalTypeAnnotation instanceof LogicalTypeAnnotation.DecimalLogicalTypeAnnotation) { LogicalTypeAnnotation.DecimalLogicalTypeAnnotation decimal = (LogicalTypeAnnotation.DecimalLogicalTypeAnnotation) logicalTypeAnnotation; this.decimalMeta = new DecimalMetadata(decimal.getPrecision(), decimal.getScale()); } else { this.decimalMeta = null; } if (columnOrder == null) { columnOrder = primitive == PrimitiveTypeName.INT96 || logicalTypeAnnotation instanceof LogicalTypeAnnotation.IntervalLogicalTypeAnnotation ? ColumnOrder.undefined() : ColumnOrder.typeDefined(); } this.columnOrder = requireValidColumnOrder(columnOrder); }
private static Type createDecimalType(DecimalMetadata decimalMetadata) { return DecimalType.createDecimalType(decimalMetadata.getPrecision(), decimalMetadata.getScale()); }
protected DecimalMetadata decimalMetadata() { DecimalMetadata meta = null; if (logicalTypeAnnotation instanceof LogicalTypeAnnotation.DecimalLogicalTypeAnnotation) { LogicalTypeAnnotation.DecimalLogicalTypeAnnotation decimalType = (LogicalTypeAnnotation.DecimalLogicalTypeAnnotation) logicalTypeAnnotation; if (newLogicalTypeSet) { if (scaleAlreadySet) { Preconditions.checkArgument(this.scale == decimalType.getScale(), "Decimal scale should match with the scale of the logical type"); } if (precisionAlreadySet) { Preconditions.checkArgument(this.precision == decimalType.getPrecision(), "Decimal precision should match with the precision of the logical type"); } scale = decimalType.getScale(); precision = decimalType.getPrecision(); } Preconditions.checkArgument(precision > 0, "Invalid DECIMAL precision: " + precision); Preconditions.checkArgument(this.scale >= 0, "Invalid DECIMAL scale: " + this.scale); Preconditions.checkArgument(this.scale <= precision, "Invalid DECIMAL scale: cannot be greater than precision"); meta = new DecimalMetadata(precision, scale); } return meta; } }