Search in sources :

Example 1 with SqlPage

use of com.hazelcast.sql.impl.client.SqlPage in project hazelcast by hazelcast.

the class QueryClientStateRegistry method registerAndFetch.

public SqlPage registerAndFetch(UUID clientId, AbstractSqlResult result, int cursorBufferSize, InternalSerializationService serializationService) {
    QueryId queryId = result.getQueryId();
    QueryClientState clientCursor = new QueryClientState(clientId, queryId, result, false);
    boolean delete = false;
    try {
        // Register the cursor.
        QueryClientState previousClientCursor = clientCursors.putIfAbsent(queryId, clientCursor);
        // Check if the cursor is already closed.
        if (previousClientCursor != null) {
            assert previousClientCursor.isClosed();
            delete = true;
            QueryException error = QueryException.cancelledByUser();
            result.close(error);
            throw error;
        }
        // Fetch the next page.
        SqlPage page = fetchInternal(clientCursor, cursorBufferSize, serializationService, result.isInfiniteRows());
        delete = page.isLast();
        return page;
    } catch (Exception e) {
        delete = true;
        throw e;
    } finally {
        if (delete) {
            deleteClientCursor(queryId);
        }
    }
}
Also used : QueryException(com.hazelcast.sql.impl.QueryException) QueryId(com.hazelcast.sql.impl.QueryId) SqlPage(com.hazelcast.sql.impl.client.SqlPage) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) QueryException(com.hazelcast.sql.impl.QueryException)

Example 2 with SqlPage

use of com.hazelcast.sql.impl.client.SqlPage in project hazelcast by hazelcast.

the class SqlPageCodecTest method check.

private void check(SqlColumnType type, List<Object> values, boolean last) {
    SqlRowMetadata rowMetadata = new SqlRowMetadata(Collections.singletonList(new SqlColumnMetadata("a", type, true)));
    List<SqlRow> rows = new ArrayList<>();
    for (Object value : values) {
        if (SqlPage.convertToData(type) && value != null) {
            value = serializationService.toData(value);
        }
        rows.add(new SqlRowImpl(rowMetadata, new JetSqlRow(TEST_SS, new Object[] { value })));
    }
    SqlPage originalPage = SqlPage.fromRows(Collections.singletonList(type), rows, last, serializationService);
    ClientMessage message = ClientMessage.createForEncode();
    SqlPageCodec.encode(message, originalPage);
    SqlPage restoredPage = SqlPageCodec.decode(message.frameIterator());
    assertEquals(1, restoredPage.getColumnCount());
    assertEquals(values.size(), restoredPage.getRowCount());
    assertEquals(last, restoredPage.isLast());
    assertEquals(1, restoredPage.getColumnTypes().size());
    assertEquals(type, restoredPage.getColumnTypes().get(0));
    for (int i = 0; i < values.size(); i++) {
        Object value = values.get(i);
        Object restoredValue = restoredPage.getColumnValueForClient(0, i);
        if (restoredValue instanceof Data) {
            assertTrue(SqlPage.convertToData(type));
            restoredValue = serializationService.toObject(restoredValue);
        }
        assertEquals(value, restoredValue);
    }
}
Also used : JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) SqlRow(com.hazelcast.sql.SqlRow) SqlRowImpl(com.hazelcast.sql.impl.SqlRowImpl) ArrayList(java.util.ArrayList) Data(com.hazelcast.internal.serialization.Data) SqlRowMetadata(com.hazelcast.sql.SqlRowMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata) SqlPage(com.hazelcast.sql.impl.client.SqlPage)

Aggregations

SqlPage (com.hazelcast.sql.impl.client.SqlPage)2 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 Data (com.hazelcast.internal.serialization.Data)1 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)1 SqlColumnMetadata (com.hazelcast.sql.SqlColumnMetadata)1 SqlRow (com.hazelcast.sql.SqlRow)1 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)1 QueryException (com.hazelcast.sql.impl.QueryException)1 QueryId (com.hazelcast.sql.impl.QueryId)1 SqlRowImpl (com.hazelcast.sql.impl.SqlRowImpl)1 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)1 ArrayList (java.util.ArrayList)1