Java Code Examples for org.apache.calcite.interpreter.Bindables#BindableTableScan

The following examples show how to use org.apache.calcite.interpreter.Bindables#BindableTableScan . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PushDownLogicTableRule.java    From Mycat2 with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
private RelNode global(RelOptCluster cluster,
                       Bindables.BindableTableScan bindableTableScan,
                       RelOptSchema relOptSchema,
                       MycatLogicTable logicTable) {
    final HashSet<String> context = new HashSet<>();
    RelNode logicalTableScan;
    MycatPhysicalTable mycatPhysicalTable = logicTable.getMycatGlobalPhysicalTable(context);
    RelOptTable dataNode = RelOptTableImpl.create(
            relOptSchema,
            logicTable.getRowType(cluster.getTypeFactory()),//这里使用logicTable,避免类型不一致
            mycatPhysicalTable,
            ImmutableList.of(mycatPhysicalTable.getBackendTableInfo().getUniqueName()));
    logicalTableScan = LogicalTableScan.create(cluster, dataNode, ImmutableList.of());
    return RelOptUtil.createProject(RelOptUtil.createFilter(logicalTableScan, bindableTableScan.filters), bindableTableScan.projects);
}
 
Example 2
Source File: PushDownLogicTableRule.java    From Mycat2 with GNU General Public License v3.0 6 votes vote down vote up
private RelNode shardingTable(RelBuilder builder, Bindables.BindableTableScan bindableTableScan, RelOptCluster cluster, RelOptSchema relOptSchema, MycatLogicTable logicTable) {
    RelNode value;
    ArrayList<RexNode> filters = new ArrayList<>(bindableTableScan.filters == null ? Collections.emptyList() : bindableTableScan.filters);
    List<DataNode> backendTableInfos = CalciteUtls.getBackendTableInfos((ShardingTableHandler) logicTable.logicTable(), filters);

    ////////////////////////////////////////////////////////////////////////////////////////////////
    //视图优化


    ////////////////////////////////////////////////////////////////////////////////////////////////
    builder.clear();
    for (DataNode backendTableInfo : backendTableInfos) {
        builder.push(getBindableTableScan(bindableTableScan, cluster, relOptSchema, backendTableInfo));
    }
    value = builder.union(true, backendTableInfos.size()).build();
    return value;
}
 
Example 3
Source File: FilterTableScanRule.java    From calcite with Apache License 2.0 6 votes vote down vote up
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) {
  final ImmutableIntList projects;
  final ImmutableList.Builder<RexNode> filters = ImmutableList.builder();
  if (scan instanceof Bindables.BindableTableScan) {
    final Bindables.BindableTableScan bindableScan =
        (Bindables.BindableTableScan) scan;
    filters.addAll(bindableScan.filters);
    projects = bindableScan.projects;
  } else {
    projects = scan.identity();
  }

  final Mapping mapping = Mappings.target(projects,
      scan.getTable().getRowType().getFieldCount());
  filters.add(
      RexUtil.apply(mapping.inverse(), filter.getCondition()));

  call.transformTo(
      Bindables.BindableTableScan.create(scan.getCluster(), scan.getTable(),
          filters.build(), projects));
}
 
Example 4
Source File: PushDownLogicTableRule.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
public RelNode toPhyTable(RelBuilder builder, TableScan judgeObject) {

        Bindables.BindableTableScan bindableTableScan;
        if (judgeObject instanceof Bindables.BindableTableScan) {
            bindableTableScan = (Bindables.BindableTableScan) judgeObject;
        } else {
            bindableTableScan = Bindables.BindableTableScan.create(judgeObject.getCluster(), judgeObject.getTable());
        }
        RelOptCluster cluster = bindableTableScan.getCluster();//工具类
        RelMetadataQuery metadataQuery = cluster.getMetadataQuery();
        RelOptTable relOptTable = bindableTableScan.getTable();//包装表
        RelOptSchema relOptSchema = bindableTableScan.getTable().getRelOptSchema();//schema信息
        MycatLogicTable logicTable = relOptTable.unwrap(MycatLogicTable.class);

        RelNode value = null;
        if (logicTable != null) {
            switch (logicTable.getTable().getType()) {
                case SHARDING:
                    value = shardingTable(builder, bindableTableScan, cluster, relOptSchema, logicTable);
                    break;
                case GLOBAL:
                    value = global(cluster, bindableTableScan, relOptSchema, logicTable);
            }

        } else {
            value = bindableTableScan;
        }
        return value;
    }
 
Example 5
Source File: PushDownLogicTableRule.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
private static RelNode getBindableTableScan(Bindables.BindableTableScan bindableTableScan, RelOptCluster cluster, RelOptSchema relOptSchema, DataNode backendTableInfo) {
    String uniqueName = backendTableInfo.getUniqueName();
    MycatLogicTable unwrap = bindableTableScan.getTable().unwrap(MycatLogicTable.class);
    MycatPhysicalTable mycatPhysicalTable = new MycatPhysicalTable(unwrap,backendTableInfo);
    RelOptTable dataNode = RelOptTableImpl.create(
            relOptSchema,
            mycatPhysicalTable.getRowType(cluster.getTypeFactory()),
            mycatPhysicalTable,
            ImmutableList.of(uniqueName));
    RelNode logicalTableScan = LogicalTableScan.create(cluster, dataNode, ImmutableList.of());
    return RelOptUtil.createProject(RelOptUtil.createFilter(logicalTableScan, bindableTableScan.filters), bindableTableScan.projects);
}
 
Example 6
Source File: HBTQueryConvertor.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
public RelNode filterFromTable(FilterFromTableSchema input) {
    List<String> names = input.getNames();
    relBuilder.scan(names);
    TableScan tableScan = (TableScan) relBuilder.peek();
    RelOptTable table = tableScan.getTable();
    relBuilder.as(names.get(names.size() - 1));
    relBuilder.filter(toRex(input.getFilter()));
    Filter build = (Filter) relBuilder.build();
    Bindables.BindableTableScan bindableTableScan = Bindables.BindableTableScan.create(build.getCluster(), table, build.getChildExps(), TableScan.identity(table));
    relBuilder.clear();
    return PushDownLogicTableRule.BindableTableScan.toPhyTable(relBuilder, bindableTableScan);
}