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);
}
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);
}
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);
}
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);
}
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"));
}
Aggregations