Search in sources :

Example 1 with SqlRow

use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.

the class BetweenOperatorIntegrationTest method executePossiblyFailingQuery.

/**
 * Execute a query and return either the result, or the exception it threw.
 */
protected Tuple2<List<SqlRow>, HazelcastSqlException> executePossiblyFailingQuery(String sql, SqlColumnType firstColumnExpectedType, Object... params) {
    try {
        SqlResult result = instance().getSql().execute(sql, params);
        List<SqlRow> rows = new ArrayList<>();
        for (SqlRow row : result) {
            assertEquals(firstColumnExpectedType, row.getMetadata().getColumn(0).getType());
            rows.add(row);
        }
        return tuple2(rows, null);
    } catch (HazelcastSqlException e) {
        return tuple2(Collections.emptyList(), e);
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) ArrayList(java.util.ArrayList) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Example 2 with SqlRow

use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.

the class IsNullPredicateIntegrationTest method checkLiteral.

private void checkLiteral(String literal, String function, boolean expectedResult) {
    String expression = literal + " " + function;
    String sql = "SELECT " + expression + " FROM map WHERE " + expression;
    List<SqlRow> rows = execute(sql);
    if (expectedResult) {
        assertEquals(1, rows.size());
        SqlRow row = rows.get(0);
        assertEquals(SqlColumnType.BOOLEAN, row.getMetadata().getColumn(0).getType());
        assertTrue(row.getObject(0));
    } else {
        assertEquals(0, rows.size());
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow)

Example 3 with SqlRow

use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.

the class IsTrueFalsePredicateIntegrationTest method keys.

private Set<Integer> keys(String sql, Object... params) {
    List<SqlRow> rows = execute(sql, params);
    if (rows.size() == 0) {
        return Collections.emptySet();
    }
    assertEquals(1, rows.get(0).getMetadata().getColumnCount());
    Set<Integer> keys = new HashSet<>();
    for (SqlRow row : rows) {
        int key = row.getObject(0);
        boolean added = keys.add(key);
        assertTrue("Key is not unique: " + key, added);
    }
    return keys;
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) BigInteger(java.math.BigInteger) HashSet(java.util.HashSet)

Example 4 with SqlRow

use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.

the class IsTrueFalsePredicateIntegrationTest method checkLiteral.

private void checkLiteral(String literal, String function, boolean expectedResult) {
    String expression = literal + " " + function;
    String sql = "SELECT " + expression + " FROM map WHERE " + expression;
    List<SqlRow> rows = execute(sql);
    if (expectedResult) {
        assertEquals(1, rows.size());
        SqlRow row = rows.get(0);
        assertEquals(SqlColumnType.BOOLEAN, row.getMetadata().getColumn(0).getType());
        assertTrue(row.getObject(0));
    } else {
        assertEquals(0, rows.size());
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow)

Example 5 with SqlRow

use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.

the class IsTrueFalsePredicateIntegrationTest method checkColumn.

private void checkColumn(String function, Set<Integer> expectedKeys) {
    String expression = "field1 " + function;
    String sql = "SELECT key, " + expression + " FROM map WHERE " + expression;
    List<SqlRow> rows = execute(sql);
    assertEquals(expectedKeys.size(), rows.size());
    for (SqlRow row : rows) {
        assertEquals(SqlColumnType.BOOLEAN, row.getMetadata().getColumn(1).getType());
        int key = row.getObject(0);
        boolean value = row.getObject(1);
        assertTrue("Key is not returned: " + key, expectedKeys.contains(key));
        assertTrue(value);
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow)

Aggregations

SqlRow (com.hazelcast.sql.SqlRow)65 Test (org.junit.Test)35 SqlResult (com.hazelcast.sql.SqlResult)29 QuickTest (com.hazelcast.test.annotation.QuickTest)25 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)17 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)13 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)11 ArrayList (java.util.ArrayList)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 SqlStatement (com.hazelcast.sql.SqlStatement)7 SqlService (com.hazelcast.sql.SqlService)5 HashSet (java.util.HashSet)5 SqlColumnType (com.hazelcast.sql.SqlColumnType)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 Config (com.hazelcast.config.Config)2 IndexConfig (com.hazelcast.config.IndexConfig)2 HazelcastException (com.hazelcast.core.HazelcastException)2 ExpressionBiValue (com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue)2 IMap (com.hazelcast.map.IMap)2 SqlColumnMetadata (com.hazelcast.sql.SqlColumnMetadata)2