Search in sources :

Example 56 with Row

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

the class RecordBinaryViewImpl method deleteExactAsync.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Boolean> deleteExactAsync(@Nullable Transaction tx, @NotNull Tuple rec) {
    Objects.requireNonNull(rec);
    final Row row = marshal(rec, false);
    return tbl.deleteExact(row, (InternalTransaction) tx);
}
Also used : BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with Row

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

the class RecordBinaryViewImpl method getAndUpsertAsync.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Tuple> getAndUpsertAsync(@Nullable Transaction tx, @NotNull Tuple rec) {
    Objects.requireNonNull(rec);
    final Row row = marshal(rec, false);
    return tbl.getAndUpsert(row, (InternalTransaction) tx).thenApply(this::wrap);
}
Also used : BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with Row

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

the class TxAbstractTest method testScan.

@Test
public void testScan() throws InterruptedException {
    accounts.recordView().upsertAll(null, List.of(makeValue(1, 100.), makeValue(2, 200.)));
    Flow.Publisher<BinaryRow> pub = ((TableImpl) accounts).internalTable().scan(0, null);
    List<Tuple> rows = new ArrayList<>();
    CountDownLatch l = new CountDownLatch(1);
    pub.subscribe(new Flow.Subscriber<BinaryRow>() {

        @Override
        public void onSubscribe(Flow.Subscription subscription) {
            subscription.request(3);
        }

        @Override
        public void onNext(BinaryRow item) {
            Row row = ((TableImpl) accounts).schemaView().resolve(item);
            rows.add(TableRow.tuple(row));
        }

        @Override
        public void onError(Throwable throwable) {
        // No-op.
        }

        @Override
        public void onComplete() {
            l.countDown();
        }
    });
    assertTrue(l.await(5_000, TimeUnit.MILLISECONDS));
    Map<Long, Tuple> map = new HashMap<>();
    for (Tuple row : rows) {
        map.put(row.longValue("accountNumber"), row);
    }
    assertEquals(100., map.get(1L).doubleValue("balance"));
    assertEquals(200., map.get(2L).doubleValue("balance"));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) CountDownLatch(java.util.concurrent.CountDownLatch) Flow(java.util.concurrent.Flow) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 59 with Row

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

the class PartitionCommandListenerTest method getTestKey.

/**
 * Prepares a test row which contains only key field.
 *
 * @return Row.
 */
@NotNull
private Row getTestKey(int key) {
    RowAssembler rowBuilder = new RowAssembler(SCHEMA, 0, 0);
    rowBuilder.appendInt(key);
    return new Row(SCHEMA, rowBuilder.build());
}
Also used : RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) NotNull(org.jetbrains.annotations.NotNull) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull)

Example 60 with Row

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

the class NumericTypesSerializerTest method testDecimalMaxScale.

@Test
public void testDecimalMaxScale() throws TupleMarshallerException {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(Integer.MAX_VALUE, Integer.MAX_VALUE), false) });
    final Tuple tup = createTuple().set("key", rnd.nextLong()).set("decimalCol", BigDecimal.valueOf(123, Integer.MAX_VALUE));
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    final Row row = marshaller.marshal(tup);
    assertEquals(row.decimalValue(1), BigDecimal.valueOf(123, Integer.MAX_VALUE));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) Tuple(org.apache.ignite.table.Tuple) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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