Search in sources :

Example 1 with ByteBufferRow

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

the class UpgradingRowAdapterTest method validateRow.

private void validateRow(List<Object> values, SchemaRegistryImpl schemaRegistry, ByteBufferRow binaryRow) {
    Row row = schemaRegistry.resolve(binaryRow);
    SchemaDescriptor schema = row.schema();
    for (int i = 0; i < values.size(); i++) {
        Column col = schema.column(i);
        NativeTypeSpec type = col.type().spec();
        if (type == NativeTypeSpec.BYTES) {
            assertArrayEquals((byte[]) values.get(i), (byte[]) NativeTypeSpec.BYTES.objectValue(row, col.schemaIndex()), "Failed for column: " + col);
        } else {
            assertEquals(values.get(i), type.objectValue(row, col.schemaIndex()), "Failed for column: " + col);
        }
    }
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow)

Example 2 with ByteBufferRow

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

the class ItInternalTableScanTest method setUp.

/**
 * Prepare test environment.
 * <ol>
 * <li>Start network node.</li>
 * <li>Start raft server.</li>
 * <li>Prepare partitioned raft group.</li>
 * <li>Prepare partitioned raft group service.</li>
 * <li>Prepare internal table as a test object.</li>
 * </ol>
 *
 * @throws Exception If any.
 */
@BeforeEach
public void setUp(TestInfo testInfo) throws Exception {
    NetworkAddress nodeNetworkAddress = new NetworkAddress("localhost", 20_000);
    network = ClusterServiceTestUtils.clusterService(testInfo, 20_000, new StaticNodeFinder(List.of(nodeNetworkAddress)), NETWORK_FACTORY);
    network.start();
    raftSrv = new RaftServerImpl(network, FACTORY);
    raftSrv.start();
    String grpName = "test_part_grp";
    List<Peer> conf = List.of(new Peer(nodeNetworkAddress));
    mockStorage = mock(PartitionStorage.class);
    txManager = new TxManagerImpl(network, new HeapLockManager());
    txManager.start();
    UUID tblId = UUID.randomUUID();
    raftSrv.startRaftGroup(grpName, new PartitionListener(tblId, new VersionedRowStore(mockStorage, txManager) {

        @Override
        protected Pair<BinaryRow, BinaryRow> versionedRow(@Nullable DataRow row, Timestamp timestamp) {
            // Return as is.
            return new Pair<>(new ByteBufferRow(row.valueBytes()), null);
        }
    }), conf);
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
    RaftGroupService raftGrpSvc = RaftGroupServiceImpl.start(RAFT_GRP_ID, network, FACTORY, 10_000, conf, true, 200, executor).get(3, TimeUnit.SECONDS);
    internalTbl = new InternalTableImpl(TEST_TABLE_NAME, tblId, Int2ObjectMaps.singleton(0, raftGrpSvc), 1, NetworkAddress::toString, txManager, mock(TableStorage.class));
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) Peer(org.apache.ignite.raft.client.Peer) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SimpleDataRow(org.apache.ignite.internal.storage.basic.SimpleDataRow) DataRow(org.apache.ignite.internal.storage.DataRow) Timestamp(org.apache.ignite.internal.tx.Timestamp) RaftServerImpl(org.apache.ignite.internal.raft.server.impl.RaftServerImpl) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) NetworkAddress(org.apache.ignite.network.NetworkAddress) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) UUID(java.util.UUID) Nullable(org.jetbrains.annotations.Nullable) PartitionStorage(org.apache.ignite.internal.storage.PartitionStorage) Pair(org.apache.ignite.internal.util.Pair) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ByteBufferRow

use of org.apache.ignite.internal.schema.ByteBufferRow 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 4 with ByteBufferRow

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

Example 5 with ByteBufferRow

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

the class RecordMarshallerImpl method marshalKey.

/**
 * {@inheritDoc}
 */
@Override
public BinaryRow marshalKey(@NotNull R rec) throws MarshallerException {
    assert recClass.isInstance(rec);
    final RowAssembler asm = createAssembler(Objects.requireNonNull(rec), null);
    keyMarsh.writeObject(rec, asm);
    return new ByteBufferRow(asm.toBytes());
}
Also used : ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler)

Aggregations

ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)22 Row (org.apache.ignite.internal.schema.row.Row)14 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)10 Tuple (org.apache.ignite.table.Tuple)10 Test (org.junit.jupiter.api.Test)10 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)7 Random (java.util.Random)5 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)4 Column (org.apache.ignite.internal.schema.Column)3 SchemaAware (org.apache.ignite.internal.schema.SchemaAware)3 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)3 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)2 Timestamp (org.apache.ignite.internal.tx.Timestamp)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ByteBuffer (java.nio.ByteBuffer)1