Search in sources :

Example 16 with HazelcastSqlException

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

the class SqlErrorAbstractTest method checkDataTypeMismatch.

protected void checkDataTypeMismatch(boolean useClient) {
    // Start two instances and fill them with data
    instance1 = newHazelcastInstance(false);
    instance2 = newHazelcastInstance(true);
    client = newClient();
    IMap<Long, Object> map = instance1.getMap(MAP_NAME);
    createMapping(instance1, MAP_NAME, long.class, long.class);
    for (long i = 0; i < DATA_SET_SIZE; i++) {
        Object value = i == 0 ? Long.toString(i) : i;
        map.put(i, value);
    }
    // Execute query.
    HazelcastSqlException error = assertSqlException(useClient ? client : instance1, query());
    assertErrorCode(SqlErrorCode.DATA_EXCEPTION, error);
    assertTrue(error.getMessage().contains("Failed to extract map entry value because of type mismatch " + "[expectedClass=java.lang.Long, actualClass=java.lang.String]"));
}
Also used : HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Example 17 with HazelcastSqlException

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

the class SqlErrorAbstractTest method checkParsingError.

protected void checkParsingError(boolean useClient) {
    instance1 = newHazelcastInstance(true);
    client = newClient();
    createMapping(instance1, MAP_NAME, long.class, long.class);
    IMap<Long, Long> map = instance1.getMap(MAP_NAME);
    map.put(1L, 1L);
    HazelcastInstance target = useClient ? client : instance1;
    HazelcastSqlException error = assertSqlException(target, new SqlStatement("SELECT bad_field FROM " + MAP_NAME));
    assertErrorCode(SqlErrorCode.PARSING, error);
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Example 18 with HazelcastSqlException

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

the class SqlErrorAbstractTest method checkUserCancel.

@SuppressWarnings("StatementWithEmptyBody")
protected void checkUserCancel(boolean useClient) {
    instance1 = newHazelcastInstance(true);
    client = newClient();
    HazelcastInstance target = useClient ? client : instance1;
    try (SqlResult res = target.getSql().execute("select * from table(generate_stream(1))")) {
        sleepSeconds(1);
        res.close();
        try {
            for (SqlRow ignore : res) {
            // No-op.
            }
            fail("Exception is not thrown");
        } catch (HazelcastSqlException e) {
            assertErrorCode(SqlErrorCode.CANCELLED_BY_USER, e);
        }
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlResult(com.hazelcast.sql.SqlResult) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Example 19 with HazelcastSqlException

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

the class SqlErrorClientTest method testParameterError_serialization.

@Test
public void testParameterError_serialization() {
    instance1 = newHazelcastInstance(true);
    client = newClient();
    SqlStatement query = new SqlStatement("SELECT * FROM map").addParameter(new BadParameter(true, false));
    HazelcastSqlException error = assertSqlException(client, query);
    assertErrorCode(SqlErrorCode.GENERIC, error);
    assertTrue(error.getMessage().contains("Failed to serialize query parameter"));
}
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 20 with HazelcastSqlException

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

the class SqlClientService method handleFetchResponse.

private void handleFetchResponse(Connection connection, SqlClientResult res, ClientMessage message, Throwable error) {
    if (error != null) {
        res.onFetchFinished(null, rethrow(error, connection));
        return;
    }
    SqlFetchCodec.ResponseParameters responseParameters = SqlFetchCodec.decodeResponse(message);
    HazelcastSqlException responseError = handleResponseError(responseParameters.error);
    if (responseError != null) {
        res.onFetchFinished(null, responseError);
        return;
    }
    assert responseParameters.rowPage != null;
    res.onFetchFinished(responseParameters.rowPage, null);
}
Also used : SqlFetchCodec(com.hazelcast.client.impl.protocol.codec.SqlFetchCodec) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Aggregations

HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)23 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 SqlRow (com.hazelcast.sql.SqlRow)8 SqlStatement (com.hazelcast.sql.SqlStatement)7 SqlResult (com.hazelcast.sql.SqlResult)6 ArrayList (java.util.ArrayList)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 ExpressionBiValue (com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue)3 List (java.util.List)3 SqlColumnType (com.hazelcast.sql.SqlColumnType)2 QueryException (com.hazelcast.sql.impl.QueryException)2 SqlFetchCodec (com.hazelcast.client.impl.protocol.codec.SqlFetchCodec)1 Config (com.hazelcast.config.Config)1 IndexConfig (com.hazelcast.config.IndexConfig)1 IndexType (com.hazelcast.config.IndexType)1 MapConfig (com.hazelcast.config.MapConfig)1 IMap (com.hazelcast.map.IMap)1 SqlColumnMetadata (com.hazelcast.sql.SqlColumnMetadata)1