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);
}
}
}
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");
}
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]));
}
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));
}
}
Aggregations