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