use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class PlanExecutor method execute.
SqlResult execute(ShowStatementPlan plan) {
Stream<String> rows;
switch(plan.getShowTarget()) {
case MAPPINGS:
rows = catalog.getMappingNames().stream();
break;
case VIEWS:
rows = catalog.getViewNames().stream();
break;
case JOBS:
assert plan.getShowTarget() == ShowStatementTarget.JOBS;
NodeEngine nodeEngine = getNodeEngine(hazelcastInstance);
JetServiceBackend jetServiceBackend = nodeEngine.getService(JetServiceBackend.SERVICE_NAME);
rows = jetServiceBackend.getJobRepository().getJobRecords().stream().map(record -> record.getConfig().getName()).filter(Objects::nonNull);
break;
default:
throw new AssertionError("Unsupported SHOW statement target.");
}
SqlRowMetadata metadata = new SqlRowMetadata(singletonList(new SqlColumnMetadata("name", VARCHAR, false)));
InternalSerializationService serializationService = Util.getSerializationService(hazelcastInstance);
return new SqlResultImpl(QueryId.create(hazelcastInstance.getLocalEndpoint().getUuid()), new StaticQueryResultProducerImpl(rows.sorted().map(name -> new JetSqlRow(serializationService, new Object[] { name })).iterator()), metadata, false);
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlHopTest method checkValidArguments.
private static void checkValidArguments(QueryDataTypeFamily orderingColumnType, String size, Object[]... values) {
String name = randomName();
TestStreamSqlConnector.create(sqlService, name, singletonList("ts"), singletonList(orderingColumnType), values);
try (SqlResult result = sqlService.execute("SELECT * FROM " + "TABLE(HOP(TABLE " + name + ", DESCRIPTOR(ts), " + size + ", " + size + "))")) {
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();
}
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class BetweenOperatorIntegrationTest method executePossiblyFailingQuery.
/**
* Execute a query and return either the result, or the exception it threw.
*/
protected Tuple2<List<SqlRow>, HazelcastSqlException> executePossiblyFailingQuery(String sql, SqlColumnType firstColumnExpectedType, Object... params) {
try {
SqlResult result = instance().getSql().execute(sql, params);
List<SqlRow> rows = new ArrayList<>();
for (SqlRow row : result) {
assertEquals(firstColumnExpectedType, row.getMetadata().getColumn(0).getType());
rows.add(row);
}
return tuple2(rows, null);
} catch (HazelcastSqlException e) {
return tuple2(Collections.emptyList(), e);
}
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class QueryClientStateRegistry method close0.
private void close0(QueryClientState clientCursor) {
SqlResult result = clientCursor.getSqlResult();
if (result != null) {
result.close();
}
deleteClientCursor(clientCursor.getQueryId());
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlMetadataInJobConfigTest method test_selectMetadata_client.
@Test
public void test_selectMetadata_client() {
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