Search in sources :

Example 96 with Tuple

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

the class ClientKeyValueViewTest method testPrimitivePutBinaryGet.

@Test
public void testPrimitivePutBinaryGet() {
    Table table = defaultTable();
    KeyValueView<Long, String> primitiveView = table.keyValueView(Mapper.of(Long.class), Mapper.of(String.class));
    primitiveView.put(null, DEFAULT_ID, DEFAULT_NAME);
    Tuple tuple = table.recordView().get(null, tupleKey(DEFAULT_ID));
    assertEquals(DEFAULT_NAME, tuple.stringValue(1));
}
Also used : Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 97 with Tuple

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

the class ClientKeyValueViewTest method testAllColumnsPojoPutBinaryGet.

@Test
public void testAllColumnsPojoPutBinaryGet() {
    Table table = fullTable();
    KeyValueView<AllColumnsPojo, AllColumnsPojo> pojoView = table.keyValueView(Mapper.of(AllColumnsPojo.class), Mapper.of(AllColumnsPojo.class));
    var val = new AllColumnsPojo();
    val.gid = 111;
    val.id = "112";
    val.zbyte = 113;
    val.zshort = 114;
    val.zint = 115;
    val.zlong = 116;
    val.zfloat = 1.17f;
    val.zdouble = 1.18;
    val.zdate = localDate;
    val.ztime = localTime;
    val.ztimestamp = instant;
    val.zstring = "119";
    val.zbytes = new byte[] { 120 };
    val.zbitmask = BitSet.valueOf(new byte[] { 121 });
    val.zdecimal = BigDecimal.valueOf(122);
    val.znumber = BigInteger.valueOf(123);
    val.zuuid = uuid;
    pojoView.put(null, val, val);
    Tuple res = table.recordView().get(null, Tuple.create().set("id", "112").set("gid", 111));
    assertNotNull(res);
    assertEquals(111, res.intValue("gid"));
    assertEquals("112", res.stringValue("id"));
    assertEquals(113, res.byteValue("zbyte"));
    assertEquals(114, res.shortValue("zshort"));
    assertEquals(115, res.intValue("zint"));
    assertEquals(116, res.longValue("zlong"));
    assertEquals(1.17f, res.floatValue("zfloat"));
    assertEquals(1.18, res.doubleValue("zdouble"));
    assertEquals(localDate, res.dateValue("zdate"));
    assertEquals(localTime.withNano(truncateNanosToMicros(localTime.getNano())), res.timeValue("ztime"));
    assertEquals(instant.with(NANO_OF_SECOND, truncateNanosToMicros(instant.getNano())), res.timestampValue("ztimestamp"));
    assertEquals("119", res.stringValue("zstring"));
    assertEquals(120, ((byte[]) res.value("zbytes"))[0]);
    assertEquals(BitSet.valueOf(new byte[] { 121 }), res.bitmaskValue("zbitmask"));
    assertEquals(122, ((Number) res.value("zdecimal")).longValue());
    assertEquals(BigInteger.valueOf(123), res.value("znumber"));
    assertEquals(uuid, res.uuidValue("zuuid"));
}
Also used : Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 98 with Tuple

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

the class ClientRecordViewTest method testPrimitivePutBinaryGet.

@Test
public void testPrimitivePutBinaryGet() {
    Table table = oneColumnTable();
    RecordView<String> primitiveView = table.recordView(Mapper.of(String.class));
    primitiveView.upsert(null, "abc");
    Tuple tuple = table.recordView().get(null, oneColumnTableKey("abc"));
    assertEquals("abc", tuple.stringValue(0));
}
Also used : Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 99 with Tuple

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

the class ClientRecordViewTest method testMissingValueColumnsAreSkipped.

@Test
public void testMissingValueColumnsAreSkipped() {
    Table table = fullTable();
    KeyValueView<Tuple, Tuple> kvView = table.keyValueView();
    RecordView<IncompletePojo> pojoView = table.recordView(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(1, val.gid);
    assertEquals("1", 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 100 with Tuple

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

the class ClientRecordViewTest method testAllColumnsPojoPutBinaryGet.

@Test
public void testAllColumnsPojoPutBinaryGet() {
    Table table = fullTable();
    RecordView<AllColumnsPojo> pojoView = table.recordView(Mapper.of(AllColumnsPojo.class));
    var val = new AllColumnsPojo();
    val.gid = 111;
    val.id = "112";
    val.zbyte = 113;
    val.zshort = 114;
    val.zint = 115;
    val.zlong = 116;
    val.zfloat = 1.17f;
    val.zdouble = 1.18;
    val.zdate = localDate;
    val.ztime = localTime;
    val.ztimestamp = instant;
    val.zstring = "119";
    val.zbytes = new byte[] { 120 };
    val.zbitmask = BitSet.valueOf(new byte[] { 121 });
    val.zdecimal = BigDecimal.valueOf(122);
    val.znumber = BigInteger.valueOf(123);
    val.zuuid = uuid;
    pojoView.upsert(null, val);
    Tuple res = table.recordView().get(null, Tuple.create().set("id", "112").set("gid", 111));
    assertNotNull(res);
    assertEquals(111, res.intValue("gid"));
    assertEquals("112", res.stringValue("id"));
    assertEquals(113, res.byteValue("zbyte"));
    assertEquals(114, res.shortValue("zshort"));
    assertEquals(115, res.intValue("zint"));
    assertEquals(116, res.longValue("zlong"));
    assertEquals(1.17f, res.floatValue("zfloat"));
    assertEquals(1.18, res.doubleValue("zdouble"));
    assertEquals(localDate, res.dateValue("zdate"));
    assertEquals(localTime.withNano(truncateNanosToMicros(localTime.getNano())), res.timeValue("ztime"));
    assertEquals(instant.with(NANO_OF_SECOND, truncateNanosToMicros(instant.getNano())), res.timestampValue("ztimestamp"));
    assertEquals("119", res.stringValue("zstring"));
    assertEquals(120, ((byte[]) res.value("zbytes"))[0]);
    assertEquals(BitSet.valueOf(new byte[] { 121 }), res.bitmaskValue("zbitmask"));
    assertEquals(122, ((Number) res.value("zdecimal")).longValue());
    assertEquals(BigInteger.valueOf(123), res.value("znumber"));
    assertEquals(uuid, res.uuidValue("zuuid"));
}
Also used : Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

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