Search in sources :

Example 66 with Row

use of org.apache.ignite.internal.schema.row.Row 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 67 with Row

use of org.apache.ignite.internal.schema.row.Row 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 68 with Row

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

the class IgniteTableImpl method toRow.

/**
 * {@inheritDoc}
 */
@Override
public <RowT> RowT toRow(ExecutionContext<RowT> ectx, BinaryRow binaryRow, RowHandler.RowFactory<RowT> factory, @Nullable ImmutableBitSet requiredColumns) {
    RowHandler<RowT> handler = factory.handler();
    assert handler == ectx.rowHandler();
    RowT res = factory.create();
    assert handler.columnCount(res) == (requiredColumns == null ? desc.columnsCount() : requiredColumns.cardinality());
    Row row = schemaRegistry.resolve(binaryRow, schemaDescriptor);
    if (requiredColumns == null) {
        for (int i = 0; i < desc.columnsCount(); i++) {
            ColumnDescriptor colDesc = desc.columnDescriptor(i);
            handler.set(i, res, row.value(colDesc.physicalIndex()));
        }
    } else {
        for (int i = 0, j = requiredColumns.nextSetBit(0); j != -1; j = requiredColumns.nextSetBit(j + 1), i++) {
            ColumnDescriptor colDesc = desc.columnDescriptor(j);
            handler.set(i, res, row.value(colDesc.physicalIndex()));
        }
    }
    return res;
}
Also used : BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) RelReferentialConstraint(org.apache.calcite.rel.RelReferentialConstraint)

Example 69 with Row

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

the class KvMarshallerTest method privateClass.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void privateClass(MarshallerFactory factory) throws MarshallerException {
    Column[] cols = new Column[] { new Column("primLongCol".toUpperCase(), INT64, false) };
    SchemaDescriptor schema = new SchemaDescriptor(1, cols, cols);
    final ObjectFactory<PrivateTestObject> objFactory = new ObjectFactory<>(PrivateTestObject.class);
    final KvMarshaller<PrivateTestObject, PrivateTestObject> marshaller = factory.create(schema, PrivateTestObject.class, PrivateTestObject.class);
    final PrivateTestObject key = PrivateTestObject.randomObject(rnd);
    final PrivateTestObject val = PrivateTestObject.randomObject(rnd);
    BinaryRow row = marshaller.marshal(key, objFactory.create());
    Object key1 = marshaller.unmarshalKey(new Row(schema, row));
    Object val1 = marshaller.unmarshalValue(new Row(schema, row));
    assertTrue(key.getClass().isInstance(key1));
    assertTrue(val.getClass().isInstance(val1));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) ObjectFactory(org.apache.ignite.internal.util.ObjectFactory) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 70 with Row

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

the class KvMarshallerTest method classLoader.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classLoader(MarshallerFactory factory) throws MarshallerException {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(new DynamicClassLoader(getClass().getClassLoader()));
        Column[] keyCols = new Column[] { new Column("key".toUpperCase(), INT64, false) };
        Column[] valCols = new Column[] { new Column("col0".toUpperCase(), INT64, false), new Column("col1".toUpperCase(), INT64, false), new Column("col2".toUpperCase(), INT64, false) };
        SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
        final Class<?> valClass = createGeneratedObjectClass();
        final ObjectFactory<?> objFactory = new ObjectFactory<>(valClass);
        KvMarshaller<Long, Object> marshaller = factory.create(schema, Long.class, (Class<Object>) valClass);
        final Long key = rnd.nextLong();
        BinaryRow row = marshaller.marshal(key, objFactory.create());
        Long key1 = marshaller.unmarshalKey(new Row(schema, row));
        Object val1 = marshaller.unmarshalValue(new Row(schema, row));
        assertTrue(valClass.isInstance(val1));
        assertEquals(key, key1);
    } finally {
        Thread.currentThread().setContextClassLoader(loader);
    }
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) ObjectFactory(org.apache.ignite.internal.util.ObjectFactory) Column(org.apache.ignite.internal.schema.Column) DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Row (org.apache.ignite.internal.schema.row.Row)83 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)55 Column (org.apache.ignite.internal.schema.Column)34 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)30 NotNull (org.jetbrains.annotations.NotNull)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)22 Tuple (org.apache.ignite.table.Tuple)21 Test (org.junit.jupiter.api.Test)18 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)17 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)15 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)15 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)15 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)14 ArrayList (java.util.ArrayList)8 InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)6 Random (java.util.Random)5 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)5 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)5 IgniteException (org.apache.ignite.lang.IgniteException)5