use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientCompactQueryTest method testQueryOnPrimitive_selectValue.
@Test
public void testQueryOnPrimitive_selectValue() {
HazelcastInstance client = factory.newHazelcastClient(clientConfig());
IMap<Integer, Object> map = client.getMap("test");
for (int i = 0; i < 10; i++) {
map.put(i, new EmployeeDTO(i, i));
}
client.getSql().execute("CREATE MAPPING " + "test" + '(' + "__key INTEGER" + ", age INTEGER" + ", \"rank\" INTEGER" + ", id BIGINT" + ", isHired BOOLEAN" + ", isFired BOOLEAN" + ") TYPE " + IMapSqlConnector.TYPE_NAME + ' ' + "OPTIONS (" + '\'' + OPTION_KEY_FORMAT + "'='int'" + ", '" + OPTION_VALUE_FORMAT + "'='" + COMPACT_FORMAT + '\'' + ", '" + OPTION_VALUE_COMPACT_TYPE_NAME + "'='" + EmployeeDTO.class.getName() + '\'' + ")");
SqlResult result = client.getSql().execute("SELECT this FROM test WHERE age >= 5");
assertThat(result).hasSize(5);
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientPortableQueryTest method testQueryOnPrimitive.
@Test
public void testQueryOnPrimitive() {
ClientConfig clientConfig = new ClientConfig();
clientConfig.getSerializationConfig().addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory());
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
createMapping(client, "test", int.class, PORTABLE_FACTORY_ID, PORTABLE_CHILD_CLASS_ID, 0);
IMap<Integer, Object> map = client.getMap("test");
fillMap(map, 50, ChildPortable::new);
SqlResult result = client.getSql().execute("SELECT * FROM test WHERE i >= 45");
assertThat(result).hasSize(5);
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientPortableQueryTest method testNestedPortableAsColumn.
@Test
public void testNestedPortableAsColumn() {
ClientConfig clientConfig = new ClientConfig();
clientConfig.getSerializationConfig().addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory());
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
createMapping(client, "test", int.class, PORTABLE_FACTORY_ID, PORTABLE_PARENT_CLASS_ID, 0);
IMap<Integer, ParentPortable> map = client.getMap("test");
fillMap(map, 100, ParentPortable::new);
SqlResult result = client.getSql().execute("SELECT id, child FROM test WHERE id = ? ", 1);
SqlRow row = Iterators.getOnlyElement(result.iterator());
assertEquals((Integer) 1, row.getObject(0));
assertEquals(new ChildPortable(1), row.getObject(1));
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientTest method test_jetJobReturnRowsToClientFrom.
@Test
public void test_jetJobReturnRowsToClientFrom() {
HazelcastInstance client = factory().newHazelcastClient();
SqlService sqlService = client.getSql();
int itemCount = 10_000;
TestBatchSqlConnector.create(sqlService, "t", itemCount);
SqlResult result = sqlService.execute("SELECT v FROM t");
BitSet seenValues = new BitSet(itemCount);
for (SqlRow r : result) {
Integer v = r.getObject(0);
assertFalse("value already seen: " + v, seenValues.get(v));
seenValues.set(v);
}
assertEquals(itemCount, seenValues.cardinality());
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientTest method when_resultClosed_then_executionContextCleanedUp.
// test for https://github.com/hazelcast/hazelcast/issues/19897
@Test
public void when_resultClosed_then_executionContextCleanedUp() {
HazelcastInstance client = factory().newHazelcastClient();
SqlService sql = client.getSql();
IMap<Integer, Integer> map = instance().getMap("map");
Map<Integer, Integer> tmpMap = new HashMap<>();
for (int i = 0; i < 100_000; i++) {
tmpMap.put(i, i);
if (i % 10_000 == 0) {
map.putAll(tmpMap);
tmpMap.clear();
}
}
createMapping("map", Integer.class, Integer.class);
for (int i = 0; i < 100; i++) {
SqlResult result = sql.execute("SELECT * FROM map");
result.close();
}
JetServiceBackend jetService = getJetServiceBackend(instance());
Collection<ExecutionContext> contexts = jetService.getJobExecutionService().getExecutionContexts();
// Assert that all ExecutionContexts are eventually cleaned up
// This assert will fail if a network packet arrives after the JobExecutionService#FAILED_EXECUTION_EXPIRY_NS
// time. Hopefully Jenkins isn't that slow.
assertTrueEventually(() -> {
String remainingContexts = contexts.stream().map(c -> idToString(c.executionId())).collect(Collectors.joining(", "));
assertEquals("remaining execIds: " + remainingContexts, 0, contexts.size());
}, 5);
// assert that failedJobs is also cleaned up
ConcurrentMap<Long, Long> failedJobs = jetService.getJobExecutionService().getFailedJobs();
assertTrueEventually(() -> assertEquals(0, failedJobs.size()));
}
Aggregations