Search in sources :

Example 6 with RowAssembler

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());
}
Also used : RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Test(org.junit.jupiter.api.Test)

Example 7 with RowAssembler

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());
}
Also used : RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Test(org.junit.jupiter.api.Test)

Example 8 with RowAssembler

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()));
}
Also used : ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow)

Example 9 with RowAssembler

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);
}
Also used : RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) RelReferentialConstraint(org.apache.calcite.rel.RelReferentialConstraint)

Example 10 with RowAssembler

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());
}
Also used : ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler)

Aggregations

RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)34 Test (org.junit.jupiter.api.Test)16 Row (org.apache.ignite.internal.schema.row.Row)13 Column (org.apache.ignite.internal.schema.Column)10 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)6 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)5 TestSimpleObject (org.apache.ignite.internal.schema.testobjects.TestSimpleObject)4 BigInteger (java.math.BigInteger)3 RelReferentialConstraint (org.apache.calcite.rel.RelReferentialConstraint)3 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)3 NotNull (org.jetbrains.annotations.NotNull)3 Columns (org.apache.ignite.internal.schema.Columns)2 Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)1 ManagementFactory (java.lang.management.ManagementFactory)1 ThreadInfo (java.lang.management.ThreadInfo)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 BigDecimal (java.math.BigDecimal)1 Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1