Search in sources :

Example 21 with RowAssembler

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

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

the class IgniteTableImpl method deleteTuple.

private <RowT> ModifyRow deleteTuple(RowT row, ExecutionContext<RowT> ectx) {
    int nonNullVarlenKeyCols = 0;
    RowHandler<RowT> hnd = ectx.rowHandler();
    for (ColumnDescriptor colDesc : columnsOrderedByPhysSchema) {
        if (!colDesc.key()) {
            break;
        }
        if (colDesc.physicalType().spec().fixedLength()) {
            continue;
        }
        Object val = hnd.get(colDesc.logicalIndex(), row);
        if (val != null) {
            nonNullVarlenKeyCols++;
        }
    }
    RowAssembler rowAssembler = new RowAssembler(schemaDescriptor, nonNullVarlenKeyCols, 0);
    for (ColumnDescriptor colDesc : columnsOrderedByPhysSchema) {
        if (!colDesc.key()) {
            break;
        }
        RowAssembler.writeValue(rowAssembler, colDesc.physicalType(), hnd.get(colDesc.logicalIndex(), row));
    }
    return new ModifyRow(rowAssembler.build(), Operation.DELETE_ROW);
}
Also used : RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) RelReferentialConstraint(org.apache.calcite.rel.RelReferentialConstraint)

Example 23 with RowAssembler

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

the class IgniteTableImpl method updateTuple.

private <RowT> ModifyRow updateTuple(RowT row, List<String> updateColList, int offset, ExecutionContext<RowT> ectx) {
    RowHandler<RowT> hnd = ectx.rowHandler();
    Object2IntMap<String> columnToIndex = new Object2IntOpenHashMap<>(updateColList.size());
    for (int i = 0; i < updateColList.size(); i++) {
        columnToIndex.put(updateColList.get(i), i + desc.columnsCount() + offset);
    }
    int nonNullVarlenKeyCols = 0;
    int nonNullVarlenValCols = 0;
    int keyOffset = schemaDescriptor.keyColumns().firstVarlengthColumn();
    if (keyOffset > -1) {
        nonNullVarlenKeyCols = countNotNullColumns(keyOffset, schemaDescriptor.keyColumns().length(), columnToIndex, offset, hnd, row);
    }
    int valOffset = schemaDescriptor.valueColumns().firstVarlengthColumn();
    if (valOffset > -1) {
        nonNullVarlenValCols = countNotNullColumns(schemaDescriptor.keyColumns().length() + valOffset, schemaDescriptor.length(), columnToIndex, offset, hnd, row);
    }
    RowAssembler rowAssembler = new RowAssembler(schemaDescriptor, nonNullVarlenKeyCols, nonNullVarlenValCols);
    for (ColumnDescriptor colDesc : columnsOrderedByPhysSchema) {
        int colIdx = columnToIndex.getOrDefault(colDesc.name(), colDesc.logicalIndex() + offset);
        Object val = hnd.get(colIdx, row);
        RowAssembler.writeValue(rowAssembler, colDesc.physicalType(), val);
    }
    return new ModifyRow(rowAssembler.build(), Operation.UPDATE_ROW);
}
Also used : RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) RelReferentialConstraint(org.apache.calcite.rel.RelReferentialConstraint)

Example 24 with RowAssembler

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

the class ColumnBindingTest method fieldBinding.

/**
 * All native types field binding.
 *
 * @throws Exception If failed.
 */
@Test
public void fieldBinding() throws Exception {
    Column[] cols = new Column[] { new Column("primitiveByteCol", INT8, false), new Column("primitiveShortCol", INT16, false), new Column("primitiveIntCol", INT32, false), new Column("primitiveLongCol", INT64, false), new Column("primitiveFloatCol", FLOAT, false), new Column("primitiveDoubleCol", DOUBLE, false), new Column("byteCol", INT8, false), new Column("shortCol", INT16, false), new Column("intCol", INT32, false), new Column("longCol", INT64, false), new Column("floatCol", FLOAT, false), new Column("doubleCol", DOUBLE, false), new Column("dateCol", DATE, false), new Column("timeCol", time(), false), new Column("dateTimeCol", datetime(), false), new Column("timestampCol", timestamp(), false), new Column("uuidCol", UUID, false), new Column("bitmaskCol", NativeTypes.bitmaskOf(9), false), new Column("stringCol", STRING, false), new Column("bytesCol", BYTES, false), new Column("numberCol", NativeTypes.numberOf(21), false), new Column("decimalCol", NativeTypes.decimalOf(19, 3), false) };
    final Pair<RowAssembler, Row> mocks = createMocks();
    final RowAssembler rowAssembler = mocks.getFirst();
    final Row row = mocks.getSecond();
    final TestObjectWithAllTypes obj = TestObjectWithAllTypes.randomObject(rnd);
    for (int i = 0; i < cols.length; i++) {
        ColumnBinding.createFieldBinding(cols[i].copy(i), TestObjectWithAllTypes.class, cols[i].name(), null).write(rowAssembler, obj);
    }
    final TestObjectWithAllTypes restoredObj = new TestObjectWithAllTypes();
    for (int i = 0; i < cols.length; i++) {
        ColumnBinding.createFieldBinding(cols[i].copy(i), TestObjectWithAllTypes.class, cols[i].name(), null).read(row, restoredObj);
    }
    assertEquals(obj, restoredObj);
}
Also used : Column(org.apache.ignite.internal.schema.Column) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Row(org.apache.ignite.internal.schema.row.Row) Test(org.junit.jupiter.api.Test)

Example 25 with RowAssembler

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

the class ColumnBindingTest method identityBindingWithConverter.

/**
 * Identity binding with converter.
 *
 * @throws Exception If failed.
 */
@Test
public void identityBindingWithConverter() throws Exception {
    final ColumnBinding binding = ColumnBinding.createIdentityBinding(new Column("val", BYTES, true).copy(0), TestSimpleObject.class, new SerializingConverter());
    final Pair<RowAssembler, Row> mocks = createMocks();
    final RowAssembler rowAssembler = mocks.getFirst();
    final Row row = mocks.getSecond();
    final TestSimpleObject obj = TestSimpleObject.randomObject(rnd);
    binding.write(rowAssembler, obj);
    Object restoredObj = binding.columnValue(row);
    assertEquals(obj, restoredObj);
}
Also used : TestSimpleObject(org.apache.ignite.internal.schema.testobjects.TestSimpleObject) Column(org.apache.ignite.internal.schema.Column) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) TestSimpleObject(org.apache.ignite.internal.schema.testobjects.TestSimpleObject) Row(org.apache.ignite.internal.schema.row.Row) Test(org.junit.jupiter.api.Test)

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