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);
}
}
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;
}
Aggregations