Search in sources :

Example 1 with NumberNativeType

use of org.apache.ignite.internal.schema.NumberNativeType in project ignite-3 by apache.

the class RowAssembler method appendNumber.

/**
 * Appends BigInteger value for the current column to the chunk.
 *
 * @param val Column value.
 * @return {@code this} for chaining.
 * @throws SchemaMismatchException If a value doesn't match the current column type.
 */
public RowAssembler appendNumber(BigInteger val) throws SchemaMismatchException {
    checkType(NativeTypeSpec.NUMBER);
    Column col = curCols.column(curCol);
    NumberNativeType type = (NumberNativeType) col.type();
    // 0 is a magic number for "unlimited precision"
    if (type.precision() > 0 && new BigDecimal(val).precision() > type.precision()) {
        throw new SchemaMismatchException("Failed to set number value for column '" + col.name() + "' " + "(max precision exceeds allocated precision) " + "[number=" + val + ", max precision=" + type.precision() + "]");
    }
    byte[] bytes = val.toByteArray();
    buf.putBytes(curOff, bytes);
    writeVarlenOffset(curVartblEntry, curOff - dataOff);
    curVartblEntry++;
    shiftColumn(bytes.length);
    return this;
}
Also used : SchemaMismatchException(org.apache.ignite.internal.schema.SchemaMismatchException) Column(org.apache.ignite.internal.schema.Column) NumberNativeType(org.apache.ignite.internal.schema.NumberNativeType) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)1 Column (org.apache.ignite.internal.schema.Column)1 NumberNativeType (org.apache.ignite.internal.schema.NumberNativeType)1 SchemaMismatchException (org.apache.ignite.internal.schema.SchemaMismatchException)1