Search in sources :

Example 6 with TableHandler

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

the class MycatTableScan method implement.

@Override
public Result implement(MycatEnumerableRelImplementor implementor, Prefer pref) {
    final BlockBuilder builder = new BlockBuilder();
    final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), JavaRowFormat.ARRAY);
    ParameterExpression root = implementor.getRootExpression();
    TableScan tableScan = (TableScan) this.relNode;
    MycatLogicTable mycatLogicTable = (MycatLogicTable) tableScan.getTable().unwrap(AbstractMycatTable.class);
    TableHandler table = mycatLogicTable.getTable();
    Method getObservable = Types.lookupMethod(NewMycatDataContext.class, "getTableObservable", String.class, String.class);
    builder.add(Expressions.call(root, getObservable, Expressions.constant(table.getSchemaName()), Expressions.constant(table.getTableName())));
    return implementor.result(physType, builder.toBlock());
}
Also used : PhysType(org.apache.calcite.adapter.enumerable.PhysType) TableScan(org.apache.calcite.rel.core.TableScan) TableHandler(io.mycat.TableHandler) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Method(java.lang.reflect.Method) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Example 7 with TableHandler

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

the class LocalTableScan method getMycatRelDataType.

@Override
public MycatRelDataType getMycatRelDataType() {
    MycatLogicTable mycatTable = getTable().unwrap(MycatLogicTable.class);
    TableHandler tableTable = mycatTable.getTable();
    List<MycatField> mycatFields = tableTable.getColumns().stream().map(c -> c.toMycatField()).collect(Collectors.toList());
    return MycatRelDataType.of(mycatFields);
}
Also used : RelInput(org.apache.calcite.rel.RelInput) TableScan(org.apache.calcite.rel.core.TableScan) TableHandler(io.mycat.TableHandler) RelFactories(org.apache.calcite.rel.core.RelFactories) MycatField(io.mycat.beans.mycat.MycatField) Collectors(java.util.stream.Collectors) MycatLogicTable(io.mycat.calcite.table.MycatLogicTable) RelWriter(org.apache.calcite.rel.RelWriter) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelHint(org.apache.calcite.rel.hint.RelHint) Map(java.util.Map) AbstractMycatTable(io.mycat.calcite.table.AbstractMycatTable) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) org.apache.calcite.plan(org.apache.calcite.plan) TableHandler(io.mycat.TableHandler) MycatLogicTable(io.mycat.calcite.table.MycatLogicTable) MycatField(io.mycat.beans.mycat.MycatField)

Example 8 with TableHandler

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

the class MycatRouteUpdateCore method explainTerms.

public RelWriter explainTerms(RelWriter pw) {
    TableHandler table = MetaClusterCurrent.wrapper(MetadataManager.class).getTable(schemaName, tableName);
    pw.item("sql", sqlStatement + "\n");
    int index = 0;
    for (Partition partition : getDataNodes(table)) {
        pw.item("dataNodes$" + index, partition + "\n");
    }
    return pw;
}
Also used : Partition(io.mycat.Partition) 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 9 with TableHandler

use of io.mycat.TableHandler 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 10 with TableHandler

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

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