Search in sources :

Example 26 with Table

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

the class ClientRecordViewTest method testBinaryPutPrimitiveGet.

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

Example 27 with Table

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

the class ClientRecordViewTest method testGetAllPrimitive.

@Test
public void testGetAllPrimitive() {
    Table table = oneColumnTable();
    RecordView<String> primitiveView = table.recordView(Mapper.of(String.class));
    primitiveView.upsertAll(null, List.of("a", "c"));
    String[] res = primitiveView.getAll(null, List.of("a", "b", "c")).toArray(new String[0]);
    assertEquals("a", res[0]);
    assertEquals("c", res[1]);
}
Also used : Table(org.apache.ignite.table.Table) Test(org.junit.jupiter.api.Test)

Example 28 with Table

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

the class ClientRecordViewTest method testColumnWithDefaultValueNotSetReturnsDefault.

@Test
public void testColumnWithDefaultValueNotSetReturnsDefault() {
    Table table = tableWithDefaultValues();
    RecordView<Tuple> recordView = table.recordView();
    RecordView<PersonPojo> pojoView = table.recordView(PersonPojo.class);
    pojoView.upsert(null, new PersonPojo());
    var res = recordView.get(null, tupleKey(0));
    assertEquals("def_str", res.stringValue("str"));
    assertEquals("def_str2", res.stringValue("strNonNull"));
}
Also used : Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 29 with Table

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

the class ClientRecordViewTest method testNullableColumnWithDefaultValueSetNullReturnsNull.

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

Example 30 with Table

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

the class ClientRecordViewTest method testAllColumnsBinaryPutPojoGet.

@Test
public void testAllColumnsBinaryPutPojoGet() {
    Table table = fullTable();
    RecordView<AllColumnsPojo> pojoView = table.recordView(Mapper.of(AllColumnsPojo.class));
    table.recordView().upsert(null, allColumnsTableVal("foo"));
    var key = new AllColumnsPojo();
    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)

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