Search in sources :

Example 36 with SqlRow

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

the class BetweenOperatorIntegrationTest method checkValues.

protected void checkValues(String sql, SqlColumnType expectedType, Object[] expectedResults, Object... params) {
    List<SqlRow> rows = execute(sql, params);
    assertEquals(expectedResults.length, rows.size());
    if (rows.size() == 0) {
        return;
    }
    if (rows.get(0).getObject(0) instanceof Integer) {
        rows.sort(Comparator.comparingInt(a -> a.getObject(0)));
    } else if (rows.get(0).getObject(0) instanceof Comparable) {
        rows.sort((a, b) -> ((Comparable<?>) a.getObject(0)).compareTo(b.getObject(0)));
    }
    for (int i = 0; i < expectedResults.length; i++) {
        SqlRow row = rows.get(i);
        assertEquals(expectedType, row.getMetadata().getColumn(0).getType());
        assertEquals(expectedResults[i], row.getObject(0));
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) INTEGER(com.hazelcast.sql.SqlColumnType.INTEGER) TIME(com.hazelcast.sql.SqlColumnType.TIME) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) LocalDateTime(java.time.LocalDateTime) DOUBLE(com.hazelcast.sql.SqlColumnType.DOUBLE) ExpressionBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) ArrayList(java.util.ArrayList) ExpressionTypes(com.hazelcast.jet.sql.impl.support.expressions.ExpressionTypes) LocalTime(java.time.LocalTime) VARCHAR(com.hazelcast.sql.SqlColumnType.VARCHAR) Tuple2(com.hazelcast.jet.datamodel.Tuple2) SqlRow(com.hazelcast.sql.SqlRow) SqlColumnType(com.hazelcast.sql.SqlColumnType) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) OBJECT(com.hazelcast.sql.SqlColumnType.OBJECT) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) BIGINT(com.hazelcast.sql.SqlColumnType.BIGINT) Category(org.junit.experimental.categories.Category) Serializable(java.io.Serializable) ExpressionTestSupport(com.hazelcast.jet.sql.impl.expression.ExpressionTestSupport) List(java.util.List) Tuple2.tuple2(com.hazelcast.jet.datamodel.Tuple2.tuple2) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) LocalDate(java.time.LocalDate) SqlResult(com.hazelcast.sql.SqlResult) ExpressionType(com.hazelcast.jet.sql.impl.support.expressions.ExpressionType) Comparator(java.util.Comparator) DATE(com.hazelcast.sql.SqlColumnType.DATE) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals)

Example 37 with SqlRow

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

the class IsNullPredicateIntegrationTest 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) HashSet(java.util.HashSet)

Example 38 with SqlRow

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

the class RandFunctionIntegrationTest method testMultipleCallsInSingleQuery.

@Test
public void testMultipleCallsInSingleQuery() {
    putAll(0, 1, 2, 3);
    List<SqlRow> rows = execute("SELECT RAND(), RAND() FROM map");
    assertEquals(4, rows.size());
    Set<Double> values = new HashSet<>();
    for (SqlRow row : rows) {
        double value1 = row.getObject(0);
        double value2 = row.getObject(1);
        assertNotEquals(value1, value2);
        values.add(value1);
    }
    assertTrue(values.size() > 1);
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 39 with SqlRow

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

the class ExpressionTestSupport method checkValues0.

/**
 * Execute a query, assert that it returns only 1 column and the values match the expectedResults array
 * in any order. Assert the type and count of the results.
 *
 * @param sql             the input query
 * @param expectedType    type of the returned value
 * @param expectedResults expected result value. If it's {@link #SKIP_VALUE_CHECK},
 *                        don't assert the value
 * @param params          query parameters
 */
protected void checkValues0(String sql, SqlColumnType expectedType, Object[] expectedResults, Object... params) {
    List<SqlRow> rows = execute(sql, params);
    int expectedResultCount = expectedResults.length;
    assertEquals(expectedResultCount, rows.size());
    Object[] values = new Object[expectedResultCount];
    for (int i = 0; i < expectedResultCount; i++) {
        SqlRow row = rows.get(i);
        assertEquals(1, row.getMetadata().getColumnCount());
        assertEquals(expectedType, row.getMetadata().getColumn(0).getType());
        Object value = row.getObject(0);
        values[i] = value;
    }
    assertThat(values).containsExactlyInAnyOrderElementsOf(Arrays.asList(expectedResults));
}
Also used : SqlRow(com.hazelcast.sql.SqlRow)

Example 40 with SqlRow

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

the class ExpressionTestSupport method checkValue0.

/**
 * Execute a query, assert that it returns exactly 1 row and 1 column. Assert
 * the type of the result and optionally the result value.
 *
 * @param sql            the input query
 * @param expectedType   type of the returned value
 * @param expectedResult expected result value. If it's {@link #SKIP_VALUE_CHECK},
 *                       don't assert the value
 * @param params         query parameters
 * @return the result value
 */
protected Object checkValue0(String sql, SqlColumnType expectedType, Object expectedResult, Object... params) {
    List<SqlRow> rows = execute(sql, params);
    assertEquals(1, rows.size());
    SqlRow row = rows.get(0);
    assertEquals(1, row.getMetadata().getColumnCount());
    assertEquals(expectedType, row.getMetadata().getColumn(0).getType());
    Object value = row.getObject(0);
    if (expectedResult != SKIP_VALUE_CHECK) {
        assertEquals(expectedResult, value);
    }
    return 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