Search in sources :

Example 31 with MetadataManager

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

the class VisualTablePlanImpl method execute.

@Override
public Observable<VectorSchemaRoot> execute(RootContext rootContext) {
    RelOptTable table = relNode.getRelNode().getTable();
    MycatLogicTable logicTable = table.unwrap(MycatLogicTable.class);
    TableHandler tableHandler = logicTable.getTable();
    VisualTableHandler visualTableHandler = (VisualTableHandler) tableHandler;
    MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
    MycatRelDataType mycatRelDataTypeByCalcite = relNode.getMycatRelDataTypeByCalcite();
    Schema schema = toArrowSchema(mycatRelDataTypeByCalcite);
    return ValuesPlan.create(schema, MycatRxJavaUtl.blockingIterable(visualTableHandler.scanAll())).execute(rootContext);
}
Also used : MetadataManager(io.mycat.MetadataManager) TableHandler(io.mycat.TableHandler) VisualTableHandler(io.mycat.prototypeserver.mysql.VisualTableHandler) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) MycatLogicTable(io.mycat.calcite.table.MycatLogicTable) Schema(org.apache.arrow.vector.types.pojo.Schema) FactoryUtil.toArrowSchema(io.ordinate.engine.factory.FactoryUtil.toArrowSchema) VisualTableHandler(io.mycat.prototypeserver.mysql.VisualTableHandler) RelOptTable(org.apache.calcite.plan.RelOptTable)

Example 32 with MetadataManager

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

the class PrototypeHandlerImpl method showCreateTable.

@Override
public List<Object[]> showCreateTable(SQLShowCreateTableStatement statement) {
    SQLPropertyExpr sqlPropertyExpr = (SQLPropertyExpr) statement.getName();
    String schemaName = SQLUtils.normalize(sqlPropertyExpr.getOwnerName());
    String tableName = SQLUtils.normalize(sqlPropertyExpr.getSimpleName());
    MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
    TableHandler tableHandler = metadataManager.getTable(schemaName, tableName);
    String createTableSQL = tableHandler.getCreateTableSQL();
    ArrayList<Object[]> objects = new ArrayList<>();
    objects.add(new Object[] { tableName, createTableSQL });
    return objects;
}
Also used : MetadataManager(io.mycat.MetadataManager) TableHandler(io.mycat.TableHandler) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)

Example 33 with MetadataManager

use of io.mycat.MetadataManager 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 34 with MetadataManager

use of io.mycat.MetadataManager 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

MetadataManager (io.mycat.MetadataManager)34 ShardingTable (io.mycat.calcite.table.ShardingTable)22 Test (org.junit.Test)22 Partition (io.mycat.Partition)17 ShardingTableConfig (io.mycat.config.ShardingTableConfig)12 CustomRuleFunction (io.mycat.router.CustomRuleFunction)12 RangeVariable (io.mycat.RangeVariable)11 DrdsSqlCompiler (io.mycat.DrdsSqlCompiler)10 ValuePredicateAnalyzer (io.mycat.calcite.rewriter.ValuePredicateAnalyzer)10 java.util (java.util)10 Map (java.util.Map)10 RexNode (org.apache.calcite.rex.RexNode)10 TableHandler (io.mycat.TableHandler)9 DefaultConnection (io.mycat.datasource.jdbc.datasource.DefaultConnection)7 JdbcConnectionManager (io.mycat.datasource.jdbc.datasource.JdbcConnectionManager)7 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 MetaClusterCurrent (io.mycat.MetaClusterCurrent)5 MycatCalciteSupport (io.mycat.calcite.MycatCalciteSupport)5 Connection (java.sql.Connection)5