Search in sources :

Example 1 with LogicTable

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();
        }
    };
}
Also used : SimpleColumnInfo(io.mycat.SimpleColumnInfo) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) MySqlCreateTableStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement) LogicTable(io.mycat.calcite.table.LogicTable) MycatRowMetaData(io.mycat.beans.mycat.MycatRowMetaData)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 MySqlCreateTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)1 SimpleColumnInfo (io.mycat.SimpleColumnInfo)1 MycatRowMetaData (io.mycat.beans.mycat.MycatRowMetaData)1 LogicTable (io.mycat.calcite.table.LogicTable)1