Search in sources :

Example 21 with HazelcastSqlException

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

the class QueryUtils method toPublicException.

public static HazelcastSqlException toPublicException(Throwable e, @Nonnull UUID localMemberId) {
    if (e instanceof HazelcastSqlException) {
        return (HazelcastSqlException) e;
    }
    if (e instanceof QueryException) {
        QueryException e0 = (QueryException) e;
        UUID originatingMemberId = e0.getOriginatingMemberId();
        if (originatingMemberId == null) {
            originatingMemberId = localMemberId;
        }
        return new HazelcastSqlException(originatingMemberId, e0.getCode(), e0.getMessage(), e, e0.getSuggestion());
    } else {
        return new HazelcastSqlException(localMemberId, SqlErrorCode.GENERIC, e.getMessage(), e, null);
    }
}
Also used : UUID(java.util.UUID) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Example 22 with HazelcastSqlException

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

the class QueryClientStateRegistry method fetchInternal.

private SqlPage fetchInternal(QueryClientState clientCursor, int cursorBufferSize, InternalSerializationService serializationService, boolean respondImmediately) {
    List<SqlColumnMetadata> columns = clientCursor.getSqlResult().getRowMetadata().getColumns();
    List<SqlColumnType> columnTypes = new ArrayList<>(columns.size());
    for (SqlColumnMetadata column : columns) {
        columnTypes.add(column.getType());
    }
    if (respondImmediately) {
        return SqlPage.fromRows(columnTypes, Collections.emptyList(), false, serializationService);
    }
    ResultIterator<SqlRow> iterator = clientCursor.getIterator();
    try {
        List<SqlRow> rows = new ArrayList<>(cursorBufferSize);
        boolean last = fetchPage(iterator, rows, cursorBufferSize);
        return SqlPage.fromRows(columnTypes, rows, last, serializationService);
    } catch (HazelcastSqlException e) {
        // it happens, the cursor is already closed with the error, so we just re-throw.
        throw e;
    } catch (Exception e) {
        // Any other exception indicates that something has happened outside of the internal query state. For example,
        // we may fail to serialize a specific column value to Data. We have to close the cursor in this case.
        AbstractSqlResult result = clientCursor.getSqlResult();
        QueryException error = QueryException.error("Failed to prepare the SQL result for the client: " + e.getMessage(), e);
        result.close(error);
        throw error;
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) ArrayList(java.util.ArrayList) SqlColumnType(com.hazelcast.sql.SqlColumnType) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) QueryException(com.hazelcast.sql.impl.QueryException) QueryException(com.hazelcast.sql.impl.QueryException) AbstractSqlResult(com.hazelcast.sql.impl.AbstractSqlResult) SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Example 23 with HazelcastSqlException

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

the class SqlQueryResultTest method checkFailure.

private void checkFailure(HazelcastInstance target, String sql, SqlExpectedResultType type) {
    assert type == SqlExpectedResultType.ROWS || type == SqlExpectedResultType.UPDATE_COUNT : type;
    try (SqlResult result = target.getSql().execute(new SqlStatement(sql).setExpectedResultType(type))) {
        result.iterator().forEachRemaining(row -> {
        });
        fail("Must fail");
    } catch (HazelcastSqlException e) {
        String message = e.getMessage();
        if (type == SqlExpectedResultType.ROWS) {
            assertEquals(message, "The statement doesn't produce rows");
        } else {
            assertEquals(message, "The statement doesn't produce update count");
        }
    }
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement) SqlResult(com.hazelcast.sql.SqlResult) 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