Search in sources :

Example 26 with SqlStatement

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

the class SqlQueryResultTest method checkSuccess.

private void checkSuccess(HazelcastInstance target, String sql, SqlExpectedResultType type, List<SqlRow> expectedRows, int expectedUpdateCount) {
    SqlResult result = target.getSql().execute(new SqlStatement(sql).setExpectedResultType(type));
    assertEquals(expectedUpdateCount, result.updateCount());
    if (expectedUpdateCount >= 0) {
        return;
    }
    List<SqlRow> rows = new ArrayList<>();
    for (SqlRow row : result) {
        rows.add(row);
    }
    assertEquals(expectedRows.size(), rows.size());
    for (int i = 0; i < expectedRows.size(); i++) {
        SqlRow expectedRow = expectedRows.get(i);
        SqlRow row = rows.get(i);
        assertEquals(expectedRow.getMetadata(), row.getMetadata());
        for (int j = 0; j < expectedRow.getMetadata().getColumnCount(); j++) {
            Object expectedValue = expectedRow.getObject(j);
            Object value = row.getObject(j);
            assertEquals(expectedValue, value);
        }
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlStatement(com.hazelcast.sql.SqlStatement) SqlResult(com.hazelcast.sql.SqlResult) ArrayList(java.util.ArrayList)

Example 27 with SqlStatement

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

the class SqlLimitTest method limitWithNullDynamicParameter.

@Test
public void limitWithNullDynamicParameter() {
    SqlStatement statement = new SqlStatement("SELECT * FROM TABLE(GENERATE_STREAM(5)) LIMIT ?");
    statement.setParameters(singletonList(null));
    assertThatThrownBy(() -> sqlService.execute(statement).iterator().next()).isInstanceOf(HazelcastSqlException.class).hasMessageContaining("LIMIT value cannot be null");
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) Test(org.junit.Test)

Example 28 with SqlStatement

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

the class SqlLimitTest method assertContainsSubsetOfRows.

/**
 * Asserts that the result of {@code sql} contains a subset of {@code
 * expectedRows}, the subset must be of size {@code subsetSize}.
 */
private static void assertContainsSubsetOfRows(String sql, List<Object> arguments, int subsetSize, Collection<Row> expectedRows) {
    List<Row> actualRows = new ArrayList<>();
    SqlStatement statement = new SqlStatement(sql);
    statement.setParameters(arguments);
    sqlService.execute(statement).iterator().forEachRemaining(sqlRow -> {
        int columnCount = sqlRow.getMetadata().getColumnCount();
        Object[] values = new Object[columnCount];
        for (int i = 0; i < columnCount; i++) {
            values[i] = sqlRow.getObject(i);
        }
        actualRows.add(new Row(values));
    });
    assertThat(actualRows).hasSize(subsetSize).containsAnyOf(expectedRows.toArray(new Row[subsetSize]));
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement) ArrayList(java.util.ArrayList)

Example 29 with SqlStatement

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

the class SqlMetadataInJobConfigTest method test_selectMetadata_member.

@Test
public void test_selectMetadata_member() {
    String sql = "SELECT * FROM table(generate_stream(1))";
    try (SqlResult ignored = client().getSql().execute(new SqlStatement(sql).setCursorBufferSize(1))) {
        List<Job> runningJobs = getJobsByStatus(RUNNING);
        assertEquals(1, runningJobs.size());
        JobConfig config = runningJobs.get(0).getConfig();
        assertEquals(sql, config.getArgument(KEY_SQL_QUERY_TEXT));
        assertEquals(Boolean.TRUE, config.getArgument(KEY_SQL_UNBOUNDED));
    }
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement) SqlResult(com.hazelcast.sql.SqlResult) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SqlStatement (com.hazelcast.sql.SqlStatement)29 SqlResult (com.hazelcast.sql.SqlResult)14 Test (org.junit.Test)11 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 SqlRow (com.hazelcast.sql.SqlRow)8 ArrayList (java.util.ArrayList)6 Job (com.hazelcast.jet.Job)3 JobConfig (com.hazelcast.jet.config.JobConfig)3 SqlService (com.hazelcast.sql.SqlService)3 SqlServiceImpl (com.hazelcast.sql.impl.SqlServiceImpl)3 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)3 HazelcastException (com.hazelcast.core.HazelcastException)2 ArrayDeque (java.util.ArrayDeque)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 TimeoutException (java.util.concurrent.TimeoutException)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Data (com.hazelcast.internal.serialization.Data)1