Search in sources :

Example 6 with SchemaMismatchException

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

the class TupleMarshallerImpl method marshalKey.

/**
 * {@inheritDoc}
 */
@Override
public Row marshalKey(@NotNull Tuple keyTuple) throws TupleMarshallerException {
    try {
        final SchemaDescriptor schema = schemaReg.schema();
        InternalTuple keyTuple0 = toInternalTuple(schema, keyTuple, true);
        if (keyTuple0.knownColumns() < keyTuple.columnCount()) {
            throw new SchemaMismatchException("Key tuple contains extra columns: " + extraColumnNames(keyTuple, true, schema));
        }
        final RowAssembler rowBuilder = createAssembler(schema, keyTuple0, InternalTuple.NO_VALUE);
        Columns cols = schema.keyColumns();
        for (int i = 0, len = cols.length(); i < len; i++) {
            final Column col = cols.column(i);
            writeColumn(rowBuilder, col, keyTuple0);
        }
        return new Row(schema, rowBuilder.build());
    } catch (Exception ex) {
        throw new TupleMarshallerException("Failed to marshal tuple.", ex);
    }
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) SchemaMismatchException(org.apache.ignite.internal.schema.SchemaMismatchException) Column(org.apache.ignite.internal.schema.Column) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Columns(org.apache.ignite.internal.schema.Columns) Row(org.apache.ignite.internal.schema.row.Row) SchemaMismatchException(org.apache.ignite.internal.schema.SchemaMismatchException)

Example 7 with SchemaMismatchException

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

the class RowAssembler method appendDecimal.

/**
 * Appends BigDecimal 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 appendDecimal(BigDecimal val) throws SchemaMismatchException {
    checkType(NativeTypeSpec.DECIMAL);
    Column col = curCols.column(curCol);
    DecimalNativeType type = (DecimalNativeType) col.type();
    val = val.setScale(type.scale(), RoundingMode.HALF_UP);
    if (val.precision() > type.precision()) {
        throw new SchemaMismatchException("Failed to set decimal value for column '" + col.name() + "' " + "(max precision exceeds allocated precision)" + " [decimal=" + val + ", max precision=" + type.precision() + "]");
    }
    byte[] bytes = val.unscaledValue().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) DecimalNativeType(org.apache.ignite.internal.schema.DecimalNativeType)

Aggregations

SchemaMismatchException (org.apache.ignite.internal.schema.SchemaMismatchException)7 Column (org.apache.ignite.internal.schema.Column)5 NotNull (org.jetbrains.annotations.NotNull)3 Columns (org.apache.ignite.internal.schema.Columns)2 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)2 Row (org.apache.ignite.internal.schema.row.Row)2 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)2 MethodHandle (java.lang.invoke.MethodHandle)1 BigDecimal (java.math.BigDecimal)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 Objects (java.util.Objects)1 DecimalNativeType (org.apache.ignite.internal.schema.DecimalNativeType)1 NumberNativeType (org.apache.ignite.internal.schema.NumberNativeType)1 SchemaAware (org.apache.ignite.internal.schema.SchemaAware)1 BinaryMode (org.apache.ignite.internal.schema.marshaller.BinaryMode)1 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)1 Factory (org.apache.ignite.internal.util.Factory)1 ObjectFactory (org.apache.ignite.internal.util.ObjectFactory)1 Mapper (org.apache.ignite.table.mapper.Mapper)1