Search in sources :

Example 56 with SqlResult

use of com.hazelcast.sql.SqlResult 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 57 with SqlResult

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

the class SqlTumbleTest method checkValidArguments.

private static void checkValidArguments(QueryDataTypeFamily orderingColumnType, String windowSize, Object[]... values) {
    String name = randomName();
    TestStreamSqlConnector.create(sqlService, name, singletonList("ts"), singletonList(orderingColumnType), values);
    try (SqlResult result = sqlService.execute("SELECT * FROM " + "TABLE(TUMBLE(TABLE " + name + ", DESCRIPTOR(ts), " + windowSize + "))")) {
        assertThat(result.getRowMetadata().findColumn("window_start")).isEqualTo(1);
        assertThat(result.getRowMetadata().getColumn(1).getType()).isEqualTo(orderingColumnType.getPublicType());
        assertThat(result.getRowMetadata().findColumn("window_end")).isEqualTo(2);
        assertThat(result.getRowMetadata().getColumn(2).getType()).isEqualTo(orderingColumnType.getPublicType());
        assertThat(result.iterator()).hasNext();
    }
}
Also used : SqlResult(com.hazelcast.sql.SqlResult)

Example 58 with SqlResult

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

the class SqlMetadataInJobConfigTest method test_dmlMetadata.

@Test
public void test_dmlMetadata() {
    createMapping("dest", Integer.class, Integer.class);
    TestBatchSqlConnector.create(instance().getSql(), "src", 1, true);
    String sql = "INSERT INTO dest SELECT v, v FROM src";
    Future<SqlResult> f = spawn(() -> instance().getSql().execute(sql));
    awaitSingleRunningJob(instance());
    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.FALSE, config.getArgument(KEY_SQL_UNBOUNDED));
}
Also used : 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)

Example 59 with SqlResult

use of com.hazelcast.sql.SqlResult 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)

Example 60 with SqlResult

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

the class SqlNullableColumnTest method testSelectWithNonNullSupport.

@Test
public void testSelectWithNonNullSupport() {
    createMapping("map", String.class, int.class);
    instance().getMap("map").put("key", 1);
    SqlResult result = instance().getSql().execute("SELECT __key, 1 FROM map");
    List<SqlColumnMetadata> columns = result.getRowMetadata().getColumns();
    assertEquals(columns.size(), 2);
    assertTrue(columns.get(0).isNullable());
    assertFalse(columns.get(1).isNullable());
}
Also used : SqlResult(com.hazelcast.sql.SqlResult) SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata) Test(org.junit.Test)

Aggregations

SqlResult (com.hazelcast.sql.SqlResult)60 Test (org.junit.Test)38 SqlRow (com.hazelcast.sql.SqlRow)31 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)23 QuickTest (com.hazelcast.test.annotation.QuickTest)23 SqlStatement (com.hazelcast.sql.SqlStatement)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 ArrayList (java.util.ArrayList)9 Job (com.hazelcast.jet.Job)8 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)8 SqlService (com.hazelcast.sql.SqlService)8 JobConfig (com.hazelcast.jet.config.JobConfig)7 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)6 HashMap (java.util.HashMap)5 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)4 List (java.util.List)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 TimeoutException (java.util.concurrent.TimeoutException)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 IndexConfig (com.hazelcast.config.IndexConfig)3