Search in sources :

Example 41 with SqlResult

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlResult(com.hazelcast.sql.SqlResult) EmployeeDTO(example.serialization.EmployeeDTO) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with SqlResult

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlResult(com.hazelcast.sql.SqlResult) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 43 with SqlResult

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));
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlResult(com.hazelcast.sql.SqlResult) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with SqlResult

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());
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlResult(com.hazelcast.sql.SqlResult) SqlService(com.hazelcast.sql.SqlService) BitSet(java.util.BitSet) Test(org.junit.Test)

Example 45 with SqlResult

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()));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlService(com.hazelcast.sql.SqlService) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) BeforeClass(org.junit.BeforeClass) Collection(java.util.Collection) Test(org.junit.Test) HashMap(java.util.HashMap) TestBatchSqlConnector(com.hazelcast.jet.sql.impl.connector.test.TestBatchSqlConnector) Collectors(java.util.stream.Collectors) ConcurrentMap(java.util.concurrent.ConcurrentMap) TestFailingSqlConnector(com.hazelcast.jet.sql.impl.connector.test.TestFailingSqlConnector) Util.idToString(com.hazelcast.jet.Util.idToString) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) SqlResult(com.hazelcast.sql.SqlResult) FAILED(com.hazelcast.jet.core.JobStatus.FAILED) BitSet(java.util.BitSet) SqlRow(com.hazelcast.sql.SqlRow) Assert.assertEquals(org.junit.Assert.assertEquals) Job(com.hazelcast.jet.Job) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) IMap(com.hazelcast.map.IMap) SqlResult(com.hazelcast.sql.SqlResult) HashMap(java.util.HashMap) Util.idToString(com.hazelcast.jet.Util.idToString) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) SqlService(com.hazelcast.sql.SqlService) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) Test(org.junit.Test)

Aggregations

SqlResult (com.hazelcast.sql.SqlResult)60 Test (org.junit.Test)38 SqlRow (com.hazelcast.sql.SqlRow)31 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)23 QuickTest (com.hazelcast.test.annotation.QuickTest)23 SqlStatement (com.hazelcast.sql.SqlStatement)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 ArrayList (java.util.ArrayList)9 Job (com.hazelcast.jet.Job)8 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)8 SqlService (com.hazelcast.sql.SqlService)8 JobConfig (com.hazelcast.jet.config.JobConfig)7 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)6 HashMap (java.util.HashMap)5 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)4 List (java.util.List)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 TimeoutException (java.util.concurrent.TimeoutException)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 IndexConfig (com.hazelcast.config.IndexConfig)3