use of com.hazelcast.sql.SqlRow 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);
}
}
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlClientResultTest method when_checkingHasNextWithTimeout_then_timeoutOccurs.
@Test
public void when_checkingHasNextWithTimeout_then_timeoutOccurs() {
try (SqlResult result = execute("select * from table(generate_stream(1))")) {
assertTrue(result.isRowSet());
ResultIterator<SqlRow> iterator = (ResultIterator<SqlRow>) result.iterator();
int timeoutCount = 0;
for (int i = 0; i < 2; i++) {
while (iterator.hasNext(10, TimeUnit.MILLISECONDS) == ResultIterator.HasNextResult.TIMEOUT) {
timeoutCount++;
}
iterator.next();
}
assertNotEquals(0, timeoutCount);
}
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlClientResultTest method when_executingValidQuery.
@Test
public void when_executingValidQuery() {
try (SqlResult result = execute("SELECT * FROM " + MAP_NAME)) {
assertEquals(2, result.getRowMetadata().getColumnCount());
assertEquals(-1, result.updateCount());
assertTrue(result.isRowSet());
Iterator<SqlRow> iterator = result.iterator();
iterator.next();
iterator.next();
assertFalse(iterator.hasNext());
checkIllegalStateException(result::iterator, "Iterator can be requested only once");
}
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlErrorClientTest method testRowError_deserialization.
@Test
public void testRowError_deserialization() {
try {
instance1 = newHazelcastInstance(true);
client = newClient();
Map<Integer, BadValue> localMap = new HashMap<>();
IMap<Integer, BadValue> map = instance1.getMap(MAP_NAME);
createMapping(instance1, MAP_NAME, int.class, BadValue.class);
for (int i = 0; i < DEFAULT_CURSOR_BUFFER_SIZE + 1; i++) {
localMap.put(i, new BadValue());
}
map.putAll(localMap);
try (SqlResult result = client.getSql().execute("SELECT __key, this FROM " + MAP_NAME)) {
Iterator<SqlRow> iterator = result.iterator();
SqlRow firstRow = iterator.next();
firstRow.getObject("__key");
firstRow.getObject("this");
BadValue.READ_ERROR.set(true);
SqlRow secondRow = iterator.next();
secondRow.getObject("__key");
assertThatThrownBy(() -> secondRow.getObject("this")).isInstanceOf(HazelcastSerializationException.class).hasMessageContaining("Failed to deserialize query result value");
}
} finally {
BadValue.READ_ERROR.set(false);
}
}
use of com.hazelcast.sql.SqlRow 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;
}
}
Aggregations