use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class ShardingSQLHandler method testExample.
private Optional<Future<Void>> testExample(SQLRequest<SQLSelectStatement> request, MycatDataContext dataContext, Response response) {
String sqlString = request.getSqlString();
if (sqlString.equalsIgnoreCase("select swapbuffer")) {
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
resultSetBuilder.addColumnInfo("1", JDBCType.INTEGER);
resultSetBuilder.addObjectRowPayload(Arrays.asList(1, 2));
resultSetBuilder.addObjectRowPayload(Arrays.asList(3, 4));
MySQLSwapbufferBuilder mySQLSwapbufferBuilder = new MySQLSwapbufferBuilder(resultSetBuilder.build());
Observable<Buffer> sender = mySQLSwapbufferBuilder.build();
return Optional.of(response.swapBuffer(sender));
}
if (sqlString.equalsIgnoreCase("select arrow")) {
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
resultSetBuilder.addColumnInfo("1", JDBCType.INTEGER);
resultSetBuilder.addObjectRowPayload(Arrays.asList(1, 2));
resultSetBuilder.addObjectRowPayload(Arrays.asList(3, 4));
RowBaseIterator rowBaseIterator = resultSetBuilder.build();
Observable<VectorSchemaRoot> observable = ResultWriterUtil.convertToVector(resultSetBuilder.build());
return Optional.of(response.sendVectorResultSet(rowBaseIterator.getMetaData(), observable));
}
return Optional.empty();
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class BaseRowObservable method toColumnMetaData.
public static MycatRowMetaData toColumnMetaData(List<ColumnDescriptor> event) {
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
for (ColumnDescriptor columnDescriptor : event) {
if (columnDescriptor instanceof ColumnDefinition) {
ColumnDefinition columnDefinition = (ColumnDefinition) columnDescriptor;
String schemaName = columnDefinition.schema();
String tableName = columnDefinition.orgTable();
String columnName = columnDefinition.name();
int columnType = columnDefinition.type().jdbcType.getVendorTypeNumber();
int precision = 0;
int scale = 0;
String columnLabel = columnDefinition.name();
boolean isAutoIncrement = false;
boolean isCaseSensitive = false;
boolean isNullable = (columnDefinition.flags() & ColumnDefinition.ColumnDefinitionFlags.NOT_NULL_FLAG) == 0;
boolean isSigned = true;
int displaySize = (int) columnDefinition.columnLength();
resultSetBuilder.addColumnInfo(schemaName, tableName, columnName, columnType, precision, scale, columnLabel, isAutoIncrement, isCaseSensitive, isNullable, isSigned, displaySize);
} else {
resultSetBuilder.addColumnInfo(columnDescriptor.name(), columnDescriptor.jdbcType());
}
}
RowBaseIterator build = resultSetBuilder.build();
return build.getMetaData();
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class HintHandler method showInstances.
public static RowBaseIterator showInstances() {
MycatRouterConfig routerConfig = MetaClusterCurrent.wrapper(MycatRouterConfig.class);
ReplicaSelectorManager replicaSelectorRuntime = MetaClusterCurrent.wrapper(ReplicaSelectorManager.class);
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
resultSetBuilder.addColumnInfo("NAME", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("ALIVE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("READABLE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("TYPE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("SESSION_COUNT", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("WEIGHT", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("MASTER", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("LIMIT_SESSION_COUNT", JDBCType.BIGINT);
resultSetBuilder.addColumnInfo("REPLICA", JDBCType.VARCHAR);
Collection<PhysicsInstance> values = replicaSelectorRuntime.getPhysicsInstances();
Map<String, DatasourceConfig> dataSourceConfig = routerConfig.getDatasources().stream().collect(Collectors.toMap(k -> k.getName(), v -> v));
for (PhysicsInstance instance : values) {
String NAME = instance.getName();
String TYPE = instance.getType().name();
boolean READABLE = instance.asSelectRead();
int SESSION_COUNT = instance.getSessionCounter();
int WEIGHT = instance.getWeight();
boolean ALIVE = instance.isAlive();
boolean MASTER = instance.isMaster();
Optional<DatasourceConfig> e = Optional.ofNullable(dataSourceConfig.get(NAME));
String replicaDataSourceSelectorList = String.join(",", replicaSelectorRuntime.getReplicaNameListByInstanceName(NAME));
resultSetBuilder.addObjectRowPayload(Arrays.asList(NAME, ALIVE, READABLE, TYPE, SESSION_COUNT, WEIGHT, MASTER, e.map(i -> i.getMaxCon()).orElse(-1), replicaDataSourceSelectorList));
}
RowBaseIterator rowBaseIterator = resultSetBuilder.build();
return rowBaseIterator;
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class HintHandler method showTables.
@Nullable
private Future<Void> showTables(Response response, String body, MetadataManager metadataManager, MycatRouterConfig routerConfig) {
Map map = JsonUtil.from(body, Map.class);
String type = (String) map.get("type");
String schemaName = (String) map.get("schemaName");
Stream<TableHandler> tables;
Stream<TableHandler> tableHandlerStream;
if (schemaName == null) {
tableHandlerStream = metadataManager.getSchemaMap().values().stream().flatMap(i -> i.logicTables().values().stream());
} else {
SchemaHandler schemaHandler = Objects.requireNonNull(metadataManager.getSchemaMap().get(schemaName));
NameMap<TableHandler> logicTables = schemaHandler.logicTables();
tableHandlerStream = logicTables.values().stream();
}
if ("global".equalsIgnoreCase(type)) {
tables = tableHandlerStream.filter(i -> i.getType() == LogicTableType.GLOBAL);
} else if ("sharding".equalsIgnoreCase(type)) {
tables = tableHandlerStream.filter(i -> i.getType() == LogicTableType.SHARDING);
} else if ("normal".equalsIgnoreCase(type)) {
tables = tableHandlerStream.filter(i -> i.getType() == LogicTableType.NORMAL);
} else if ("custom".equalsIgnoreCase(type)) {
tables = tableHandlerStream.filter(i -> i.getType() == LogicTableType.CUSTOM);
} else {
tables = tableHandlerStream;
}
ResultSetBuilder builder = ResultSetBuilder.create();
builder.addColumnInfo("SCHEMA_NAME", JDBCType.VARCHAR).addColumnInfo("TABLE_NAME", JDBCType.VARCHAR).addColumnInfo("CREATE_TABLE_SQL", JDBCType.VARCHAR).addColumnInfo("TYPE", JDBCType.VARCHAR).addColumnInfo("COLUMNS", JDBCType.VARCHAR).addColumnInfo("CONFIG", JDBCType.VARCHAR);
tables.forEach(table -> {
String SCHEMA_NAME = table.getSchemaName();
String TABLE_NAME = table.getTableName();
String CREATE_TABLE_SQL = table.getCreateTableSQL();
LogicTableType TYPE = table.getType();
String COLUMNS = table.getColumns().stream().map(i -> i.toString()).collect(Collectors.joining(","));
String CONFIG = routerConfig.getSchemas().stream().filter(i -> SCHEMA_NAME.equalsIgnoreCase(i.getSchemaName())).map(i -> {
switch(TYPE) {
case SHARDING:
return NameMap.immutableCopyOf(i.getShardingTables());
case GLOBAL:
return NameMap.immutableCopyOf(i.getGlobalTables());
case NORMAL:
return NameMap.immutableCopyOf(i.getNormalTables());
case CUSTOM:
return NameMap.immutableCopyOf(i.getCustomTables());
default:
return null;
}
}).map(i -> i.get(TABLE_NAME)).findFirst().map(i -> i.toString()).orElse(null);
builder.addObjectRowPayload(Arrays.asList(SCHEMA_NAME, TABLE_NAME, CREATE_TABLE_SQL, TYPE, COLUMNS, CONFIG));
});
return response.sendResultSet(() -> builder.build());
}
use of io.mycat.beans.mycat.ResultSetBuilder in project Mycat2 by MyCATApache.
the class MysqlShowDatabaseStatusHandler method onExecute.
@Override
protected Future<Void> onExecute(SQLRequest<MySqlShowDatabaseStatusStatement> request, MycatDataContext dataContext, Response response) {
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
resultSetBuilder.addColumnInfo("ID", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("NAME", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("CONNECTION_STRING", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("PHYSICAL_DB", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("SIZE_IN_MB", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("RATIO", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("THREAD_RUNNING", JDBCType.VARCHAR);
return response.sendResultSet(resultSetBuilder.build());
}
Aggregations