Search in sources :

Example 51 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class TxAbstractTest method testTwoTables.

@Test
public void testTwoTables() throws TransactionException {
    customers.recordView().upsert(null, makeValue(1, "test"));
    accounts.recordView().upsert(null, makeValue(1, 100.));
    assertEquals("test", customers.recordView().get(null, makeKey(1)).stringValue("name"));
    assertEquals(100., accounts.recordView().get(null, makeKey(1)).doubleValue("balance"));
    InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
    InternalTransaction tx2 = (InternalTransaction) igniteTransactions.begin();
    var txCust = customers.recordView();
    var txAcc = accounts.recordView();
    txCust.upsert(tx, makeValue(1, "test2"));
    txAcc.upsert(tx, makeValue(1, 200.));
    Tuple txValCust = txCust.get(tx, makeKey(1));
    assertEquals("test2", txValCust.stringValue("name"));
    txValCust.set("accountNumber", 2L);
    txValCust.set("name", "test3");
    Tuple txValAcc = txAcc.get(tx, makeKey(1));
    assertEquals(200., txValAcc.doubleValue("balance"));
    txValAcc.set("accountNumber", 2L);
    txValAcc.set("balance", 300.);
    tx.commit();
    tx2.commit();
    assertEquals("test2", customers.recordView().get(null, makeKey(1)).stringValue("name"));
    assertEquals(200., accounts.recordView().get(null, makeKey(1)).doubleValue("balance"));
    assertTrue(lockManager(accounts).isEmpty());
}
Also used : InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 52 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class TxAbstractTest method doTestComplex.

/**
 * Checks operation over tuple record view. The scenario was moved from ITDistributedTableTest.
 *
 * @param view Record view.
 * @param tx   Transaction or {@code null} for implicit one.
 */
private void doTestComplex(RecordView<Tuple> view, Transaction tx) {
    final int keysCnt = 10;
    long start = System.nanoTime();
    for (long i = 0; i < keysCnt; i++) {
        view.insert(tx, makeValue(i, i + 2.));
    }
    long dur = (long) ((System.nanoTime() - start) / 1000 / 1000.);
    log.info("Inserted={}, time={}ms  avg={} tps={}", keysCnt, dur, dur / keysCnt, 1000 / (dur / (float) keysCnt));
    for (long i = 0; i < keysCnt; i++) {
        Tuple entry = view.get(tx, makeKey(i));
        assertEquals(i + 2., entry.doubleValue("balance"));
    }
    for (int i = 0; i < keysCnt; i++) {
        view.upsert(tx, makeValue(i, i + 5.));
        Tuple entry = view.get(tx, makeKey(i));
        assertEquals(i + 5., entry.doubleValue("balance"));
    }
    HashSet<Tuple> keys = new HashSet<>();
    for (long i = 0; i < keysCnt; i++) {
        keys.add(makeKey(i));
    }
    Collection<Tuple> entries = view.getAll(tx, keys);
    assertEquals(keysCnt, entries.size());
    for (long i = 0; i < keysCnt; i++) {
        boolean res = view.replace(tx, makeValue(i, i + 5.), makeValue(i, i + 2.));
        assertTrue(res, "Failed to replace for idx=" + i);
    }
    for (long i = 0; i < keysCnt; i++) {
        boolean res = view.delete(tx, makeKey(i));
        assertTrue(res);
        Tuple entry = view.get(tx, makeKey(i));
        assertNull(entry);
    }
    ArrayList<Tuple> batch = new ArrayList<>(keysCnt);
    for (long i = 0; i < keysCnt; i++) {
        batch.add(makeValue(i, i + 2.));
    }
    view.upsertAll(tx, batch);
    for (long i = 0; i < keysCnt; i++) {
        Tuple entry = view.get(tx, makeKey(i));
        assertEquals(i + 2., entry.doubleValue("balance"));
    }
    view.deleteAll(tx, keys);
    for (Tuple key : keys) {
        Tuple entry = view.get(tx, key);
        assertNull(entry);
    }
}
Also used : ArrayList(java.util.ArrayList) Tuple(org.apache.ignite.table.Tuple) HashSet(java.util.HashSet)

Example 53 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class NumericTypesSerializerTest method testStringDecimalSpecialCase.

@Test
public void testStringDecimalSpecialCase() throws TupleMarshallerException {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(1, 0), false) });
    // representation of "0000" value.
    final Tuple tup = createTuple().set("key", rnd.nextLong()).set("decimalCol", new BigDecimal("0E+3"));
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    final Row row = marshaller.marshal(tup);
    assertEquals(row.decimalValue(1), BigDecimal.ZERO);
}
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) BigDecimal(java.math.BigDecimal) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 54 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class NumericTypesSerializerTest method testPrecisionRestrictionsForNumbers.

@Test
public void testPrecisionRestrictionsForNumbers() {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("number1", NativeTypes.numberOf(5), false) });
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    final Tuple badTup = createTuple().set("key", rnd.nextLong());
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", BigInteger.valueOf(999991L))), "Column's type mismatch");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", new BigInteger("111111"))), "Column's type mismatch");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", BigInteger.valueOf(-999991L))), "Column's type mismatch");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", new BigInteger("-111111"))), "Column's type mismatch");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) BigInteger(java.math.BigInteger) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 55 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class NumericTypesSerializerTest method testSameBinaryRepresentation.

/**
 * Test.
 */
@ParameterizedTest
@MethodSource("sameDecimals")
public void testSameBinaryRepresentation(Pair<BigInteger, BigInteger> pair) throws Exception {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(19, 3), false) });
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    long randomKey = rnd.nextLong();
    final Tuple firstTup = createTuple().set("key", randomKey).set("decimalCol", pair.getFirst());
    final Tuple secondTup = createTuple().set("key", randomKey).set("decimalCol", pair.getSecond());
    final Row firstRow = marshaller.marshal(firstTup);
    final Row secondRow = marshaller.marshal(secondTup);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    firstRow.writeTo(stream);
    byte[] firstRowInBytes = stream.toByteArray();
    stream.reset();
    secondRow.writeTo(stream);
    byte[] secondRowInBytes = stream.toByteArray();
    assertArrayEquals(firstRowInBytes, secondRowInBytes);
}
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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Tuple(org.apache.ignite.table.Tuple) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Tuple (org.apache.ignite.table.Tuple)130 Test (org.junit.jupiter.api.Test)101 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)33 Table (org.apache.ignite.table.Table)27 Column (org.apache.ignite.internal.schema.Column)25 Row (org.apache.ignite.internal.schema.row.Row)21 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)19 Ignite (org.apache.ignite.Ignite)17 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)17 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)17 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)17 InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)10 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)9 ArrayList (java.util.ArrayList)8 Disabled (org.junit.jupiter.api.Disabled)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)7 BigDecimal (java.math.BigDecimal)6 Transaction (org.apache.ignite.tx.Transaction)6