@Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof DruidRel) { datasourceNames.addAll(((DruidRel) node).getDataSourceNames()); } if (node instanceof Bindables.BindableTableScan) { Bindables.BindableTableScan bts = (Bindables.BindableTableScan) node; RelOptTable table = bts.getTable(); String tableName = table.getQualifiedName().get(0); datasourceNames.add(tableName); } node.childrenAccept(this); } }
private PlannerOp planBindableTableScan(BindableTableScan scan, RelDataType rowType) { if (rowType == null) { rowType = scan.getRowType(); final String tableSpace = scan.getTable().getQualifiedName().get(0); final TableImpl tableImpl = (TableImpl) scan.getTable().unwrap(org.apache.calcite.schema.Table.class ); Table table = tableImpl.tableManager.getTable();
protected void apply(RelOptRuleCall call, Project project, TableScan scan) { final RelOptTable table = scan.getTable(); assert table.unwrap(ProjectableFilterableTable.class) != null; final Mappings.TargetMapping mapping = project.getMapping(); if (mapping == null || Mappings.isIdentity(mapping)) { return; } final ImmutableIntList projects; final ImmutableList<RexNode> filters; if (scan instanceof Bindables.BindableTableScan) { final Bindables.BindableTableScan bindableScan = (Bindables.BindableTableScan) scan; filters = bindableScan.filters; projects = bindableScan.projects; } else { filters = ImmutableList.of(); projects = scan.identity(); } final List<Integer> projects2 = Mappings.apply((Mapping) mapping, projects); call.transformTo( Bindables.BindableTableScan.create(scan.getCluster(), scan.getTable(), filters, projects2)); } }
protected void apply(RelOptRuleCall call, Project project, TableScan scan) { final RelOptTable table = scan.getTable(); assert table.unwrap(ProjectableFilterableTable.class) != null; final Mappings.TargetMapping mapping = project.getMapping(); if (mapping == null || Mappings.isIdentity(mapping)) { return; } final ImmutableIntList projects; final ImmutableList<RexNode> filters; if (scan instanceof Bindables.BindableTableScan) { final Bindables.BindableTableScan bindableScan = (Bindables.BindableTableScan) scan; filters = bindableScan.filters; projects = bindableScan.projects; } else { filters = ImmutableList.of(); projects = scan.identity(); } final List<Integer> projects2 = Mappings.apply((Mapping) mapping, projects); call.transformTo( Bindables.BindableTableScan.create(scan.getCluster(), scan.getTable(), filters, projects2)); } }
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, filter.getCondition())); call.transformTo( Bindables.BindableTableScan.create(scan.getCluster(), scan.getTable(), filters.build(), projects)); } }
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, filter.getCondition())); call.transformTo( Bindables.BindableTableScan.create(scan.getCluster(), scan.getTable(), filters.build(), projects)); } }
/** Creates a BindableTableScan. */ public static BindableTableScan create(RelOptCluster cluster, RelOptTable relOptTable, List<RexNode> filters, List<Integer> projects) { final Table table = relOptTable.unwrap(Table.class); final RelTraitSet traitSet = cluster.traitSetOf(BindableConvention.INSTANCE) .replaceIfs(RelCollationTraitDef.INSTANCE, () -> { if (table != null) { return table.getStatistic().getCollations(); } return ImmutableList.of(); }); return new BindableTableScan(cluster, traitSet, relOptTable, ImmutableList.copyOf(filters), ImmutableIntList.copyOf(projects)); }
/** Creates a BindableTableScan. */ public static BindableTableScan create(RelOptCluster cluster, RelOptTable relOptTable, List<RexNode> filters, List<Integer> projects) { final Table table = relOptTable.unwrap(Table.class); final RelTraitSet traitSet = cluster.traitSetOf(BindableConvention.INSTANCE) .replaceIfs(RelCollationTraitDef.INSTANCE, () -> { if (table != null) { return table.getStatistic().getCollations(); } return ImmutableList.of(); }); return new BindableTableScan(cluster, traitSet, relOptTable, ImmutableList.copyOf(filters), ImmutableIntList.copyOf(projects)); }
@Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof DruidRel) { datasourceNames.addAll(((DruidRel) node).getDatasourceNames()); } if (node instanceof Bindables.BindableTableScan) { Bindables.BindableTableScan bts = (Bindables.BindableTableScan) node; RelOptTable table = bts.getTable(); String tableName = table.getQualifiedName().get(0); datasourceNames.add(tableName); } node.childrenAccept(this); } }
@Override public RelDataType deriveRowType() { final RelDataTypeFactory.Builder builder = getCluster().getTypeFactory().builder(); final List<RelDataTypeField> fieldList = table.getRowType().getFieldList(); for (int project : projects) { builder.add(fieldList.get(project)); } return builder.build(); }
/** Creates a BindableTableScan. * * <p>Use {@link #create} unless you know what you are doing. */ BindableTableScan(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, ImmutableList<RexNode> filters, ImmutableIntList projects) { super(cluster, traitSet, table); this.filters = Objects.requireNonNull(filters); this.projects = Objects.requireNonNull(projects); Preconditions.checkArgument(canHandle(table)); }
/** Creates a BindableTableScan. * * <p>Use {@link #create} unless you know what you are doing. */ BindableTableScan(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, ImmutableList<RexNode> filters, ImmutableIntList projects) { super(cluster, traitSet, table); this.filters = Objects.requireNonNull(filters); this.projects = Objects.requireNonNull(projects); Preconditions.checkArgument(canHandle(table)); }
@Override public RelWriter explainTerms(RelWriter pw) { return super.explainTerms(pw) .itemIf("filters", filters, !filters.isEmpty()) .itemIf("projects", projects, !projects.equals(identity())); }
@Override public RelDataType deriveRowType() { final RelDataTypeFactory.Builder builder = getCluster().getTypeFactory().builder(); final List<RelDataTypeField> fieldList = table.getRowType().getFieldList(); for (int project : projects) { builder.add(fieldList.get(project)); } return builder.build(); }
@Override public RelWriter explainTerms(RelWriter pw) { return super.explainTerms(pw) .itemIf("filters", filters, !filters.isEmpty()) .itemIf("projects", projects, !projects.equals(identity())); }