use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlTestSupport method assertTipOfStream.
/**
* Execute the given `sql` and assert that the first rows it returns are those in
* `expectedRows`. Ignores the rest of rows.
* <p>
* This is useful for asserting initial output of streaming queries where
* the output arrives in a stable order.
*/
public static void assertTipOfStream(String sql, Collection<Row> expectedRows) {
assert !expectedRows.isEmpty() : "no point in asserting a zero-length tip of a stream";
SqlService sqlService = instance().getSql();
CompletableFuture<Void> future = new CompletableFuture<>();
Deque<Row> rows = new ArrayDeque<>();
Thread thread = new Thread(() -> {
SqlStatement statement = new SqlStatement(sql);
try (SqlResult result = sqlService.execute(statement)) {
Iterator<SqlRow> iterator = result.iterator();
for (int i = 0; i < expectedRows.size() && iterator.hasNext(); i++) {
rows.add(new Row(iterator.next()));
}
future.complete(null);
} catch (Throwable e) {
e.printStackTrace();
future.completeExceptionally(e);
}
});
thread.start();
try {
try {
future.get(10, TimeUnit.SECONDS);
} catch (TimeoutException e) {
thread.interrupt();
thread.join();
}
} catch (Exception e) {
throw sneakyThrow(e);
}
List<Row> actualRows = new ArrayList<>(rows);
assertThat(actualRows).containsExactlyElementsOf(expectedRows);
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SelectWithoutFromStatementTest method when_multipleColumnsSelected_returnCorrectResult.
@Test
public void when_multipleColumnsSelected_returnCorrectResult() {
final SqlRow row = execute("SELECT 1 as A, 'B' as B");
assertEquals(SqlColumnType.TINYINT, row.getMetadata().getColumn(0).getType());
assertEquals(SqlColumnType.VARCHAR, row.getMetadata().getColumn(1).getType());
assertEquals((byte) 1, (byte) row.getObject("A"));
assertEquals("B", row.getObject("B"));
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SelectWithoutFromStatementTest method checkWithType.
private void checkWithType(String sql, SqlColumnType type, Object expected) {
final SqlRow row = execute(sql);
assertEquals(1, row.getMetadata().getColumnCount());
assertEquals(type, row.getMetadata().getColumn(0).getType());
assertEquals(expected, row.getObject(0));
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlQueryResultTest method check.
private void check(boolean client) {
HazelcastInstance member = instance();
HazelcastInstance target = client ? client() : instance();
createMapping(MAP_NAME, int.class, int.class);
member.getMap(MAP_NAME).put(1, 1);
// Check rows
List<SqlRow> expectedRows = execute(SQL_READ);
assertEquals(1, expectedRows.size());
checkSuccess(target, SQL_READ, SqlExpectedResultType.ANY, expectedRows, -1);
checkSuccess(target, SQL_READ, SqlExpectedResultType.ROWS, expectedRows, -1);
checkFailure(target, SQL_READ, SqlExpectedResultType.UPDATE_COUNT);
// Check update count
// TODO: implement updateCount for DML and single key plans.
checkSuccess(target, SQL_DELETE, SqlExpectedResultType.ANY, emptyList(), 0);
checkFailure(target, SQL_DELETE, SqlExpectedResultType.ROWS);
checkSuccess(target, SQL_DELETE, SqlExpectedResultType.UPDATE_COUNT, emptyList(), 0);
}
use of com.hazelcast.sql.SqlRow 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);
}
}
}
Aggregations