@Override public LogicalExpression visitInputRef(RexInputRef inputRef) { final int index = inputRef.getIndex(); final RelDataTypeField field = fieldList.get(index); return FieldReference.getWithQuotedRef(field.getName()); }
public static Map<LogicalExpression, Integer> getExprsFromRowType( RelDataType indexScanRowType) { Map<LogicalExpression, Integer> rowTypeExprs = Maps.newLinkedHashMap(); int idx = 0; for (RelDataTypeField field : indexScanRowType.getFieldList()) { rowTypeExprs.put(FieldReference.getWithQuotedRef(field.getName()), idx++); } return rowTypeExprs; }
protected LogicalExpression toDrill(AggregateCall call, List<String> fn) { List<LogicalExpression> args = Lists.newArrayList(); for (Integer i : call.getArgList()) { args.add(FieldReference.getWithQuotedRef(fn.get(i))); } // for count(1). if (args.isEmpty()) { args.add(new ValueExpressions.LongExpression(1L)); } return new FunctionCall(call.getAggregation().getName().toLowerCase(), args, ExpressionPosition.UNKNOWN); }
/** * Build the list of join conditions for this join. * A join condition is built only for equality and IS NOT DISTINCT FROM comparisons. The difference is: * null == null is FALSE whereas null IS NOT DISTINCT FROM null is TRUE * For a use case of the IS NOT DISTINCT FROM comparison, see * {@link org.apache.calcite.rel.rules.AggregateRemoveRule} * @param conditions populated list of join conditions * @param leftFields join fields from the left input * @param rightFields join fields from the right input */ protected void buildJoinConditions(List<JoinCondition> conditions, List<String> leftFields, List<String> rightFields, List<Integer> leftKeys, List<Integer> rightKeys) { List<RexNode> conjuncts = RelOptUtil.conjunctions(this.getCondition()); short i=0; for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) { final RexNode conditionExpr = conjuncts.get(i++); final SqlKind kind = conditionExpr.getKind(); if (kind != SqlKind.EQUALS && kind != SqlKind.IS_NOT_DISTINCT_FROM) { throw UserException.unsupportedError() .message("Unsupported comparator in join condition %s", conditionExpr) .build(logger); } conditions.add(new JoinCondition(kind.toString(), FieldReference.getWithQuotedRef(leftFields.get(pair.left)), FieldReference.getWithQuotedRef(rightFields.get(pair.right)))); } }
@Override protected List<NamedExpression> getProjectExpressions(DrillParseContext context) { List<NamedExpression> expressions = Lists.newArrayList(); for (Pair<RexNode, String> pair : Pair.zip(exps, getRowType().getFieldNames())) { LogicalExpression expr = DrillOptiq.toDrill(context, getInput(), pair.left); expressions.add(new NamedExpression(expr, FieldReference.getWithQuotedRef(pair.right))); } return expressions; }
@Override public LogicalExpression visitInputRef(RexInputRef inputRef) { final int index = inputRef.getIndex(); //no extra project in between of input and this layer if(project == null) { final RelDataTypeField field = getRowType().getFieldList().get(index); return addExprToRexs(FieldReference.getWithQuotedRef(field.getName()), inputRef); } //get the actual expression of this projected rex RexNode rex = IndexPlanUtils.getProjects(project).get(index); return addExprToRexs(rex.accept(projectToInput), inputRef); }
protected List<NamedExpression> getProjectExpressions(DrillParseContext context) { List<NamedExpression> expressions = Lists.newArrayList(); HashMap<String, String> starColPrefixes = new HashMap<>(); // T1.* will subsume T1.*0, but will not subsume any regular column/expression. // Select *, col1, *, col2 : the intermediate will output one set of regular columns expanded from star with prefix, // plus col1 and col2 without prefix. // This will allow us to differentiate the regular expanded from *, and the regular column referenced in the query. for (Pair<RexNode, String> pair : projects()) { if (StarColumnHelper.isPrefixedStarColumn(pair.right)) { String prefix = StarColumnHelper.extractStarColumnPrefix(pair.right); if (! starColPrefixes.containsKey(prefix)) { starColPrefixes.put(prefix, pair.right); } } } for (Pair<RexNode, String> pair : projects()) { if (! StarColumnHelper.subsumeColumn(starColPrefixes, pair.right)) { LogicalExpression expr = DrillOptiq.toDrill(context, getInput(), pair.left); expressions.add(new NamedExpression(expr, FieldReference.getWithQuotedRef(pair.right))); } } return expressions; }
RelDataTypeField f2 = rsFields.get(j); if (f1.getName().equals(f2.getName())) { FieldReference ref = FieldReference.getWithQuotedRef(f1.getName()); RelFieldCollation origCollation = collationMap.get(ref); if (origCollation != null) {
FieldReference fr = FieldReference.getWithQuotedRef(childFields.get(group)); keys.add(new NamedExpression(fr, fr)); FieldReference ref = FieldReference.getWithQuotedRef(fields.get(aggExprOrdinal)); LogicalExpression expr = toDrill(aggCall.e, childFields); NamedExpression ne = new NamedExpression(expr, ref);
protected RelNode createRangeDistRight(final RelNode rightPrel, final RelDataTypeField rightRowKeyField, final DbGroupScan origDbGroupScan) { List<DrillDistributionTrait.DistributionField> rangeDistFields = Lists.newArrayList(new DrillDistributionTrait.DistributionField(0 /* rowkey ordinal on the right side */)); FieldReference rangeDistRef = FieldReference.getWithQuotedRef(rightRowKeyField.getName()); List<FieldReference> rangeDistRefList = Lists.newArrayList(); rangeDistRefList.add(rangeDistRef); final DrillDistributionTrait distRight; if (IndexPlanUtils.scanIsPartition(origDbGroupScan)) { distRight = new DrillDistributionTrait( DrillDistributionTrait.DistributionType.RANGE_DISTRIBUTED, ImmutableList.copyOf(rangeDistFields), origDbGroupScan.getRangePartitionFunction(rangeDistRefList)); } else { distRight = DrillDistributionTrait.SINGLETON; } RelTraitSet rightTraits = newTraitSet(distRight).plus(Prel.DRILL_PHYSICAL); RelNode convertedRight = Prule.convert(rightPrel, rightTraits); return convertedRight; }
List<FieldReference> rangeDistRefList = Lists.newArrayList(); FieldReference rangeDistRef = FieldReference.getWithQuotedRef(right.getRowType().getFieldList().get(joinKeyRight).getName()); rangeDistRefList.add(rangeDistRef); RelNode leftScan = DrillPushRowKeyJoinToScanRule.getValidJoinInput(left);