Search in sources :

Example 11 with SqlStatement

use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.

the class SqlErrorAbstractTest method checkTimeout.

protected void checkTimeout(boolean useClient) {
    // Start two instances and fill them with data
    instance1 = newHazelcastInstance(false);
    instance2 = newHazelcastInstance(true);
    client = newClient();
    // Execute query on the instance1.
    SqlStatement query = new SqlStatement("select v from table(generate_stream(1))").setTimeoutMillis(1L);
    HazelcastSqlException error = assertSqlException(useClient ? client : instance1, query);
    assertTrue(error.getMessage().contains("CANCEL_FORCEFUL"));
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Example 12 with SqlStatement

use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.

the class SqlErrorTest method testMemberLeaveDuringQueryAfterImmediateShutdown.

@Test
public void testMemberLeaveDuringQueryAfterImmediateShutdown() {
    // Start two instances
    instance1 = newHazelcastInstance(false);
    instance2 = newHazelcastInstance(true);
    SqlStatement streamingQuery = new SqlStatement("SELECT * FROM TABLE(GENERATE_STREAM(1000))");
    // Start query with immediate shutdown afterwards
    HazelcastSqlException error = assertSqlExceptionWithShutdown(instance1, streamingQuery);
    assertInstanceOf(HazelcastInstanceNotActiveException.class, findRootCause(error));
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with SqlStatement

use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.

the class SqlIndexAbstractTest method sqlKeys.

private Set<Integer> sqlKeys(boolean withIndex, String sql, List<Object> params) {
    SqlStatement query = new SqlStatement(sql);
    if (!params.isEmpty()) {
        query.setParameters(params);
    }
    Set<Integer> keys = new HashSet<>();
    try (SqlResult result = instance().getSql().execute(query)) {
        for (SqlRow row : result) {
            keys.add(row.getObject(0));
        }
    }
    return keys;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SqlRow(com.hazelcast.sql.SqlRow) SqlStatement(com.hazelcast.sql.SqlStatement) SqlResult(com.hazelcast.sql.SqlResult) HashSet(java.util.HashSet)

Example 14 with SqlStatement

use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.

the class SqlIndexCastTest method checkComparison.

private void checkComparison(ExpressionType<?> typeFrom, QueryDataTypeFamily typeTo, boolean expectedIndexUsage) {
    String sql = "SELECT field1 FROM " + MAP_NAME + " WHERE CAST(field1 AS " + typeTo + ") = CAST(? as " + typeTo + ")";
    SqlStatement statement = new SqlStatement(sql).addParameter(null);
    checkIndexUsage(statement, typeFrom, expectedIndexUsage);
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement)

Example 15 with SqlStatement

use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.

the class SqlIndexResolutionTest method checkIndexUsage.

private void checkIndexUsage(IMap<?, ?> map, boolean firstResolved, boolean secondResolved) {
    String field1Literal = toLiteral(type1, type1.valueFrom());
    String field2Literal = toLiteral(type2, type2.valueFrom());
    // The second component could be used if both components are resolved.
    Usage expectedUsage;
    if (firstResolved) {
        if (secondResolved) {
            // Both components were resolved
            expectedUsage = Usage.BOTH;
        } else {
            // Only one component is resolved
            if (composite && indexType == IndexType.HASH) {
                // Composite HASH index with the first component only cannot be used, because it requires range requests
                expectedUsage = Usage.NONE;
            } else {
                // Otherwise, used the first component
                expectedUsage = Usage.ONE;
            }
        }
    } else {
        // No components were resolved
        expectedUsage = Usage.NONE;
    }
    SqlStatement sql = new SqlStatement("SELECT * FROM " + map.getName() + " WHERE field1=" + field1Literal + " AND field2=" + field2Literal);
    checkIndexUsage(sql, map.getName(), expectedUsage);
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement)

Aggregations

SqlStatement (com.hazelcast.sql.SqlStatement)29 SqlResult (com.hazelcast.sql.SqlResult)14 Test (org.junit.Test)11 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 SqlRow (com.hazelcast.sql.SqlRow)8 ArrayList (java.util.ArrayList)6 Job (com.hazelcast.jet.Job)3 JobConfig (com.hazelcast.jet.config.JobConfig)3 SqlService (com.hazelcast.sql.SqlService)3 SqlServiceImpl (com.hazelcast.sql.impl.SqlServiceImpl)3 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)3 HazelcastException (com.hazelcast.core.HazelcastException)2 ArrayDeque (java.util.ArrayDeque)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 TimeoutException (java.util.concurrent.TimeoutException)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Data (com.hazelcast.internal.serialization.Data)1