private static Type fromKuduClientType(org.apache.kudu.Type ktype, ColumnTypeAttributes attributes) { switch (ktype) { case STRING: return VarcharType.VARCHAR; case UNIXTIME_MICROS: return TimestampType.TIMESTAMP; case INT64: return BigintType.BIGINT; case INT32: return IntegerType.INTEGER; case INT16: return SmallintType.SMALLINT; case INT8: return TinyintType.TINYINT; case FLOAT: return RealType.REAL; case DOUBLE: return DoubleType.DOUBLE; case BOOL: return BooleanType.BOOLEAN; case BINARY: return VarbinaryType.VARBINARY; case DECIMAL: return DecimalType.createDecimalType(attributes.getPrecision(), attributes.getScale()); default: throw new IllegalStateException("Kudu type not implemented for " + ktype); } }
/** * The size of this type on the wire * @param typeAttributes the additional attributes of the type. * @return A size */ public int getSize(ColumnTypeAttributes typeAttributes) { if (this == DECIMAL) { return DecimalUtil.precisionToSize(typeAttributes.getPrecision()); } return this.size; }
/** * Get the data type from the common's pb * @param typeAttributes the additional attributes of the type. * @return A DataType */ public DataType getDataType(ColumnTypeAttributes typeAttributes) { if (this == DECIMAL) { return DecimalUtil.precisionToDataType(typeAttributes.getPrecision()); } return this.dataTypes.get(0); }
private static Type fromKuduClientType(org.apache.kudu.Type ktype, ColumnTypeAttributes attributes) { switch (ktype) { case STRING: return VarcharType.VARCHAR; case UNIXTIME_MICROS: return TimestampType.TIMESTAMP; case INT64: return BigintType.BIGINT; case INT32: return IntegerType.INTEGER; case INT16: return SmallintType.SMALLINT; case INT8: return TinyintType.TINYINT; case FLOAT: return RealType.REAL; case DOUBLE: return DoubleType.DOUBLE; case BOOL: return BooleanType.BOOLEAN; case BINARY: return VarbinaryType.VARBINARY; case DECIMAL: return DecimalType.createDecimalType(attributes.getPrecision(), attributes.getScale()); default: throw new IllegalStateException("Kudu type not implemented for " + ktype); } }
private static Type fromKuduClientType(org.apache.kudu.Type ktype, ColumnTypeAttributes attributes) { switch (ktype) { case STRING: return VarcharType.VARCHAR; case UNIXTIME_MICROS: return TimestampType.TIMESTAMP; case INT64: return BigintType.BIGINT; case INT32: return IntegerType.INTEGER; case INT16: return SmallintType.SMALLINT; case INT8: return TinyintType.TINYINT; case FLOAT: return RealType.REAL; case DOUBLE: return DoubleType.DOUBLE; case BOOL: return BooleanType.BOOLEAN; case BINARY: return VarbinaryType.VARBINARY; case DECIMAL: return DecimalType.createDecimalType(attributes.getPrecision(), attributes.getScale()); default: throw new IllegalStateException("Kudu type not implemented for " + ktype); } }
case DECIMAL: return Bytes.getDecimal(value.toByteArray(), typeAttributes.getPrecision(), typeAttributes.getScale()); default: throw new IllegalArgumentException("This type is unknown: " + type);
case DECIMAL128: ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); return Bytes.getDecimal(value, typeAttributes.getPrecision(), typeAttributes.getScale()).toString(); default:
/** * Add a Decimal for the specified column. * @param columnIndex the column's index in the schema * @param val value to add * @throws IllegalArgumentException if the value doesn't match the column's type * @throws IllegalStateException if the row was already applied * @throws IndexOutOfBoundsException if the column doesn't exist */ public void addDecimal(int columnIndex, BigDecimal val) { checkNotFrozen(); ColumnSchema column = schema.getColumnByIndex(columnIndex); ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); checkColumn(column, Type.DECIMAL); BigDecimal coercedVal = DecimalUtil.coerce(val,typeAttributes.getPrecision(), typeAttributes.getScale()); Bytes.setBigDecimal(rowAlloc, coercedVal, typeAttributes.getPrecision(), getPositionInRowAllocAndSetBitSet(columnIndex)); }
for (T value : values) { vals.add(Bytes.fromBigDecimal((BigDecimal) value, column.getTypeAttributes().getPrecision()));
/** * Set a BigDecimal for the lower bound * @param lowerBound value for the lower bound */ public void setLowerBound(BigDecimal lowerBound) { checkColumn(Type.DECIMAL); int precision = column.getTypeAttributes().getPrecision(); int scale = column.getTypeAttributes().getScale(); BigDecimal coercedVal = DecimalUtil.coerce(lowerBound, precision, scale); setLowerBoundInternal(Bytes.fromBigDecimal(coercedVal, precision)); }
public static Common.ColumnTypeAttributesPB columnTypeAttributesToPb( Common.ColumnTypeAttributesPB.Builder builder, ColumnSchema column) { ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); if (typeAttributes.hasPrecision()) { builder.setPrecision(typeAttributes.getPrecision()); } if (typeAttributes.hasScale()) { builder.setScale(typeAttributes.getScale()); } return builder.build(); }
/** * Set a BigDecimal for the upper bound * @param upperBound value for the upper bound */ public void setUpperBound(BigDecimal upperBound) { checkColumn(Type.DECIMAL); int precision = column.getTypeAttributes().getPrecision(); int scale = column.getTypeAttributes().getScale(); BigDecimal coercedVal = DecimalUtil.coerce(upperBound, precision, scale); setUpperBoundInternal(Bytes.fromBigDecimal(coercedVal, precision)); }
checkColumn(column, Type.DECIMAL); ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); int precision = typeAttributes.getPrecision(); int scale = typeAttributes.getScale();
case DECIMAL: ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); int precision = typeAttributes.getPrecision(); int scale = typeAttributes.getScale(); return Bytes.getDecimal(a.rowAlloc, offset, precision, scale)
private static byte[] objectToWireFormat(ColumnSchema col, Object value) { switch (col.getType()) { case BOOL: return Bytes.fromBoolean((Boolean) value); case INT8: return new byte[] {(Byte) value}; case INT16: return Bytes.fromShort((Short) value); case INT32: return Bytes.fromInt((Integer) value); case INT64: case UNIXTIME_MICROS: return Bytes.fromLong((Long) value); case STRING: return ((String) value).getBytes(UTF_8); case BINARY: return (byte[]) value; case FLOAT: return Bytes.fromFloat((Float) value); case DOUBLE: return Bytes.fromDouble((Double) value); case DECIMAL: return Bytes.fromBigDecimal((BigDecimal) value, col.getTypeAttributes().getPrecision()); default: throw new IllegalArgumentException("The column " + col.getName() + " is of type " + col .getType() + " which is unknown"); } }
/** * Get the specified column's Decimal. * * @param columnIndex Column index in the schema * @return a BigDecimal * @throws IllegalArgumentException if the column is null, is unset, * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public BigDecimal getDecimal(int columnIndex) { checkColumn(schema.getColumnByIndex(columnIndex), Type.DECIMAL); checkColumnExists(schema.getColumnByIndex(columnIndex)); checkValue(columnIndex); ColumnSchema column = schema.getColumnByIndex(columnIndex); ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); return Bytes.getDecimal(rowAlloc, schema.getColumnOffset(columnIndex), typeAttributes.getPrecision(), typeAttributes.getScale()); }
table.getSchema().getColumn("c1").getTypeAttributes().getPrecision());
/** * Get the specified column's Decimal. * * @param columnIndex Column index in the schema * @return a BigDecimal. * @throws IllegalArgumentException if the column is null * @throws IndexOutOfBoundsException if the column doesn't exist */ public BigDecimal getDecimal(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.DECIMAL); ColumnSchema column = schema.getColumnByIndex(columnIndex); ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); return Bytes.getDecimal(this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(columnIndex), typeAttributes.getPrecision(), typeAttributes.getScale()); }
ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); addDecimal(index, DecimalUtil.minValue(typeAttributes.getPrecision(), typeAttributes.getScale())); break; case STRING:
ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); return KuduPredicate.newComparisonPredicate(column, op, Bytes.getDecimal(bound, typeAttributes.getPrecision(), typeAttributes.getScale())); default: throw new IllegalStateException(String.format("unknown column type %s", column.getType()));