Search in sources :

Example 56 with Tuple

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");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Tuple(org.apache.ignite.table.Tuple) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 57 with Tuple

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");
        }
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Statement(java.sql.Statement) Connection(java.sql.Connection) Tuple(org.apache.ignite.table.Tuple)

Example 58 with Tuple

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());
}
Also used : Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 59 with Tuple

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"));
}
Also used : BigInteger(java.math.BigInteger) Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 60 with Tuple

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));
    }
}
Also used : 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