use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class NumericTypesSerializerTest method testPrecisionRestrictionsForDecimal.
@Test
public void testPrecisionRestrictionsForDecimal() {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(9, 3), false) });
final Tuple badTup = createTuple().set("key", rnd.nextLong());
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("123456789.0123"))), "Failed to set decimal value for column");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("-1234567890123"))), "Failed to set decimal value for column");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("1234567"))), "Failed to set decimal value for column");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("12345678.9"))), "Failed to set decimal value for column");
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class RecordViewExample method main.
/**
* Main method of the example.
*
* @param args The command line arguments.
* @throws Exception If failed.
*/
public static void main(String[] args) throws Exception {
try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
Statement stmt = conn.createStatement()) {
stmt.executeUpdate("CREATE TABLE accounts (" + "accountNumber INT PRIMARY KEY," + "firstName VARCHAR," + "lastName VARCHAR," + "balance DOUBLE)");
}
// --------------------------------------------------------------------------------------
//
// Creating a client to connect to the cluster.
//
// --------------------------------------------------------------------------------------
System.out.println("\nConnecting to server...");
try (IgniteClient client = IgniteClient.builder().addresses("127.0.0.1:10800").build()) {
// --------------------------------------------------------------------------------------
//
// Creating a record view for the 'accounts' table.
//
// --------------------------------------------------------------------------------------
RecordView<Tuple> accounts = client.tables().table("PUBLIC.accounts").recordView();
// --------------------------------------------------------------------------------------
//
// Performing the 'insert' operation.
//
// --------------------------------------------------------------------------------------
System.out.println("\nInserting a record into the 'accounts' table...");
Tuple newAccountTuple = Tuple.create().set("accountNumber", 123456).set("firstName", "Val").set("lastName", "Kulichenko").set("balance", 100.00d);
accounts.insert(null, newAccountTuple);
// --------------------------------------------------------------------------------------
//
// Performing the 'get' operation.
//
// --------------------------------------------------------------------------------------
System.out.println("\nRetrieving a record using RecordView API...");
Tuple accountNumberTuple = Tuple.create().set("accountNumber", 123456);
Tuple accountTuple = accounts.get(null, accountNumberTuple);
System.out.println("\nRetrieved record:\n" + " Account Number: " + accountTuple.intValue("accountNumber") + '\n' + " Owner: " + accountTuple.stringValue("firstName") + " " + accountTuple.stringValue("lastName") + '\n' + " Balance: $" + accountTuple.doubleValue("balance"));
} finally {
System.out.println("\nDropping the table...");
try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
Statement stmt = conn.createStatement()) {
stmt.executeUpdate("DROP TABLE accounts");
}
}
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class ClientKeyValueBinaryViewTest method testRecordUpsertKvGet.
@Test
public void testRecordUpsertKvGet() {
Table table = defaultTable();
table.recordView().upsert(null, tuple());
KeyValueView<Tuple, Tuple> kvView = table.keyValueView();
Tuple key = defaultTupleKey();
Tuple val = kvView.get(null, key);
assertEquals(DEFAULT_NAME, val.value("name"));
assertEquals(DEFAULT_NAME, val.value(0));
assertEquals(1, val.columnCount());
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class ClientKeyValueViewTest method testColumnWithDefaultValueNotSetReturnsDefault.
@Test
public void testColumnWithDefaultValueNotSetReturnsDefault() {
Table table = tableWithDefaultValues();
RecordView<Tuple> recordView = table.recordView();
KeyValueView<Integer, NamePojo> pojoView = table.keyValueView(Integer.class, NamePojo.class);
pojoView.put(null, 1, new NamePojo());
var res = recordView.get(null, tupleKey(1));
assertEquals("def_str", res.stringValue("str"));
assertEquals("def_str2", res.stringValue("strNonNull"));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class ClientKeyValueViewTest method testNullablePrimitiveFields.
@Test
public void testNullablePrimitiveFields() {
KeyValueView<IncompletePojoNullable, IncompletePojoNullable> pojoView = fullTable().keyValueView(IncompletePojoNullable.class, IncompletePojoNullable.class);
RecordView<Tuple> tupleView = fullTable().recordView();
var rec = new IncompletePojoNullable();
rec.id = "1";
rec.gid = 1;
pojoView.put(null, rec, rec);
IncompletePojoNullable res = pojoView.get(null, rec);
Tuple binRes = tupleView.get(null, Tuple.create().set("id", "1").set("gid", 1L));
assertNotNull(res);
assertNotNull(binRes);
assertNull(res.zbyte);
assertNull(res.zshort);
assertNull(res.zint);
assertNull(res.zlong);
assertNull(res.zfloat);
assertNull(res.zdouble);
for (int i = 0; i < binRes.columnCount(); i++) {
if (binRes.columnName(i).endsWith("ID")) {
continue;
}
assertNull(binRes.value(i));
}
}
Aggregations