Schema(TableScan scan) { HiveTableScan hts = (HiveTableScan) scan; String tabName = hts.getTableAlias(); for (RelDataTypeField field : scan.getRowType().getFieldList()) { add(new ColumnInfo(tabName, field.getName())); } }
private void fetchColStats(RelNode key, TableScan tableAccessRel, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) { final List<Integer> iRefSet = Lists.newArrayList(); if (key instanceof Project) { final Project project = (Project) key; for (RexNode rx : project.getChildExps()) { iRefSet.addAll(HiveCalciteUtil.getInputRefs(rx)); } } else { final int fieldCount = tableAccessRel.getRowType().getFieldCount(); if (fieldsUsed.equals(ImmutableBitSet.range(fieldCount)) && extraFields.isEmpty()) { // get all cols iRefSet.addAll(ImmutableBitSet.range(fieldCount).asList()); } } //Remove any virtual cols if (tableAccessRel instanceof HiveTableScan) { iRefSet.removeAll(((HiveTableScan)tableAccessRel).getVirtualCols()); } if (!iRefSet.isEmpty()) { final RelOptTable table = tableAccessRel.getTable(); if (table instanceof RelOptHiveTable) { ((RelOptHiveTable) table).getColStat(iRefSet, true); LOG.debug("Got col stats for {} in {}", iRefSet, tableAccessRel.getTable().getQualifiedName()); } } }
Schema(TableScan scan) { HiveTableScan hts = (HiveTableScan) scan; String tabName = hts.getTableAlias(); for (RelDataTypeField field : scan.getRowType().getFieldList()) { add(new ColumnInfo(tabName, field.getName())); } }
final int fieldCount = tableAccessRel.getRowType().getFieldCount(); if (fieldsUsed.equals(ImmutableBitSet.range(fieldCount)) && extraFields.isEmpty()) {
@Override public void onMatch(RelOptRuleCall call) { final Filter fil = call.rel(0); final TableScan rel = call.rel(1); // Add identity RelBuilder relBuilder = call.builder(); relBuilder.push(rel); List<RexNode> identityFields = relBuilder.fields( ImmutableBitSet.range(0, rel.getRowType().getFieldCount()).asList()); RelNode newRel = relBuilder .project(identityFields, ImmutableList.<String>of(), true) .build(); call.transformTo(fil.copy(fil.getTraitSet(), ImmutableList.of(newRel))); }
public List<Double> averageColumnSizes(TableScan rel, RelMetadataQuery mq) { final List<RelDataTypeField> fields = rel.getRowType().getFieldList(); final ImmutableList.Builder<Double> list = ImmutableList.builder(); for (RelDataTypeField field : fields) { list.add(averageTypeValueSize(field.getType())); } return list.build(); }
public List<Double> averageColumnSizes(TableScan rel, RelMetadataQuery mq) { final List<RelDataTypeField> fields = rel.getRowType().getFieldList(); final ImmutableList.Builder<Double> list = ImmutableList.builder(); for (RelDataTypeField field : fields) { list.add(averageTypeValueSize(field.getType())); } return list.build(); }
public Mappings.TargetMapping mapping() { return mapping != null ? mapping : Mappings.createIdentity(scan.getRowType().getFieldCount()); }
public Mappings.TargetMapping mapping() { return mapping != null ? mapping : Mappings.createIdentity(scan.getRowType().getFieldCount()); }
public Set<RelColumnOrigin> getColumnOrigins(TableScan tableScan, RelMetadataQuery mq, int iOutputColumn) { final Set<RelColumnOrigin> set = new HashSet<>(); RelOptTable table = tableScan.getTable(); if (table == null) { return null; } if (table.getRowType() != tableScan.getRowType()) { String columnName = tableScan.getRowType().getFieldNames().get(iOutputColumn); int newOutputColumn = 0; for (String tableCol : table.getRowType().getFieldNames()) { if (tableCol.equals(columnName)) { set.add(new RelColumnOrigin(table, newOutputColumn, false)); return set; } newOutputColumn++; } } else { set.add(new RelColumnOrigin(table, iOutputColumn, false)); } return set; }
Schema(TableScan scan) { String tabName = ((HiveTableScan) scan).getTableAlias(); for (RelDataTypeField field : scan.getRowType().getFieldList()) { add(new ColumnInfo(tabName, field.getName())); } }
/** * 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); }
public void rewriteRel(TableScan rel) { RelNode newRel = rel.getTable().toRel(toRelContext); if (!SqlTypeUtil.isFlat(rel.getRowType())) { final List<Pair<RexNode, String>> flattenedExpList = new ArrayList<>(); flattenInputs(rel.getRowType().getFieldList(), rexBuilder.makeRangeReference(newRel), flattenedExpList); newRel = relBuilder.push(newRel) .projectNamed(Pair.left(flattenedExpList), Pair.right(flattenedExpList), true) .build(); } setNewForOldRel(rel, newRel); }
public void rewriteRel(TableScan rel) { RelNode newRel = rel.getTable().toRel(toRelContext); if (!SqlTypeUtil.isFlat(rel.getRowType())) { final List<Pair<RexNode, String>> flattenedExpList = new ArrayList<>(); flattenInputs(rel.getRowType().getFieldList(), rexBuilder.makeRangeReference(newRel), flattenedExpList); newRel = relBuilder.push(newRel) .projectNamed(Pair.left(flattenedExpList), Pair.right(flattenedExpList), true) .build(); } setNewForOldRel(rel, newRel); }
/** * 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, Filter filter, TableScan scan) { //Avoid optimizing already optimized scan if (scan instanceof QuarkViewScan || scan instanceof QuarkTileScan) { return; } RelNode root = filter.copy(filter.getTraitSet(), Collections.singletonList((RelNode) scan)); RelOptPlanner planner = call.getPlanner(); if (planner instanceof VolcanoPlanner) { List<RelOptMaterialization> materializations = ((VolcanoPlanner) planner).getMaterializations(); for (RelOptMaterialization materialization : materializations) { if (scan.getRowType().equals(materialization.queryRel.getRowType())) { RelNode target = materialization.queryRel; final HepPlanner hepPlanner = new HepPlanner(program, planner.getContext()); hepPlanner.setRoot(target); target = hepPlanner.findBestExp(); List<RelNode> subs = new MaterializedViewSubstitutionVisitor(target, root) .go(materialization.tableRel); for (RelNode s : subs) { call.transformTo(s); } } } } } }
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) { final RelOptPlanner planner = call.getPlanner(); final List<RelOptMaterialization> materializations = planner.getMaterializations(); if (!materializations.isEmpty()) { RelNode root = filter.copy(filter.getTraitSet(), Collections.singletonList((RelNode) scan)); List<RelOptMaterialization> applicableMaterializations = RelOptMaterializations.getApplicableMaterializations(root, materializations); for (RelOptMaterialization materialization : applicableMaterializations) { if (RelOptUtil.areRowTypesEqual(scan.getRowType(), materialization.queryRel.getRowType(), false)) { RelNode target = materialization.queryRel; final HepPlanner hepPlanner = new HepPlanner(program, planner.getContext()); hepPlanner.setRoot(target); target = hepPlanner.findBestExp(); List<RelNode> subs = new MaterializedViewSubstitutionVisitor(target, root) .go(materialization.tableRel); for (RelNode s : subs) { call.transformTo(s); } } } } } }
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) { final RelOptPlanner planner = call.getPlanner(); final List<RelOptMaterialization> materializations = planner.getMaterializations(); if (!materializations.isEmpty()) { RelNode root = filter.copy(filter.getTraitSet(), Collections.singletonList((RelNode) scan)); List<RelOptMaterialization> applicableMaterializations = RelOptMaterializations.getApplicableMaterializations(root, materializations); for (RelOptMaterialization materialization : applicableMaterializations) { if (RelOptUtil.areRowTypesEqual(scan.getRowType(), materialization.queryRel.getRowType(), false)) { RelNode target = materialization.queryRel; final HepPlanner hepPlanner = new HepPlanner(program, planner.getContext()); hepPlanner.setRoot(target); target = hepPlanner.findBestExp(); List<RelNode> subs = new MaterializedViewSubstitutionVisitor(target, root) .go(materialization.tableRel); for (RelNode s : subs) { call.transformTo(s); } } } } } }
ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) { final int fieldCount = tableAccessRel.getRowType().getFieldCount(); if (fieldsUsed.equals(ImmutableBitSet.range(fieldCount)) && extraFields.isEmpty()) {
if (scan.getRowType().getFieldList().isEmpty()) { return; ProjectPushInfo projectPushInfo = DrillRelOptUtil.getFieldsInformation(scan.getRowType(), project.getProjects()); if (!canPushProjectIntoScan(scan.getTable(), projectPushInfo)) { return;