use of io.mycat.calcite.table.LogicTable in project Mycat2 by MyCATApache.
the class VisualTableHandler method createByMySQL.
public static VisualTableHandler createByMySQL(String sql, Supplier<Observable<Object[]>> rowsProvider) {
SQLStatement sqlStatement1 = SQLUtils.parseSingleMysqlStatement(sql);
MySqlCreateTableStatement sqlStatement = (MySqlCreateTableStatement) sqlStatement1;
String schema = SQLUtils.normalize(sqlStatement.getSchema()).toLowerCase();
String tableName = SQLUtils.normalize(sqlStatement.getTableName()).toLowerCase();
MycatRowMetaData mycatRowMetaData = SQL2ResultSetUtil.getMycatRowMetaData((MySqlCreateTableStatement) sqlStatement);
List<SimpleColumnInfo> columnInfo = CalciteConvertors.getColumnInfo(Objects.requireNonNull(mycatRowMetaData));
LogicTable logicTable = new LogicTable(LogicTableType.NORMAL, schema, tableName, columnInfo, Collections.emptyMap(), sql);
return new VisualTableHandler(logicTable) {
@Override
public Observable<Object[]> scanAll() {
return rowsProvider.get();
}
};
}
Aggregations