use of org.apache.ignite.internal.schema.row.RowAssembler in project ignite-3 by apache.
the class RowAssemblerSimpleSchemaTest method fixedKeyVarlenNullableValue.
/**
* Validate row layout for schema of fix-len non-null key and var-len nullable value.
*/
@Test
public void fixedKeyVarlenNullableValue() {
SchemaDescriptor schema = new SchemaDescriptor(42, new Column[] { new Column("keyShortCol", INT16, false) }, new Column[] { new Column("valStrCol", STRING, true) });
assertRowBytesEquals(new byte[] { 42, 0, -23, -36, 114, 80, 7, 0, 0, 0, 0, -33, -1, 9, 0, 0, 0, 0, 0, 118, 97, 108 }, new RowAssembler(schema, 0, 1).appendShort((short) -33).appendString("val").toBytes());
// Null value.
assertRowBytesEquals(new byte[] { 42, 0, -45, 61, -70, -41, 7, 0, 0, 0, 0, 33, 0, 6, 0, 0, 0, 0, 1 }, new RowAssembler(schema, 0, 0).appendShort((short) 33).appendNull().toBytes());
// No value.
assertRowBytesEquals(new byte[] { 0, 0, -45, 61, -70, -41, 7, 0, 0, 0, 0, 33, 0 }, new RowAssembler(schema, 0, 0).appendShort((short) 33).toBytes());
}
use of org.apache.ignite.internal.schema.row.RowAssembler in project ignite-3 by apache.
the class RowAssemblerSimpleSchemaTest method varlenKeyVarlenValue.
/**
* Validate row layout for schema of var-len non-null key and var-len non-null value.
*/
@Test
public void varlenKeyVarlenValue() {
SchemaDescriptor schema = new SchemaDescriptor(42, new Column[] { new Column("keyStrCol", STRING, false) }, new Column[] { new Column("valBytesCol", BYTES, false) });
assertRowBytesEquals(new byte[] { 42, 0, 64, -119, 105, 64, 8, 0, 0, 0, 0, 107, 101, 121, 9, 0, 0, 0, 0, -1, 1, 0, 120 }, new RowAssembler(schema, 1, 1).appendString("key").appendBytes(new byte[] { -1, 1, 0, 120 }).toBytes());
// No value.
assertRowBytesEquals(new byte[] { 0, 0, 64, -119, 105, 64, 8, 0, 0, 0, 0, 107, 101, 121 }, new RowAssembler(schema, 1, 0).appendString("key").toBytes());
}
use of org.apache.ignite.internal.schema.row.RowAssembler in project ignite-3 by apache.
the class ItTablePersistenceTest method createKeyRow.
/**
* Creates a {@link Row} with the supplied key.
*
* @param id Key.
* @return Row.
*/
private static Row createKeyRow(long id) {
RowAssembler rowBuilder = new RowAssembler(SCHEMA, 0, 0);
rowBuilder.appendLong(id);
return new Row(SCHEMA, new ByteBufferRow(rowBuilder.toBytes()));
}
use of org.apache.ignite.internal.schema.row.RowAssembler in project ignite-3 by apache.
the class IgniteTableImpl method insertTuple.
private <RowT> ModifyRow insertTuple(RowT row, ExecutionContext<RowT> ectx) {
int nonNullVarlenKeyCols = 0;
int nonNullVarlenValCols = 0;
RowHandler<RowT> hnd = ectx.rowHandler();
for (ColumnDescriptor colDesc : columnsOrderedByPhysSchema) {
if (colDesc.physicalType().spec().fixedLength()) {
continue;
}
Object val = hnd.get(colDesc.logicalIndex(), row);
if (val != null) {
if (colDesc.key()) {
nonNullVarlenKeyCols++;
} else {
nonNullVarlenValCols++;
}
}
}
RowAssembler rowAssembler = new RowAssembler(schemaDescriptor, nonNullVarlenKeyCols, nonNullVarlenValCols);
for (ColumnDescriptor colDesc : columnsOrderedByPhysSchema) {
RowAssembler.writeValue(rowAssembler, colDesc.physicalType(), hnd.get(colDesc.logicalIndex(), row));
}
return new ModifyRow(rowAssembler.build(), Operation.INSERT_ROW);
}
use of org.apache.ignite.internal.schema.row.RowAssembler in project ignite-3 by apache.
the class KvMarshallerImpl method marshal.
/**
* {@inheritDoc}
*/
@Override
public BinaryRow marshal(@NotNull K key) throws MarshallerException {
assert keyClass.isInstance(key);
final RowAssembler asm = createAssembler(key, null);
keyMarsh.writeObject(key, asm);
return new ByteBufferRow(asm.toBytes());
}
Aggregations