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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations