protected void doPushLimitIntoGroupScan(RelOptRuleCall call, LimitPrel limit, final ProjectPrel project, ScanPrel scan, GroupScan groupScan) { try { final GroupScan newGroupScan = getGroupScanWithLimit(groupScan, limit); if (newGroupScan == null) { return; } final ScanPrel newScan = new ScanPrel(scan.getCluster(), scan.getTraitSet(), newGroupScan, scan.getRowType(), scan.getTable()); final RelNode newChild; if (project != null) { final ProjectPrel newProject = new ProjectPrel(project.getCluster(), project.getTraitSet(), newScan, project.getProjects(), project.getRowType()); newChild = newProject; } else { newChild = newScan; } call.transformTo(newChild); logger.debug("pushLimitIntoGroupScan: Converted to a new ScanPrel " + newScan.getGroupScan()); } catch (Exception e) { logger.warn("pushLimitIntoGroupScan: Exception while trying limit pushdown!", e); } }
@Override public void onMatch(RelOptRuleCall call) { final ScanPrel scan = call.rel(1); final FilterPrel filter = call.rel(0); final RexNode condition = filter.getCondition(); LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan, condition); KafkaGroupScan groupScan = (KafkaGroupScan) scan.getGroupScan(); logger.info("Partitions ScanSpec before pushdown: " + groupScan.getPartitionScanSpecList()); KafkaPartitionScanSpecBuilder builder = new KafkaPartitionScanSpecBuilder(groupScan, conditionExp); List<KafkaPartitionScanSpec> newScanSpec = null; newScanSpec = builder.parseTree(); builder.close(); //Close consumer //No pushdown if(newScanSpec == null) { return; } logger.info("Partitions ScanSpec after pushdown: " + newScanSpec); GroupScan newGroupScan = groupScan.cloneWithNewSpec(newScanSpec); final ScanPrel newScanPrel = new ScanPrel(scan.getCluster(), filter.getTraitSet(), newGroupScan, scan.getRowType(), scan.getTable()); call.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of(newScanPrel))); }
DrillRelOptUtil.getFieldsInformation(scan.getRowType(), project.getProjects()); if (columnInfo == null || Utilities.isStarQuery(columnInfo.getFields()) || !groupScan.canPushdownProjects(columnInfo.getFields())) { sameRowTypeProjectionsFields(project.getRowType(), newScan.getRowType())) { call.transformTo(newScan); } else {
protected void doPushFilterToScan(final RelOptRuleCall call, final FilterPrel filter, final ProjectPrel project, final ScanPrel scan, final HBaseGroupScan groupScan, final RexNode condition) { final LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan, condition); final HBaseFilterBuilder hbaseFilterBuilder = new HBaseFilterBuilder(groupScan, conditionExp); final HBaseScanSpec newScanSpec = hbaseFilterBuilder.parseTree(); if (newScanSpec == null) { return; //no filter pushdown ==> No transformation. } final HBaseGroupScan newGroupsScan = new HBaseGroupScan(groupScan.getUserName(), groupScan.getStoragePlugin(), newScanSpec, groupScan.getColumns()); newGroupsScan.setFilterPushedDown(true); final ScanPrel newScanPrel = new ScanPrel(scan.getCluster(), filter.getTraitSet(), newGroupsScan, scan.getRowType(), scan.getTable()); // Depending on whether is a project in the middle, assign either scan or copy of project to childRel. final RelNode childRel = project == null ? newScanPrel : project.copy(project.getTraitSet(), ImmutableList.of(newScanPrel)); if (hbaseFilterBuilder.isAllExpressionsConverted()) { /* * Since we could convert the entire filter condition expression into an HBase filter, * we can eliminate the filter operator altogether. */ call.transformTo(childRel); } else { call.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of(childRel))); } }
newGroupsScan.setFilterPushedDown(true); final ScanPrel newScanPrel = new ScanPrel(scan.getCluster(), filter.getTraitSet(), newGroupsScan, scan.getRowType(), scan.getTable());
newGroupsScan.setFilterPushedDown(true); final ScanPrel newScanPrel = new ScanPrel(scan.getCluster(), filter.getTraitSet(), newGroupsScan, scan.getRowType(), scan.getTable());
RelDataTypeField f = indexContext.scan.getRowType().getFieldList().get(idx); String pathSeg = f.getName().replaceAll("`", ""); final String[] segs = pathSeg.split("\\.");
protected void doPushLimitIntoGroupScan(RelOptRuleCall call, LimitPrel limit, final ProjectPrel project, ScanPrel scan, GroupScan groupScan) { try { final GroupScan newGroupScan = getGroupScanWithLimit(groupScan, limit); if (newGroupScan == null) { return; } final ScanPrel newScan = new ScanPrel(scan.getCluster(), scan.getTraitSet(), newGroupScan, scan.getRowType(), scan.getTable()); final RelNode newChild; if (project != null) { final ProjectPrel newProject = new ProjectPrel(project.getCluster(), project.getTraitSet(), newScan, project.getProjects(), project.getRowType()); newChild = newProject; } else { newChild = newScan; } call.transformTo(newChild); logger.debug("pushLimitIntoGroupScan: Converted to a new ScanPrel " + newScan.getGroupScan()); } catch (Exception e) { logger.warn("pushLimitIntoGroupScan: Exception while trying limit pushdown!", e); } }
RelDataType scanRowType = scanPrel.getRowType(); RelDataTypeField field = scanRowType.getField(leftFieldName, true, true); int index = field.getIndex();
int rowKeyIndex = getRowKeyIndex(indexScanPrel.getRowType(), origScan); assert rowKeyIndex >= 0; indexProjectExprs.add(RexInputRef.of(rowKeyIndex, indexScanPrel.getRowType())); final List<RelDataTypeField> indexScanFields = indexScanPrel.getRowType().getFieldList();
int leftRowKeyIndex = getRowKeyIndex(dbScan.getRowType(), origScan); final RelDataTypeField leftRowKeyField = dbScan.getRowType().getFieldList().get(leftRowKeyIndex); final RelDataTypeFactory.FieldInfoBuilder leftFieldTypeBuilder = dbScan.getCluster().getTypeFactory().builder(); leftProjectExprs.add(RexInputRef.of(leftRowKeyIndex, dbScan.getRowType()));
@Override public RelOptCost computeSelfCost(final RelOptPlanner planner, RelMetadataQuery mq) { final PlannerSettings settings = PrelUtil.getPlannerSettings(planner); final ScanStats stats = this.getGroupScan().getScanStats(settings); final int columnCount = this.getRowType().getFieldCount(); if(PrelUtil.getSettings(getCluster()).useDefaultCosting()) { return planner.getCostFactory().makeCost(stats.getRecordCount() * columnCount, stats.getCpuCost(), stats.getDiskCost()); } // double rowCount = RelMetadataQuery.getRowCount(this); double rowCount = stats.getRecordCount(); // As DRILL-4083 points out, when columnCount == 0, cpuCost becomes zero, // which makes the costs of HiveScan and HiveDrillNativeParquetScan the same double cpuCost = rowCount * Math.max(columnCount, 1); // For now, assume cpu cost is proportional to row count. // If a positive value for CPU cost is given multiply the default CPU cost by given CPU cost. if (stats.getCpuCost() > 0) { cpuCost *= stats.getCpuCost(); } double ioCost = stats.getDiskCost(); DrillCostFactory costFactory = (DrillCostFactory)planner.getCostFactory(); return costFactory.makeCost(rowCount, cpuCost, ioCost, 0); }
selector.addIndex(indexDesc, true, indexContext.lowerProject != null ? indexContext.lowerProject.getRowType().getFieldCount() : indexContext.scan.getRowType().getFieldCount());
DrillRelOptUtil.getFieldsInformation(scan.getRowType(), project.getProjects()); if (columnInfo == null || Utilities.isStarQuery(columnInfo.getFields()) || !groupScan.canPushdownProjects(columnInfo.getFields())) { sameRowTypeProjectionsFields(project.getRowType(), newScan.getRowType())) { call.transformTo(newScan); } else {
rewriteFunctionalCondition(coveringCondition, indexScanPrel.getRowType(), functionInfo); DrillParseContext parseContxt = new DrillParseContext(PrelUtil.getPlannerSettings(newProject.getCluster())); for(RexNode projectRex: newProject.getProjects()) { RexNode newRex = IndexPlanUtils.rewriteFunctionalRex(indexContext, parseContxt, null, origScan, projectRex, indexScanPrel.getRowType(), functionInfo); newProjects.add(newRex);
for(RexNode projectRex: newProject.getProjects()) { RexNode newRex = IndexPlanUtils.rewriteFunctionalRex(indexContext, parseContxt, null, origScan, projectRex, indexScanPrel.getRowType(), functionInfo); newProjects.add(newRex);
protected void doPushFilterToScan(final RelOptRuleCall call, final FilterPrel filter, final ProjectPrel project, final ScanPrel scan, final HBaseGroupScan groupScan, final RexNode condition) { final LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan, condition); final HBaseFilterBuilder hbaseFilterBuilder = new HBaseFilterBuilder(groupScan, conditionExp); final HBaseScanSpec newScanSpec = hbaseFilterBuilder.parseTree(); if (newScanSpec == null) { return; //no filter pushdown ==> No transformation. } final HBaseGroupScan newGroupsScan = new HBaseGroupScan(groupScan.getUserName(), groupScan.getStoragePlugin(), newScanSpec, groupScan.getColumns()); newGroupsScan.setFilterPushedDown(true); final ScanPrel newScanPrel = new ScanPrel(scan.getCluster(), filter.getTraitSet(), newGroupsScan, scan.getRowType(), scan.getTable()); // Depending on whether is a project in the middle, assign either scan or copy of project to childRel. final RelNode childRel = project == null ? newScanPrel : project.copy(project.getTraitSet(), ImmutableList.of(newScanPrel)); if (hbaseFilterBuilder.isAllExpressionsConverted()) { /* * Since we could convert the entire filter condition expression into an HBase filter, * we can eliminate the filter operator altogether. */ call.transformTo(childRel); } else { call.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of(childRel))); } }
newGroupsScan.setFilterPushedDown(true); final ScanPrel newScanPrel = new ScanPrel(scan.getCluster(), filter.getTraitSet(), newGroupsScan, scan.getRowType(), scan.getTable());
newGroupsScan.setFilterPushedDown(true); RelNode input = new ScanPrel(scan.getCluster(), filter.getTraitSet(), newGroupsScan, scan.getRowType(), scan.getTable()); if (project != null) { input = project.copy(project.getTraitSet(), input, project.getProjects(), filter.getRowType());
newGroupsScan.setFilterPushedDown(true); final ScanPrel newScanPrel = new ScanPrel(scan.getCluster(), filter.getTraitSet(), newGroupsScan, scan.getRowType(), scan.getTable());