Search in sources :

Example 46 with BinaryRow

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

the class KeyValueBinaryViewImpl method putAllAsync.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Void> putAllAsync(@Nullable Transaction tx, @NotNull Map<Tuple, Tuple> pairs) {
    Objects.requireNonNull(pairs);
    List<BinaryRow> rows = new ArrayList<>(pairs.size());
    for (Map.Entry<Tuple, Tuple> pair : pairs.entrySet()) {
        final Row row = marshal(pair.getKey(), pair.getValue());
        rows.add(row);
    }
    return tbl.upsertAll(rows, (InternalTransaction) tx);
}
Also used : ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) Map(java.util.Map) Tuple(org.apache.ignite.table.Tuple) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with BinaryRow

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

the class StopCalciteModuleTest method before.

/**
 * Before.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
@BeforeEach
public void before(TestInfo testInfo) {
    when(clusterSrvc.messagingService()).thenReturn(msgSrvc);
    when(clusterSrvc.topologyService()).thenReturn(topologySrvc);
    when(clusterSrvc.localConfiguration()).thenReturn(localCfg);
    ClusterNode node = new ClusterNode("mock-node-id", NODE_NAME, null);
    when(topologySrvc.localMember()).thenReturn(node);
    when(topologySrvc.allMembers()).thenReturn(Collections.singleton(node));
    SchemaDescriptor schemaDesc = new SchemaDescriptor(1, new Column[] { new Column(0, "ID", NativeTypes.INT32, false) }, new Column[] { new Column(1, "VAL", NativeTypes.INT32, false) });
    schemaReg = new SchemaRegistryImpl(1, (v) -> schemaDesc, () -> INITIAL_SCHEMA_VERSION);
    when(tbl.name()).thenReturn("PUBLIC.TEST");
    // Mock create table (notify on register listener).
    doAnswer(invocation -> {
        EventListener<TableEventParameters> clo = (EventListener<TableEventParameters>) invocation.getArguments()[1];
        clo.notify(new TableEventParameters(0, UUID.randomUUID(), "TEST", new TableImpl(tbl, schemaReg)), null);
        return null;
    }).when(tableManager).listen(eq(TableEvent.CREATE), any());
    RowAssembler asm = new RowAssembler(schemaReg.schema(), 0, 0, 0, 0);
    asm.appendInt(0);
    asm.appendInt(0);
    BinaryRow binaryRow = asm.build();
    // Mock table scan
    doAnswer(invocation -> {
        int part = (int) invocation.getArguments()[0];
        return (Flow.Publisher<BinaryRow>) s -> {
            s.onSubscribe(new Flow.Subscription() {

                @Override
                public void request(long n) {
                }

                @Override
                public void cancel() {
                }
            });
            if (part == 0) {
                for (int i = 0; i < ROWS; ++i) {
                    s.onNext(binaryRow);
                }
            }
            s.onComplete();
        };
    }).when(tbl).scan(anyInt(), any());
    LOG.info(">>>> Starting test {}", testInfo.getTestMethod().orElseThrow().getName());
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) InternalTable(org.apache.ignite.internal.table.InternalTable) IgniteException(org.apache.ignite.lang.IgniteException) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) IgniteLogger(org.apache.ignite.lang.IgniteLogger) ThreadInfo(java.lang.management.ThreadInfo) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) TableImpl(org.apache.ignite.internal.table.TableImpl) Flow(java.util.concurrent.Flow) INITIAL_SCHEMA_VERSION(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ManagementFactory(java.lang.management.ManagementFactory) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) MessagingService(org.apache.ignite.network.MessagingService) TableManager(org.apache.ignite.internal.table.distributed.TableManager) TopologyService(org.apache.ignite.network.TopologyService) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) Mockito.when(org.mockito.Mockito.when) ThreadMXBean(java.lang.management.ThreadMXBean) UUID(java.util.UUID) TestInfo(org.junit.jupiter.api.TestInfo) ClusterNode(org.apache.ignite.network.ClusterNode) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) Column(org.apache.ignite.internal.schema.Column) TableEvent(org.apache.ignite.internal.table.event.TableEvent) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ClusterService(org.apache.ignite.network.ClusterService) EventListener(org.apache.ignite.internal.manager.EventListener) Collections(java.util.Collections) SchemaRegistry(org.apache.ignite.internal.schema.SchemaRegistry) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableImpl(org.apache.ignite.internal.table.TableImpl) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) Flow(java.util.concurrent.Flow) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) Column(org.apache.ignite.internal.schema.Column) EventListener(org.apache.ignite.internal.manager.EventListener) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 48 with BinaryRow

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

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

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

BinaryRow (org.apache.ignite.internal.schema.BinaryRow)57 Row (org.apache.ignite.internal.schema.row.Row)34 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 MethodSource (org.junit.jupiter.params.provider.MethodSource)19 Column (org.apache.ignite.internal.schema.Column)18 ArrayList (java.util.ArrayList)13 NotNull (org.jetbrains.annotations.NotNull)11 IgniteException (org.apache.ignite.lang.IgniteException)10 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)9 CountDownLatch (java.util.concurrent.CountDownLatch)6 Subscription (java.util.concurrent.Flow.Subscription)6 Test (org.junit.jupiter.api.Test)5 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)4 HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 Flow (java.util.concurrent.Flow)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3