@Override public RelNode convert(RelNode rel) { final TableScan scan = (TableScan) rel; int parallelismHint = DEFAULT_PARALLELISM_HINT; final ParallelTable parallelTable = scan.getTable().unwrap(ParallelTable.class); if (parallelTable != null && parallelTable.parallelismHint() != null) { parallelismHint = parallelTable.parallelismHint(); } final Table table = scan.getTable().unwrap(Table.class); switch (table.getJdbcTableType()) { case STREAM: return new StreamsStreamScanRel(scan.getCluster(), scan.getTraitSet().replace(StreamsLogicalConvention.INSTANCE), scan.getTable(), parallelismHint); default: throw new IllegalArgumentException(String.format("Unsupported table type: %s", table.getJdbcTableType())); } } }
@Override public RelNode visit(TableScan scan) { scan.getCluster().setMetadataProvider(metadataProvider); return super.visit(scan); }
MixedTableScan(TableScan scan) { super(scan.getCluster(), scan.getTraitSet(), scan.getTable()); } }
@Override public RelNode visit(TableScan tableScan) { if (!(tableScan instanceof IncrementallyUpdateable)) { return tableScan; } final RelNode newScan = updateScan((IncrementallyUpdateable) tableScan); // build new filter to apply refresh condition. final RexBuilder rexBuilder = tableScan.getCluster().getRexBuilder(); final RexNode inputRef = rexBuilder.makeInputRef(newScan, newScan.getRowType().getField(UPDATE_COLUMN, false, false).getIndex()); final RexNode literal = generateLiteral(rexBuilder, tableScan.getCluster().getTypeFactory()); final RexNode condition = tableScan.getCluster().getRexBuilder().makeCall(SqlStdOperatorTable.GREATER_THAN, ImmutableList.of(inputRef, literal)); return LogicalFilter.create(newScan, condition); }
@Override public RelNode visit(final TableScan scan) { final Optional<MaterializationDescriptor> descriptor = table.getDescriptor(scan.getTable().getQualifiedName()); if (descriptor.isPresent()) { // Always use metadataQuery from the cluster (do not use calcite's default CALCITE_INSTANCE) final RelOptCost cost = scan.getCluster().getMetadataQuery().getCumulativeCost(scan); final double acceleratedCost = DremioCost.aggregateCost(cost); final double originalCost = descriptor.get().getOriginalCost(); final double speedUp = originalCost/acceleratedCost; builder.addSubstitution(new SubstitutionInfo.Substitution(descriptor.get(), speedUp)); } return super.visit(scan); }
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)); } }
private TableScan createTemporaryTableScan(RelOptTableImpl relOptTable, List<String> tableAlias, TableScan tableScan, RelNode originTable) { RelDataType type = originTable.getRowType(); RelOptTableImpl relOptTableWithAlias = relOptTable.modifyTableName(tableAlias); RelOptTable newRelOptTable = RelOptTableImpl.create( relOptTableWithAlias.getRelOptSchema(), type, relOptTableWithAlias.getTable(), ImmutableList.copyOf(relOptTableWithAlias.getQualifiedName()) ); return new TemporaryTableScan( tableScan.getCluster(), tableScan.getTraitSet(), newRelOptTable ); }
/** * Expression lineage from {@link TableScan}. * * <p>We extract the fields referenced by the expression and we express them * using {@link RexTableInputRef}. */ public Set<RexNode> getExpressionLineage(TableScan rel, RelMetadataQuery mq, RexNode outputExpression) { final RexBuilder rexBuilder = rel.getCluster().getRexBuilder(); // Extract input fields referenced by expression final ImmutableBitSet inputFieldsUsed = extractInputRefs(outputExpression); // Infer column origin expressions for given references final Map<RexInputRef, Set<RexNode>> mapping = new LinkedHashMap<>(); for (int idx : inputFieldsUsed) { final RexNode inputRef = RexTableInputRef.of( RelTableRef.of(rel.getTable(), 0), RexInputRef.of(idx, rel.getRowType().getFieldList())); final RexInputRef ref = RexInputRef.of(idx, rel.getRowType().getFieldList()); mapping.put(ref, ImmutableSet.of(inputRef)); } // Return result return createAllPossibleExpressions(rexBuilder, outputExpression, mapping); }
final RexBuilder rexBuilder = getCluster().getRexBuilder(); final List<RelDataTypeField> fields = getRowType().getFieldList();
@Override public RelNode visit(TableScan scan) { RelOptTable relOptTable = scan.getTable(); final Table table = relOptTable.unwrap(Table.class); if (table.equals(starTable.tables.get(0))) { Mappings.TargetMapping mapping = Mappings.createShiftMapping( starRelOptTable.getRowType().getFieldCount(), 0, 0, relOptTable.getRowType().getFieldCount()); final RelOptCluster cluster = scan.getCluster(); final RelNode scan2 = starRelOptTable.toRel(RelOptUtil.getContext(cluster)); return RelOptUtil.createProject(scan2, Mappings.asList(mapping.inverse())); } return scan; }
final RexBuilder rexBuilder = getCluster().getRexBuilder(); final List<RelDataTypeField> fields = getRowType().getFieldList();
@Override public RelNode visit(TableScan scan) { RelOptTable relOptTable = scan.getTable(); final Table table = relOptTable.unwrap(Table.class); if (table.equals(starTable.tables.get(0))) { Mappings.TargetMapping mapping = Mappings.createShiftMapping( starRelOptTable.getRowType().getFieldCount(), 0, 0, relOptTable.getRowType().getFieldCount()); final RelOptCluster cluster = scan.getCluster(); final RelNode scan2 = starRelOptTable.toRel(ViewExpanders.simpleContext(cluster)); return RelOptUtil.createProject(scan2, Mappings.asList(mapping.inverse())); } return scan; }
/** * Expression lineage from {@link TableScan}. * * <p>We extract the fields referenced by the expression and we express them * using {@link RexTableInputRef}. */ public Set<RexNode> getExpressionLineage(TableScan rel, RelMetadataQuery mq, RexNode outputExpression) { final RexBuilder rexBuilder = rel.getCluster().getRexBuilder(); // Extract input fields referenced by expression final Set<RelDataTypeField> inputExtraFields = new LinkedHashSet<>(); final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); outputExpression.accept(inputFinder); final ImmutableBitSet inputFieldsUsed = inputFinder.inputBitSet.build(); // Infer column origin expressions for given references final Map<RexInputRef, Set<RexNode>> mapping = new LinkedHashMap<>(); for (int idx : inputFieldsUsed) { final RexNode inputRef = RexTableInputRef.of( RelTableRef.of(rel.getTable(), 0), RexInputRef.of(idx, rel.getRowType().getFieldList())); final RexInputRef ref = RexInputRef.of(idx, rel.getRowType().getFieldList()); mapping.put(ref, ImmutableSet.of(inputRef)); } // Return result return createAllPossibleExpressions(rexBuilder, outputExpression, mapping); }
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)); } }
if (!rejectedFilters.isEmpty()) { final RexNode filter = RexUtil.composeConjunction(rel.getCluster().getRexBuilder(), rejectedFilters); filter2 = RexUtil.apply(mapping, filter); final RelDataTypeFactory.Builder builder = rel.getCluster().getTypeFactory().builder(); final List<RelDataTypeField> fieldList = rel.getTable().getRowType().getFieldList();
if (!rejectedFilters.isEmpty()) { final RexNode filter = RexUtil.composeConjunction(rel.getCluster().getRexBuilder(), rejectedFilters); filter2 = RexUtil.apply(mapping, filter); final RelDataTypeFactory.Builder builder = rel.getCluster().getTypeFactory().builder(); final List<RelDataTypeField> fieldList = rel.getTable().getRowType().getFieldList();
final FileGroupScan newGroupScan = ((FileGroupScan)((DrillScanRel)scanRel).getGroupScan()).clone(newFileSelection); return new DrillScanRel(scanRel.getCluster(), scanRel.getTraitSet().plus(DrillRel.DRILL_LOGICAL), scanRel.getTable(),
new DrillScanRel(scan.getCluster(), scan.getTraitSet().plus(DrillRel.DRILL_LOGICAL), scan.getTable(),