use of com.hazelcast.sql.SqlColumnMetadata in project hazelcast by hazelcast.
the class PlanExecutor method execute.
SqlResult execute(ShowStatementPlan plan) {
Stream<String> rows;
switch(plan.getShowTarget()) {
case MAPPINGS:
rows = catalog.getMappingNames().stream();
break;
case VIEWS:
rows = catalog.getViewNames().stream();
break;
case JOBS:
assert plan.getShowTarget() == ShowStatementTarget.JOBS;
NodeEngine nodeEngine = getNodeEngine(hazelcastInstance);
JetServiceBackend jetServiceBackend = nodeEngine.getService(JetServiceBackend.SERVICE_NAME);
rows = jetServiceBackend.getJobRepository().getJobRecords().stream().map(record -> record.getConfig().getName()).filter(Objects::nonNull);
break;
default:
throw new AssertionError("Unsupported SHOW statement target.");
}
SqlRowMetadata metadata = new SqlRowMetadata(singletonList(new SqlColumnMetadata("name", VARCHAR, false)));
InternalSerializationService serializationService = Util.getSerializationService(hazelcastInstance);
return new SqlResultImpl(QueryId.create(hazelcastInstance.getLocalEndpoint().getUuid()), new StaticQueryResultProducerImpl(rows.sorted().map(name -> new JetSqlRow(serializationService, new Object[] { name })).iterator()), metadata, false);
}
use of com.hazelcast.sql.SqlColumnMetadata in project hazelcast by hazelcast.
the class CalciteSqlOptimizer method createRowMetadata.
private SqlRowMetadata createRowMetadata(List<String> columnNames, List<QueryDataType> columnTypes, List<RelDataTypeField> fields) {
assert columnNames.size() == columnTypes.size();
assert columnTypes.size() == fields.size();
List<SqlColumnMetadata> columns = new ArrayList<>(columnNames.size());
for (int i = 0; i < columnNames.size(); i++) {
SqlColumnMetadata column = QueryUtils.getColumnMetadata(columnNames.get(i), columnTypes.get(i), fields.get(i).getType().isNullable());
columns.add(column);
}
return new SqlRowMetadata(columns);
}
use of com.hazelcast.sql.SqlColumnMetadata in project hazelcast by hazelcast.
the class SqlBasicTest method checkRowMetadata.
private void checkRowMetadata(SqlRowMetadata rowMetadata) {
List<String> fields = fields();
List<SqlColumnType> fieldTypes = fieldTypes();
assertEquals(fields.size(), rowMetadata.getColumnCount());
for (int i = 0; i < fields.size(); i++) {
String field = fields.get(i);
String adjustedField = adjustFieldName(field);
SqlColumnType fieldType = fieldTypes.get(i);
int fieldIndex = rowMetadata.findColumn(adjustedField);
assertNotEquals(SqlRowMetadata.COLUMN_NOT_FOUND, fieldIndex);
SqlColumnMetadata columnMetadata = rowMetadata.getColumn(fieldIndex);
assertEquals(adjustedField, columnMetadata.getName());
assertEquals(fieldType, columnMetadata.getType());
assertTrue(columnMetadata.isNullable());
}
assertThrows(IndexOutOfBoundsException.class, () -> rowMetadata.getColumn(-1));
assertThrows(IndexOutOfBoundsException.class, () -> rowMetadata.getColumn(fields.size()));
}
use of com.hazelcast.sql.SqlColumnMetadata in project hazelcast by hazelcast.
the class SqlConsole method determineColumnWidths.
private static int[] determineColumnWidths(SqlRowMetadata metadata) {
int colCount = metadata.getColumnCount();
int[] colWidths = new int[colCount];
for (int i = 0; i < colCount; i++) {
SqlColumnMetadata colMetadata = metadata.getColumn(i);
SqlColumnType type = colMetadata.getType();
String colName = colMetadata.getName();
switch(type) {
case BOOLEAN:
colWidths[i] = determineColumnWidth(colName, Constants.BOOLEAN_FORMAT_LENGTH);
break;
case DATE:
colWidths[i] = determineColumnWidth(colName, Constants.DATE_FORMAT_LENGTH);
break;
case TIMESTAMP_WITH_TIME_ZONE:
colWidths[i] = determineColumnWidth(colName, Constants.TIMESTAMP_WITH_TIME_ZONE_FORMAT_LENGTH);
break;
case DECIMAL:
colWidths[i] = determineColumnWidth(colName, Constants.DECIMAL_FORMAT_LENGTH);
break;
case REAL:
colWidths[i] = determineColumnWidth(colName, Constants.REAL_FORMAT_LENGTH);
break;
case DOUBLE:
colWidths[i] = determineColumnWidth(colName, Constants.DOUBLE_FORMAT_LENGTH);
break;
case INTEGER:
colWidths[i] = determineColumnWidth(colName, Constants.INTEGER_FORMAT_LENGTH);
break;
case NULL:
colWidths[i] = determineColumnWidth(colName, Constants.NULL_FORMAT_LENGTH);
break;
case TINYINT:
colWidths[i] = determineColumnWidth(colName, Constants.TINYINT_FORMAT_LENGTH);
break;
case SMALLINT:
colWidths[i] = determineColumnWidth(colName, Constants.SMALLINT_FORMAT_LENGTH);
break;
case TIMESTAMP:
colWidths[i] = determineColumnWidth(colName, Constants.TIMESTAMP_FORMAT_LENGTH);
break;
case BIGINT:
colWidths[i] = determineColumnWidth(colName, Constants.BIGINT_FORMAT_LENGTH);
break;
case VARCHAR:
colWidths[i] = determineColumnWidth(colName, Constants.VARCHAR_FORMAT_LENGTH);
break;
case OBJECT:
colWidths[i] = determineColumnWidth(colName, Constants.OBJECT_FORMAT_LENGTH);
break;
case JSON:
colWidths[i] = determineColumnWidth(colName, Constants.JSON_FORMAT_LENGTH);
break;
default:
throw new UnsupportedOperationException(type.toString());
}
}
return colWidths;
}
use of com.hazelcast.sql.SqlColumnMetadata 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);
}
}
Aggregations