Search in sources :

Example 6 with MycatLogicTable

use of io.mycat.calcite.table.MycatLogicTable in project Mycat2 by MyCATApache.

the class HBTQueryConvertor method fromTable.

private RelNode fromTable(FromTableSchema input) {
    List<String> collect = new ArrayList<>(input.getNames());
    RelNode build = relBuilder.scan(collect).as(collect.get(collect.size() - 1)).build();
    MycatLogicTable mycatLogicTable = build.getTable().unwrap(MycatLogicTable.class);
    // 消除逻辑表,变成物理表
    if (mycatLogicTable != null) {
        relBuilder.clear();
        Stream<Map<String, Partition>> dataNodes = mycatLogicTable.createDistribution().getDataNodes();
        return toPhyTable(mycatLogicTable, dataNodes.flatMap(i -> i.values().stream()).collect(Collectors.toList()));
    }
    return build;
}
Also used : RelNode(org.apache.calcite.rel.RelNode) MycatLogicTable(io.mycat.calcite.table.MycatLogicTable) ByteString(org.apache.calcite.avatica.util.ByteString)

Example 7 with MycatLogicTable

use of io.mycat.calcite.table.MycatLogicTable 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)

Aggregations

MycatLogicTable (io.mycat.calcite.table.MycatLogicTable)7 TableHandler (io.mycat.TableHandler)4 MycatRelDataType (io.mycat.beans.mycat.MycatRelDataType)3 RelOptTable (org.apache.calcite.plan.RelOptTable)3 ImmutableList (com.google.common.collect.ImmutableList)2 MetadataManager (io.mycat.MetadataManager)2 FactoryUtil.toArrowSchema (io.ordinate.engine.factory.FactoryUtil.toArrowSchema)2 Collectors (java.util.stream.Collectors)2 TableScan (org.apache.calcite.rel.core.TableScan)2 RelHint (org.apache.calcite.rel.hint.RelHint)2 SQLUtils (com.alibaba.druid.sql.SQLUtils)1 SQLDataType (com.alibaba.druid.sql.ast.SQLDataType)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)1 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)1 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)1 ImmutableList.builder (com.google.common.collect.ImmutableList.builder)1 MetaClusterCurrent (io.mycat.MetaClusterCurrent)1 Partition (io.mycat.Partition)1 JdbcRowMetaData (io.mycat.beans.mycat.JdbcRowMetaData)1