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);
}
}
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;
}
}
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");
}
}
}
Aggregations