use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlTestSupport method assertEmptyResultStream.
/**
* Runs a streaming query and checks that for a hard-coded time it
* doesn't return any results.
*/
public static void assertEmptyResultStream(String sql) {
Future<Boolean> future;
try (SqlResult result = instance().getSql().execute(sql)) {
future = spawn(() -> result.iterator().hasNext());
assertTrueAllTheTime(() -> assertFalse(future.isDone()), 2);
}
assertTrueEventually(() -> assertTrue(future.isDone()));
}
use of com.hazelcast.sql.SqlResult 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.SqlResult in project hazelcast by hazelcast.
the class ExplainStatementTest method test_explainStatementDynamicParams.
@Test
public void test_explainStatementDynamicParams() {
IMap<Integer, Integer> map = instance().getMap("map");
map.put(1, 10);
createMapping("map", Integer.class, Integer.class);
String sql = "EXPLAIN SELECT * FROM map WHERE __key = ?";
SqlStatement statement = new SqlStatement(sql).addParameter(1);
SqlResult result = instance().getSql().execute(statement);
String expectedScanRes = "SelectByKeyMapPhysicalRel(table=[[hazelcast, public, map[projects=[$0, $1], " + "filter==($0, ?0)]]], keyCondition=[?0], projections=[__key=[$0], this=[$1]])";
assertEquals(result.iterator().next().getObject(0), expectedScanRes);
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class PlanExecutorTest method test_insertExecution.
@Test
public void test_insertExecution() {
// given
QueryId queryId = QueryId.create(UuidUtil.newSecureUUID());
DmlPlan plan = new DmlPlan(Operation.INSERT, planKey(), QueryParameterMetadata.EMPTY, emptySet(), dag, null, false, planExecutor, Collections.emptyList());
given(hazelcastInstance.getJet()).willReturn(jet);
given(jet.newLightJob(eq(dag), isA(JobConfig.class))).willReturn(job);
// when
SqlResult result = planExecutor.execute(plan, queryId, emptyList(), 0L);
// then
assertThat(result.updateCount()).isEqualTo(0);
verify(job).join();
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlQueryResultTest method checkFailure.
private void checkFailure(HazelcastInstance target, String sql, SqlExpectedResultType type) {
assert type == SqlExpectedResultType.ROWS || type == SqlExpectedResultType.UPDATE_COUNT : type;
try (SqlResult result = target.getSql().execute(new SqlStatement(sql).setExpectedResultType(type))) {
result.iterator().forEachRemaining(row -> {
});
fail("Must fail");
} catch (HazelcastSqlException e) {
String message = e.getMessage();
if (type == SqlExpectedResultType.ROWS) {
assertEquals(message, "The statement doesn't produce rows");
} else {
assertEquals(message, "The statement doesn't produce update count");
}
}
}
Aggregations