use of com.hazelcast.sql.SqlColumnMetadata in project hazelcast by hazelcast.
the class SqlConsole method determineAlignments.
private static Alignment[] determineAlignments(SqlRowMetadata metadata) {
int colCount = metadata.getColumnCount();
Alignment[] alignments = new Alignment[colCount];
for (int i = 0; i < colCount; i++) {
SqlColumnMetadata colMetadata = metadata.getColumn(i);
SqlColumnType type = colMetadata.getType();
switch(type) {
case BIGINT:
case DECIMAL:
case DOUBLE:
case INTEGER:
case REAL:
case SMALLINT:
case TINYINT:
alignments[i] = Alignment.RIGHT;
break;
case BOOLEAN:
case DATE:
case NULL:
case OBJECT:
case TIMESTAMP:
case VARCHAR:
case TIMESTAMP_WITH_TIME_ZONE:
default:
alignments[i] = Alignment.LEFT;
}
}
return alignments;
}
use of com.hazelcast.sql.SqlColumnMetadata in project hazelcast by hazelcast.
the class PlanExecutor method execute.
SqlResult execute(ExplainStatementPlan plan) {
Stream<String> planRows;
SqlRowMetadata metadata = new SqlRowMetadata(singletonList(new SqlColumnMetadata("rel", VARCHAR, false)));
InternalSerializationService serializationService = Util.getSerializationService(hazelcastInstance);
planRows = Arrays.stream(plan.getRel().explain().split(LE));
return new SqlResultImpl(QueryId.create(hazelcastInstance.getLocalEndpoint().getUuid()), new StaticQueryResultProducerImpl(planRows.map(rel -> new JetSqlRow(serializationService, new Object[] { rel })).iterator()), metadata, false);
}
use of com.hazelcast.sql.SqlColumnMetadata in project hazelcast by hazelcast.
the class SqlRowImpl method toString.
@Override
public String toString() {
StringJoiner joiner = new StringJoiner(", ", "[", "]");
for (int i = 0; i < rowMetadata.getColumnCount(); i++) {
SqlColumnMetadata columnMetadata = rowMetadata.getColumn(i);
// toString() is often called by the debugger, it must not mutate the state by serializing or deserializing.
Object columnValue = row.getMaybeSerialized(i);
joiner.add(columnMetadata.getName() + ' ' + columnMetadata.getType() + '=' + columnValue);
}
return joiner.toString();
}
use of com.hazelcast.sql.SqlColumnMetadata 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.SqlColumnMetadata in project hazelcast by hazelcast.
the class ShowStatementTest method test_showStatement_metadata.
@Test
public void test_showStatement_metadata() {
SqlRowMetadata expectedMetadata = new SqlRowMetadata(singletonList(new SqlColumnMetadata("name", SqlColumnType.VARCHAR, false)));
assertThat(sqlService.execute("show mappings").getRowMetadata()).isEqualTo(expectedMetadata);
assertThat(sqlService.execute("show jobs").getRowMetadata()).isEqualTo(expectedMetadata);
}
Aggregations