Search in sources :

Example 11 with TableHandler

use of io.mycat.TableHandler in project Mycat2 by MyCATApache.

the class AnalyzeHanlder method onExecute.

@Override
protected Future<Void> onExecute(SQLRequest<MySqlAnalyzeStatement> request, MycatDataContext dataContext, Response response) {
    MySqlAnalyzeStatement ast = request.getAst();
    List<SQLExprTableSource> tableSources = Optional.ofNullable(ast.getTableSources()).orElse(Collections.emptyList());
    if (tableSources.isEmpty()) {
        return response.sendError(new MycatException("need tables"));
    } else {
        ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
        resultSetBuilder.addColumnInfo("Table", JDBCType.VARCHAR);
        resultSetBuilder.addColumnInfo("Op", JDBCType.VARCHAR);
        resultSetBuilder.addColumnInfo("Msg_type", JDBCType.VARCHAR);
        resultSetBuilder.addColumnInfo("Msg_Text", JDBCType.VARCHAR);
        for (SQLExprTableSource tableSource : tableSources) {
            String schemaName = SQLUtils.normalize(tableSource.getSchema());
            String tableName = SQLUtils.normalize(tableSource.getTableName());
            resultSetBuilder.addObjectRowPayload(Arrays.asList(schemaName + "." + tableName, "analyze", "status", "OK"));
            MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
            TableHandler tableHandler = metadataManager.getTable(schemaName, tableName);
            if (tableHandler == null) {
                return response.sendError(new MycatException(tableSource + "不存在"));
            }
            StatisticCenter statisticCenter = MetaClusterCurrent.wrapper(StatisticCenter.class);
            statisticCenter.fetchTableRowCount(tableHandler);
        }
        return response.sendResultSet(resultSetBuilder.build());
    }
}
Also used : MySqlAnalyzeStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAnalyzeStatement) MycatException(io.mycat.MycatException) ResultSetBuilder(io.mycat.beans.mycat.ResultSetBuilder) MetadataManager(io.mycat.MetadataManager) TableHandler(io.mycat.TableHandler) StatisticCenter(io.mycat.statistic.StatisticCenter) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource)

Example 12 with TableHandler

use of io.mycat.TableHandler in project Mycat2 by MyCATApache.

the class MycatRouteUpdateCore method explain.

public ExplainWriter explain(ExplainWriter writer) {
    TableHandler table = MetaClusterCurrent.wrapper(MetadataManager.class).getTable(schemaName, tableName);
    writer.name("MycatUpdateRel").into();
    writer.item("sql", sqlStatement);
    writer.item("dataNodes", getDataNodes(table));
    return writer.ret();
}
Also used : MetadataManager(io.mycat.MetadataManager) TableHandler(io.mycat.TableHandler) GlobalTableHandler(io.mycat.calcite.table.GlobalTableHandler) NormalTableHandler(io.mycat.calcite.table.NormalTableHandler) ShardingTableHandler(io.mycat.router.ShardingTableHandler)

Example 13 with TableHandler

use of io.mycat.TableHandler in project Mycat2 by MyCATApache.

the class MycatRouteInsertCore method logicTable.

public ShardingTableHandler logicTable() {
    MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
    TableHandler tableHandler = metadataManager.getTable(schemaName, tableName);
    return (ShardingTableHandler) tableHandler;
}
Also used : ShardingTableHandler(io.mycat.router.ShardingTableHandler) MetadataManager(io.mycat.MetadataManager) TableHandler(io.mycat.TableHandler) ShardingTableHandler(io.mycat.router.ShardingTableHandler)

Aggregations

TableHandler (io.mycat.TableHandler)13 MetadataManager (io.mycat.MetadataManager)9 MycatLogicTable (io.mycat.calcite.table.MycatLogicTable)4 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)3 MycatRelDataType (io.mycat.beans.mycat.MycatRelDataType)3 ShardingTableHandler (io.mycat.router.ShardingTableHandler)3 Collectors (java.util.stream.Collectors)3 SQLUtils (com.alibaba.druid.sql.SQLUtils)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)2 SQLLiteralExpr (com.alibaba.druid.sql.ast.expr.SQLLiteralExpr)2 SQLTextLiteralExpr (com.alibaba.druid.sql.ast.expr.SQLTextLiteralExpr)2 com.alibaba.druid.sql.ast.statement (com.alibaba.druid.sql.ast.statement)2 com.alibaba.druid.sql.dialect.mysql.ast.statement (com.alibaba.druid.sql.dialect.mysql.ast.statement)2 MetaClusterCurrent (io.mycat.MetaClusterCurrent)2 MysqlVariableService (io.mycat.MysqlVariableService)2 PrepareExecutor (io.mycat.calcite.PrepareExecutor)2 GlobalTableHandler (io.mycat.calcite.table.GlobalTableHandler)2 NormalTableHandler (io.mycat.calcite.table.NormalTableHandler)2 SchemaHandler (io.mycat.calcite.table.SchemaHandler)2 DatasourceConfig (io.mycat.config.DatasourceConfig)2