Search in sources :

Example 71 with Tuple

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

the class ItFunctionsTest method testRangeWithCache.

@Test
public void testRangeWithCache() {
    TableDefinition tblDef = SchemaBuilders.tableBuilder("PUBLIC", "TEST").columns(SchemaBuilders.column("ID", ColumnType.INT32).build(), SchemaBuilders.column("VAL", ColumnType.INT32).build()).withPrimaryKey("ID").build();
    String tblName = tblDef.canonicalName();
    RecordView<Tuple> tbl = CLUSTER_NODES.get(0).tables().createTable(tblDef.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(tblDef, tblCh).changeReplicas(1).changePartitions(10)).recordView();
    try {
        for (int i = 0; i < 100; i++) {
            tbl.insert(null, Tuple.create().set("ID", i).set("VAL", i));
        }
        // Correlated INNER join.
        assertQuery("SELECT t.val FROM test t WHERE t.val < 5 AND " + "t.id in (SELECT x FROM table(system_range(t.val, t.val))) ").returns(0).returns(1).returns(2).returns(3).returns(4).check();
        // Correlated LEFT joins.
        assertQuery("SELECT t.val FROM test t WHERE t.val < 5 AND " + "EXISTS (SELECT x FROM table(system_range(t.val, t.val)) WHERE mod(x, 2) = 0) ").returns(0).returns(2).returns(4).check();
        assertQuery("SELECT t.val FROM test t WHERE t.val < 5 AND " + "NOT EXISTS (SELECT x FROM table(system_range(t.val, t.val)) WHERE mod(x, 2) = 0) ").returns(1).returns(3).check();
        assertQuery("SELECT t.val FROM test t WHERE " + "EXISTS (SELECT x FROM table(system_range(t.val, null))) ").check();
        // Non-correlated join.
        assertQuery("SELECT t.val FROM test t JOIN table(system_range(1, 50)) as r ON t.id = r.x " + "WHERE mod(r.x, 10) = 0").returns(10).returns(20).returns(30).returns(40).returns(50).check();
    } finally {
        CLUSTER_NODES.get(0).tables().dropTable(tblName);
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) RecordView(org.apache.ignite.table.RecordView) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Time(java.sql.Time) LongFunction(java.util.function.LongFunction) IgniteException(org.apache.ignite.lang.IgniteException) SchemaConfigurationConverter(org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter) Timestamp(java.sql.Timestamp) SqlValidatorException(org.apache.calcite.sql.validate.SqlValidatorException) ColumnType(org.apache.ignite.schema.definition.ColumnType) Disabled(org.junit.jupiter.api.Disabled) Date(java.sql.Date) Test(org.junit.jupiter.api.Test) IgniteTestUtils(org.apache.ignite.internal.testframework.IgniteTestUtils) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IgniteStringFormatter(org.apache.ignite.lang.IgniteStringFormatter) Tuple(org.apache.ignite.table.Tuple) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 72 with Tuple

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

the class InteropOperationsTest method readKeyValueBinary.

/**
 * Read through binary view.
 *
 * @param id Id to read.
 * @return {@code true} if read successfully, {@code false} - otherwise.
 */
private boolean readKeyValueBinary(int id, boolean nulls) {
    Tuple k = Tuple.create().set("id", (long) id);
    Tuple v = KV_BIN_VIEW.get(null, k);
    boolean contains = KV_BIN_VIEW.contains(null, k);
    assertEquals((v != null), contains);
    if (v == null) {
        return false;
    }
    v.set("id", (long) id);
    validateTuple(id, v, nulls);
    return true;
}
Also used : Tuple(org.apache.ignite.table.Tuple)

Example 73 with Tuple

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

the class KeyValueBinaryViewOperationsTest method contains.

@Test
public void contains() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id", NativeTypes.INT64, false) }, new Column[] { new Column("val", NativeTypes.INT64, false) });
    KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
    final Tuple key = Tuple.create().set("id", 1L);
    final Tuple val = Tuple.create().set("val", 11L);
    final Tuple val2 = Tuple.create().set("val", 22L);
    // Not-existed value.
    assertFalse(tbl.contains(null, key));
    // Put KV pair.
    tbl.put(null, key, val);
    assertTrue(tbl.contains(null, Tuple.create().set("id", 1L)));
    // Delete key.
    assertTrue(tbl.remove(null, key));
    assertFalse(tbl.contains(null, Tuple.create().set("id", 1L)));
    // Put KV pair.
    tbl.put(null, key, val2);
    assertTrue(tbl.contains(null, Tuple.create().set("id", 1L)));
    // Non-existed key.
    assertFalse(tbl.contains(null, Tuple.create().set("id", 2L)));
    tbl.remove(null, Tuple.create().set("id", 2L));
    assertFalse(tbl.contains(null, Tuple.create().set("id", 2L)));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 74 with Tuple

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

the class KeyValueBinaryViewOperationsTest method putIfAbsent.

@Test
public void putIfAbsent() {
    SchemaDescriptor schema = schemaDescriptor();
    KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
    final Tuple key = Tuple.create().set("id", 1L);
    final Tuple val = Tuple.create().set("val", 11L);
    final Tuple val2 = Tuple.create().set("val", 22L);
    assertNull(tbl.get(null, key));
    // Insert new KV pair.
    assertTrue(tbl.putIfAbsent(null, key, val));
    assertEqualsValues(schema, val, tbl.get(null, key));
    assertEqualsValues(schema, val, tbl.get(null, Tuple.create().set("id", 1L)));
    // Update KV pair.
    assertFalse(tbl.putIfAbsent(null, key, val2));
    assertEqualsValues(schema, val, tbl.get(null, key));
    assertEqualsValues(schema, val, tbl.get(null, Tuple.create().set("id", 1L)));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 75 with Tuple

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

the class TupleMarshallerFixlenOnlyBenchmark method measureTupleBuildAndMarshallerCost.

/**
 * Measure tuple build then marshall.
 *
 * @param bh Black hole.
 */
@Benchmark
public void measureTupleBuildAndMarshallerCost(Blackhole bh) throws TupleMarshallerException {
    final Columns cols = schema.valueColumns();
    final Tuple valBld = Tuple.create(cols.length());
    for (int i = 0; i < cols.length(); i++) {
        valBld.set(cols.column(i).name(), vals[i]);
    }
    Tuple keyTuple = Tuple.create(1).set("key", rnd.nextLong());
    final Row row = marshaller.marshal(keyTuple, valBld);
    bh.consume(row);
}
Also used : Columns(org.apache.ignite.internal.schema.Columns) Row(org.apache.ignite.internal.schema.row.Row) Tuple(org.apache.ignite.table.Tuple) Benchmark(org.openjdk.jmh.annotations.Benchmark)

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