Search in sources :

Example 21 with Table

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

the class ClientKeyValueViewTest method testBinaryPutPrimitiveGet.

@Test
public void testBinaryPutPrimitiveGet() {
    Table table = defaultTable();
    KeyValueView<Long, String> primitiveView = table.keyValueView(Mapper.of(Long.class), Mapper.of(String.class));
    table.recordView().upsert(null, tuple());
    String val = primitiveView.get(null, DEFAULT_ID);
    String missingVal = primitiveView.get(null, -1L);
    assertEquals(DEFAULT_NAME, val);
    assertNull(missingVal);
}
Also used : Table(org.apache.ignite.table.Table) Test(org.junit.jupiter.api.Test)

Example 22 with Table

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

the class ClientKeyValueViewTest method testMissingValueColumnsAreSkipped.

@Test
public void testMissingValueColumnsAreSkipped() {
    Table table = fullTable();
    KeyValueView<Tuple, Tuple> kvView = table.keyValueView();
    KeyValueView<IncompletePojo, IncompletePojo> pojoView = table.keyValueView(IncompletePojo.class, IncompletePojo.class);
    kvView.put(null, allClumnsTableKey(1), allColumnsTableVal("x"));
    var key = new IncompletePojo();
    key.id = "1";
    key.gid = 1;
    // This POJO does not have fields for all table columns, and this is ok.
    IncompletePojo val = pojoView.get(null, key);
    assertEquals(0, val.gid);
    assertNull(val.id);
    assertEquals("x", val.zstring);
    assertEquals(2, val.zbytes[1]);
    assertEquals(11, val.zbyte);
}
Also used : Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 23 with Table

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

the class ClientKeyValueViewTest method testAllColumnsBinaryPutPojoGet.

@Test
public void testAllColumnsBinaryPutPojoGet() {
    Table table = fullTable();
    KeyValueView<IncompletePojo, AllColumnsPojo> pojoView = table.keyValueView(Mapper.of(IncompletePojo.class), Mapper.of(AllColumnsPojo.class));
    table.recordView().upsert(null, allColumnsTableVal("foo"));
    var key = new IncompletePojo();
    key.gid = (int) (long) DEFAULT_ID;
    key.id = String.valueOf(DEFAULT_ID);
    AllColumnsPojo res = pojoView.get(null, key);
    assertEquals(11, res.zbyte);
    assertEquals(12, res.zshort);
    assertEquals(13, res.zint);
    assertEquals(14, res.zlong);
    assertEquals(1.5f, res.zfloat);
    assertEquals(1.6, res.zdouble);
    assertEquals(localDate, res.zdate);
    assertEquals(localTime.withNano(truncateNanosToMicros(localTime.getNano())), res.ztime);
    assertEquals(instant.with(NANO_OF_SECOND, truncateNanosToMicros(instant.getNano())), res.ztimestamp);
    assertEquals("foo", res.zstring);
    assertArrayEquals(new byte[] { 1, 2 }, res.zbytes);
    assertEquals(BitSet.valueOf(new byte[] { 32 }), res.zbitmask);
    assertEquals(21, res.zdecimal.longValue());
    assertEquals(22, res.znumber.longValue());
    assertEquals(uuid, res.zuuid);
}
Also used : Table(org.apache.ignite.table.Table) Test(org.junit.jupiter.api.Test)

Example 24 with Table

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

the class ClientKeyValueViewTest method testGetAll.

@Test
public void testGetAll() {
    Table table = defaultTable();
    KeyValueView<Long, PersonPojo> pojoView = table.keyValueView(Mapper.of(Long.class), Mapper.of(PersonPojo.class));
    table.recordView().upsert(null, tuple());
    table.recordView().upsert(null, tuple(100L, "100"));
    Collection<Long> keys = List.of(DEFAULT_ID, 101L, 100L);
    Map<Long, PersonPojo> res = pojoView.getAll(null, keys);
    Long[] resKeys = res.keySet().toArray(new Long[0]);
    PersonPojo[] resVals = res.values().toArray(new PersonPojo[0]);
    assertEquals(2, resVals.length);
    assertNotNull(resVals[0]);
    assertNotNull(resVals[1]);
    assertEquals(DEFAULT_ID, resKeys[0]);
    assertEquals(DEFAULT_NAME, resVals[0].name);
    assertEquals(100L, resKeys[1]);
    assertEquals("100", resVals[1].name);
}
Also used : Table(org.apache.ignite.table.Table) Test(org.junit.jupiter.api.Test)

Example 25 with Table

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

the class ClientKeyValueViewTest method testNullableColumnWithDefaultValueSetNullReturnsNull.

@Test
public void testNullableColumnWithDefaultValueSetNullReturnsNull() {
    Table table = tableWithDefaultValues();
    RecordView<Tuple> recordView = table.recordView();
    KeyValueView<Integer, DefaultValuesPojo> pojoView = table.keyValueView(Integer.class, DefaultValuesPojo.class);
    var pojo = new DefaultValuesPojo();
    pojo.str = null;
    pojo.strNonNull = "s";
    pojoView.put(null, 1, pojo);
    var res = recordView.get(null, tupleKey(1));
    assertNull(res.stringValue("str"));
}
Also used : BigInteger(java.math.BigInteger) Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Aggregations

Table (org.apache.ignite.table.Table)65 Test (org.junit.jupiter.api.Test)51 Tuple (org.apache.ignite.table.Tuple)29 Ignite (org.apache.ignite.Ignite)15 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)15 List (java.util.List)12 UUID (java.util.UUID)12 CompletableFuture (java.util.concurrent.CompletableFuture)12 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)12 ArrayList (java.util.ArrayList)11 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)11 TableImpl (org.apache.ignite.internal.table.TableImpl)10 Function (java.util.function.Function)9 Collectors (java.util.stream.Collectors)9 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)9 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)8 ColumnType (org.apache.ignite.schema.definition.ColumnType)8 NotNull (org.jetbrains.annotations.NotNull)8 Consumer (java.util.function.Consumer)7 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)7