Search in sources :

Example 16 with RowAssembler

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

the class ItTablePersistenceTest method createKeyValueRow.

/**
 * Creates a {@link Row} with the supplied key and value.
 *
 * @param id    Key.
 * @param value Value.
 * @return Row.
 */
private static Row createKeyValueRow(long id, long value) {
    RowAssembler rowBuilder = new RowAssembler(SCHEMA, 0, 0);
    rowBuilder.appendLong(id);
    rowBuilder.appendLong(value);
    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 17 with RowAssembler

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

the class BinaryIndexRowFactory method createRowAssembler.

/**
 * Creates a {@link RowAssembler} that can later be used to serialized the given column mapping.
 */
private RowAssembler createRowAssembler(Object[] rowColumns) {
    SchemaDescriptor schemaDescriptor = descriptor.asSchemaDescriptor();
    int nonNullVarlenKeyCols = 0;
    for (Column column : schemaDescriptor.keyColumns().columns()) {
        Object columnValue = rowColumns[column.columnOrder()];
        if (!column.type().spec().fixedLength() && columnValue != null) {
            nonNullVarlenKeyCols += 1;
        }
    }
    return new RowAssembler(schemaDescriptor, nonNullVarlenKeyCols, 0);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler)

Example 18 with RowAssembler

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

the class BinaryIndexRowFactory method createIndexRow.

@Override
public IndexRow createIndexRow(Object[] columnValues, SearchRow primaryKey) {
    if (columnValues.length != descriptor.indexRowColumns().size()) {
        throw new IllegalArgumentException(String.format("Incorrect number of column values passed. Expected %d, got %d", descriptor.indexRowColumns().size(), columnValues.length));
    }
    RowAssembler rowAssembler = createRowAssembler(columnValues);
    for (Column column : descriptor.asSchemaDescriptor().keyColumns().columns()) {
        Object columnValue = columnValues[column.columnOrder()];
        RowAssembler.writeValue(rowAssembler, column, columnValue);
    }
    return new BinaryIndexRow(rowAssembler.build(), primaryKey);
}
Also used : Column(org.apache.ignite.internal.schema.Column) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler)

Example 19 with RowAssembler

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

the class TupleMarshallerImpl method buildRow.

/**
 * Marshal tuple to a row.
 *
 * @param schema    Schema.
 * @param keyTuple0 Internal key tuple.
 * @param valTuple0 Internal value tuple.
 * @return Row.
 * @throws SchemaMismatchException If failed to write tuple column.
 */
@NotNull
private Row buildRow(SchemaDescriptor schema, InternalTuple keyTuple0, InternalTuple valTuple0) throws SchemaMismatchException {
    RowAssembler rowBuilder = createAssembler(schema, keyTuple0, valTuple0);
    Columns columns = schema.keyColumns();
    for (int i = 0, len = columns.length(); i < len; i++) {
        final Column col = columns.column(i);
        writeColumn(rowBuilder, col, keyTuple0);
    }
    if (valTuple0.tuple != null) {
        columns = schema.valueColumns();
        for (int i = 0, len = columns.length(); i < len; i++) {
            final Column col = columns.column(i);
            writeColumn(rowBuilder, col, valTuple0);
        }
    }
    return new Row(schema, rowBuilder.build());
}
Also used : 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) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with RowAssembler

use of org.apache.ignite.internal.schema.row.RowAssembler 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)

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