Search in sources :

Example 16 with QueryField

use of org.apache.ignite.internal.processors.query.QueryField in project ignite by apache.

the class H2DynamicColumnsAbstractBasicSelfTest method testAddColumnToNonDynamicCacheWithRealValueType.

/**
 * Test that we can add columns dynamically to tables associated with non dynamic caches storing user types as well.
 */
@SuppressWarnings("unchecked")
public void testAddColumnToNonDynamicCacheWithRealValueType() throws SQLException {
    CacheConfiguration<Integer, City> ccfg = defaultCacheConfiguration().setName("City").setIndexedTypes(Integer.class, City.class);
    IgniteCache<Integer, ?> cache = ignite(nodeIndex()).getOrCreateCache(ccfg);
    run(cache, "ALTER TABLE \"City\".City ADD COLUMN population int");
    doSleep(500);
    QueryField c = c("POPULATION", Integer.class.getName());
    checkTableState("City", "CITY", c);
    run(cache, "INSERT INTO \"City\".City (_key, id, name, state_name, population) values " + "(1, 1, 'Washington', 'DC', 2500000)");
    List<List<?>> res = run(cache, "select _key, id, name, state_name, population from \"City\".City");
    assertEquals(Collections.singletonList(Arrays.asList(1, 1, "Washington", "DC", 2500000)), res);
    if (!Boolean.valueOf(GridTestProperties.getProperty(BINARY_MARSHALLER_USE_SIMPLE_NAME_MAPPER))) {
        City city = (City) cache.get(1);
        assertEquals(1, city.id());
        assertEquals("Washington", city.name());
        assertEquals("DC", city.state());
    } else {
        BinaryObject city = (BinaryObject) cache.withKeepBinary().get(1);
        assertEquals(1, (int) city.field("id"));
        assertEquals("Washington", (String) city.field("name"));
        assertEquals("DC", (String) city.field("state"));
        assertEquals(2500000, (int) city.field("population"));
    }
    cache.destroy();
}
Also used : QueryField(org.apache.ignite.internal.processors.query.QueryField) BinaryObject(org.apache.ignite.binary.BinaryObject) List(java.util.List)

Example 17 with QueryField

use of org.apache.ignite.internal.processors.query.QueryField in project ignite by apache.

the class H2DynamicColumnsAbstractBasicSelfTest method testAddNullColumn.

/**
 * Test addition of column explicitly defined as nullable.
 */
public void testAddNullColumn() throws SQLException {
    run("ALTER TABLE Person ADD COLUMN age int NULL");
    doSleep(500);
    QueryField c = new QueryField("AGE", Integer.class.getName(), true);
    checkTableState(QueryUtils.DFLT_SCHEMA, "PERSON", c);
}
Also used : QueryField(org.apache.ignite.internal.processors.query.QueryField)

Aggregations

QueryField (org.apache.ignite.internal.processors.query.QueryField)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 Ignite (org.apache.ignite.Ignite)4 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)4 List (java.util.List)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 BinaryObject (org.apache.ignite.binary.BinaryObject)3 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 IgniteException (org.apache.ignite.IgniteException)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1