Search in sources :

Example 21 with QueryField

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

the class DynamicColumnsAbstractTest method checkTableState.

/**
 * Check that given columns are seen by client.
 * @param node Node to check.
 * @param schemaName Schema name to look for the table in.
 * @param tblName Table name to check.
 * @param cols Columns whose presence must be checked.
 * @return Number of other columns.
 */
static int checkTableState(IgniteEx node, String schemaName, String tblName, QueryField... cols) throws SQLException {
    List<QueryField> flds = new ArrayList<>();
    try (Connection c = connect(node)) {
        try (ResultSet rs = c.getMetaData().getColumns(null, schemaName, tblName, "%")) {
            while (rs.next()) {
                String name = rs.getString("COLUMN_NAME");
                short type = rs.getShort("DATA_TYPE");
                String typeClsName = DataType.getTypeClassName(DataType.convertSQLTypeToValueType(type));
                short nullable = rs.getShort("NULLABLE");
                flds.add(new QueryField(name, typeClsName, nullable == 1));
            }
        }
    }
    Iterator<QueryField> it = flds.iterator();
    for (int i = flds.size() - cols.length; i > 0 && it.hasNext(); i--) it.next();
    for (QueryField exp : cols) {
        assertTrue("New column not found in metadata: " + exp.name(), it.hasNext());
        QueryField act = it.next();
        assertEquals(exp.name(), act.name());
        assertEquals(exp.typeName(), act.typeName());
        assertEquals(exp.isNullable(), act.isNullable());
    }
    return flds.size() - cols.length;
}
Also used : QueryField(org.apache.ignite.internal.processors.query.QueryField) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Aggregations

QueryField (org.apache.ignite.internal.processors.query.QueryField)21 Test (org.junit.Test)10 List (java.util.List)6 ArrayList (java.util.ArrayList)5 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 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 BinaryObject (org.apache.ignite.binary.BinaryObject)4 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)3 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 IgniteException (org.apache.ignite.IgniteException)2 QueryEntity (org.apache.ignite.cache.QueryEntity)2