public static List<RexNode> getProjsFromBelowAsInputRef(final RelNode rel) { List<RexNode> projectList = Lists.transform(rel.getRowType().getFieldList(), new Function<RelDataTypeField, RexNode>() { @Override public RexNode apply(RelDataTypeField field) { return rel.getCluster().getRexBuilder().makeInputRef(field.getType(), field.getIndex()); } }); return projectList; }
private RelDataType getFieldType(RelNode relNode, int i) { final RelDataTypeField inputField = relNode.getRowType().getFieldList().get(i); return inputField.getType(); }
public static List<String> getFieldNames(List<Integer> inputRefs, RelNode inputRel) { List<String> fieldNames = new ArrayList<String>(); List<String> schemaNames = inputRel.getRowType().getFieldNames(); for (Integer iRef : inputRefs) { fieldNames.add(schemaNames.get(iRef)); } return fieldNames; }
public static HiveProject createProjectWithoutColumn(RelNode input, Set<Integer> positions) throws CalciteSemanticException { List<RexNode> originalInputRefs = Lists.transform(input.getRowType().getFieldList(), new Function<RelDataTypeField, RexNode>() { @Override public RexNode apply(RelDataTypeField input) { return new RexInputRef(input.getIndex(), input.getType()); } }); List<RexNode> copyInputRefs = new ArrayList<>(); for (int i = 0; i < originalInputRefs.size(); i++) { if (!positions.contains(i)) { copyInputRefs.add(originalInputRefs.get(i)); } } return HiveProject.create(input, copyInputRefs, null); }
Stream<Values> inputStream = planCreator.pop(); RelDataType inputRowType = getInput(0).getRowType(); int outputCount = outputFieldNames.size(); List<RexNode> expandedNodes = new ArrayList<>(); for (RexLocalRef project : projectList) { expandedNodes.add(program.expandLocalRef(project));
RexNodeConverter converter = new RexNodeConverter(this.cluster, srcRel.getRowType(), posMap, 0, false); Builder<RexNode> calciteAggFnArgsBldr = ImmutableList.<RexNode> builder(); Builder<RelDataType> calciteAggFnArgsTypeBldr = ImmutableList.<RelDataType> builder(); for (int i = 0; i < hiveAggInfo.m_aggParams.size(); i++) { calciteAggFnArgsBldr.add(converter.convert(hiveAggInfo.m_aggParams.get(i))); calciteAggFnArgsTypeBldr.add(TypeConverter.convert(hiveAggInfo.m_aggParams.get(i) .getTypeInfo(), this.cluster.getTypeFactory()));
public static RexNode convert(RelOptCluster cluster, ExprNodeDesc joinCondnExprNode, List<RelNode> inputRels, LinkedHashMap<RelNode, RowResolver> relToHiveRR, Map<RelNode, ImmutableMap<String, Integer>> relToHiveColNameCalcitePosMap, boolean flattenExpr) throws SemanticException { List<InputCtx> inputCtxLst = new ArrayList<InputCtx>(); int offSet = 0; for (RelNode r : inputRels) { inputCtxLst.add(new InputCtx(r.getRowType(), relToHiveColNameCalcitePosMap.get(r), relToHiveRR .get(r), offSet)); offSet += r.getRowType().getFieldCount(); } return (new RexNodeConverter(cluster, inputCtxLst, flattenExpr)).convert(joinCondnExprNode); } }
/** * Projects all {@code input} output fields plus the additional expressions. * * @param input Input relational expression * @param additionalExprs Additional expressions and names * @return the new Project */ private RelNode createProjectWithAdditionalExprs( RelNode input, List<Pair<RexNode, String>> additionalExprs) { final List<RelDataTypeField> fieldList = input.getRowType().getFieldList(); List<Pair<RexNode, String>> projects = Lists.newArrayList(); for (Ord<RelDataTypeField> field : Ord.zip(fieldList)) { projects.add( Pair.of( (RexNode) rexBuilder.makeInputRef( field.e.getType(), field.i), field.e.getName())); } projects.addAll(additionalExprs); return RelOptUtil.createProject(input, Pair.left(projects), Pair.right(projects), false, relBuilder); }
RelDataTypeField field = getInput().getRowType().getField(func.getRewriteFieldName(), true, false); if (newArgList.isEmpty()) { newArgList.add(field.getIndex()); } else {
this.joinRel = joinRel; this.isSemiJoin = isSemiJoin; nFieldsLeft = joinRel.getLeft().getRowType().getFieldList().size(); nFieldsRight = joinRel.getRight().getRowType().getFieldList().size(); nSysFields = joinRel.getSystemFieldList().size(); leftFieldsBitSet = ImmutableBitSet.range(nSysFields, nSysFields + nFieldsLeft);
@Override public void streamsPlan(StreamsPlanCreator planCreator) throws Exception { // SingleRel RelNode input = getInput(); StormRelUtils.getStormRelInput(input).streamsPlan(planCreator); Stream<Values> inputStream = planCreator.pop(); String projectionClassName = StormRelUtils.getClassName(this); List<String> outputFieldNames = getRowType().getFieldNames(); int outputCount = outputFieldNames.size(); List<RexNode> childExps = getChildExps(); RelDataType inputRowType = getInput(0).getRowType(); ExecutableExpression projectionInstance = planCreator.createScalarInstance(childExps, inputRowType, projectionClassName); EvaluationFunction evalFunc = new EvaluationFunction(projectionInstance, outputCount, planCreator.getDataContext()); final Stream<Values> finalStream = inputStream.map(evalFunc); planCreator.addStream(finalStream); } }
/** Infers the alias of an expression. * * <p>If the expression was created by {@link #alias}, replaces the expression * in the project list. */ private String inferAlias(List<RexNode> exprList, RexNode expr) { switch (expr.getKind()) { case INPUT_REF: final RexInputRef ref = (RexInputRef) expr; return peek(0).getRowType().getFieldNames().get(ref.getIndex()); case CAST: return inferAlias(exprList, ((RexCall) expr).getOperands().get(0)); case AS: final RexCall call = (RexCall) expr; for (;;) { final int i = exprList.indexOf(expr); if (i < 0) { break; } exprList.set(i, call.getOperands().get(0)); } return ((NlsString) ((RexLiteral) call.getOperands().get(1)).getValue()) .getValue(); default: return null; } }
/** Returns a reference to a particular field, by offset, across several * inputs on a {@link RelBuilder}'s stack. */ private RexInputRef field(HiveSubQRemoveRelBuilder builder, int inputCount, int offset) { for (int inputOrdinal = 0;;) { final RelNode r = builder.peek(inputCount, inputOrdinal); if (offset < r.getRowType().getFieldCount()) { return builder.field(inputCount, inputOrdinal, offset); } ++inputOrdinal; offset -= r.getRowType().getFieldCount(); } }
public static HiveProject createProjectWithoutColumn(RelNode input, Set<Integer> positions) throws CalciteSemanticException { List<RexNode> originalInputRefs = Lists.transform(input.getRowType().getFieldList(), new Function<RelDataTypeField, RexNode>() { @Override public RexNode apply(RelDataTypeField input) { return new RexInputRef(input.getIndex(), input.getType()); } }); List<RexNode> copyInputRefs = new ArrayList<>(); for (int i = 0; i < originalInputRefs.size(); i++) { if (!positions.contains(i)) { copyInputRefs.add(originalInputRefs.get(i)); } } return HiveProject.create(input, copyInputRefs, null); }
public static List<String> getFieldNames(List<Integer> inputRefs, RelNode inputRel) { List<String> fieldNames = new ArrayList<String>(); List<String> schemaNames = inputRel.getRowType().getFieldNames(); for (Integer iRef : inputRefs) { fieldNames.add(schemaNames.get(iRef)); } return fieldNames; }
public static RexNode convert(RelOptCluster cluster, ExprNodeDesc joinCondnExprNode, List<RelNode> inputRels, LinkedHashMap<RelNode, RowResolver> relToHiveRR, Map<RelNode, ImmutableMap<String, Integer>> relToHiveColNameCalcitePosMap, boolean flattenExpr) throws SemanticException { List<InputCtx> inputCtxLst = new ArrayList<InputCtx>(); int offSet = 0; for (RelNode r : inputRels) { inputCtxLst.add(new InputCtx(r.getRowType(), relToHiveColNameCalcitePosMap.get(r), relToHiveRR .get(r), offSet)); offSet += r.getRowType().getFieldCount(); } return (new RexNodeConverter(cluster, inputCtxLst, flattenExpr)).convert(joinCondnExprNode); } }
/** * Projects all {@code input} output fields plus the additional expressions. * * @param input Input relational expression * @param additionalExprs Additional expressions and names * @return the new LogicalProject */ private RelNode createProjectWithAdditionalExprs( RelNode input, List<Pair<RexNode, String>> additionalExprs) { final List<RelDataTypeField> fieldList = input.getRowType().getFieldList(); List<Pair<RexNode, String>> projects = Lists.newArrayList(); for (Ord<RelDataTypeField> field : Ord.zip(fieldList)) { projects.add( Pair.of( (RexNode) rexBuilder.makeInputRef( field.e.getType(), field.i), field.e.getName())); } projects.addAll(additionalExprs); return RelOptUtil.createProject(input, projects, false); }
public static ImmutableList<RexNode> getInputRef(List<Integer> inputRefs, RelNode inputRel) { ImmutableList.Builder<RexNode> bldr = ImmutableList.<RexNode> builder(); for (int i : inputRefs) { bldr.add(new RexInputRef(i, inputRel.getRowType().getFieldList().get(i).getType())); } return bldr.build(); }
@Override public EnumerableRel implementEnumerable(List<EnumerableRel> inputs) { if (getInput() instanceof OLAPFilterRel) { // merge project & filter OLAPFilterRel filter = (OLAPFilterRel) getInput(); RelNode inputOfFilter = inputs.get(0).getInput(0); RexProgram program = RexProgram.create(inputOfFilter.getRowType(), this.rewriteProjects, filter.getCondition(), this.rowType, getCluster().getRexBuilder()); return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), // inputOfFilter, program); } else { // keep project for table scan EnumerableRel input = sole(inputs); RexProgram program = RexProgram.create(input.getRowType(), this.rewriteProjects, null, this.rowType, getCluster().getRexBuilder()); return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), // input, program); } }
/** Returns the number of fields in all inputs before (to the left of) * the given input. * * @param inputCount Number of inputs * @param inputOrdinal Input ordinal */ private int inputOffset(int inputCount, int inputOrdinal) { int offset = 0; for (int i = 0; i < inputOrdinal; i++) { offset += peek(inputCount, i).getRowType().getFieldCount(); } return offset; }