Search in sources :

Example 11 with SqlColumnType

use of com.hazelcast.sql.SqlColumnType 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 12 with SqlColumnType

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

the class HazelcastCastFunction method checkOperandTypes.

@Override
public boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure) {
    RelDataType sourceType = binding.getOperandType(0);
    RelDataType targetType = binding.getOperandType(1);
    SqlNode sourceOperand = binding.operand(0);
    if (sourceOperand.getKind() == SqlKind.DYNAMIC_PARAM) {
        int sourceParameterIndex = ((SqlDynamicParam) sourceOperand).getIndex();
        binding.getValidator().setParameterConverter(sourceParameterIndex, NoOpParameterConverter.INSTANCE);
    }
    if (canCast(sourceType, targetType)) {
        return true;
    }
    if (throwOnFailure) {
        SqlColumnType sourceType0 = toHazelcastType(sourceType).getTypeFamily().getPublicType();
        SqlColumnType targetType0 = toHazelcastType(targetType).getTypeFamily().getPublicType();
        throw binding.newError(HazelcastResources.RESOURCES.cannotCastValue(sourceType0.toString(), targetType0.toString()));
    } else {
        return false;
    }
}
Also used : SqlDynamicParam(org.apache.calcite.sql.SqlDynamicParam) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlColumnType(com.hazelcast.sql.SqlColumnType) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

SqlColumnType (com.hazelcast.sql.SqlColumnType)12 SqlColumnMetadata (com.hazelcast.sql.SqlColumnMetadata)4 ArrayList (java.util.ArrayList)4 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)3 SqlRow (com.hazelcast.sql.SqlRow)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)2 ExpressionType (com.hazelcast.jet.sql.impl.support.expressions.ExpressionType)2 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2 LocalTime (java.time.LocalTime)2 List (java.util.List)2 HazelcastJsonValueCodec (com.hazelcast.client.impl.protocol.codec.custom.HazelcastJsonValueCodec)1 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)1 Data (com.hazelcast.internal.serialization.Data)1 Tuple2 (com.hazelcast.jet.datamodel.Tuple2)1 Tuple2.tuple2 (com.hazelcast.jet.datamodel.Tuple2.tuple2)1 ExpressionTestSupport (com.hazelcast.jet.sql.impl.expression.ExpressionTestSupport)1