/** * Returns the index of the first field in <code>rel</code> which comes from its <code>ordinal * </code>th input. * * <p>For example, if rel joins T0(A,B,C) to T1(D,E), then countFields(0,rel) yields 0, and * countFields(1,rel) yields 3. */ private int computeFieldOffset(RelNode rel, int ordinal) { if (ordinal == 0) { // short-circuit for the common case return 0; } int fieldOffset = 0; final List<RelNode> inputs = rel.getInputs(); for (int i = 0; i < ordinal; i++) { RelNode input = inputs.get(i); fieldOffset += input.getRowType().getFieldList().size(); } return fieldOffset; }
/** * Returns the variable which, in the generated program, will hold the current row of a given * relational expression. This method is only applicable if the relational expression is the * current one or an input; if it is an ancestor, there is no current value, and this method * returns null. */ public Variable findInputVariable(RelNode rel) { while (true) { JavaFrame frame = (JavaFrame) mapRel2Frame.get(rel); if ((frame != null) && frame.hasVariable()) { return frame.getVariable(); } List<RelNode> inputs = rel.getInputs(); if (inputs.size() == 1) { rel = inputs.get(0); } else { return null; } } }
private JavaFrame findFrame() { RelNode previous = rel; while (true) { JavaFrame frame = (JavaFrame) mapRel2Frame.get(previous); if (frame.bind != null) { tracer.log( Level.FINE, "Bind " + rel.toString() + " to " + previous.toString() + "(" + frame.bind + ")"); return frame; } // go deeper List<RelNode> inputs = previous.getInputs(); assert (inputs.size() == 1) : "input is not bound"; previous = inputs.get(0); } }
protected void explain_(RelNode rel, List<Pair<String, Object>> values) { final Map<String, Object> map = jsonBuilder.map(); map.put("id", null); // ensure that id is the first attribute map.put("relOp", relJson.classToTypeName(rel.getClass())); for (Pair<String, Object> value : values) { if (value.right instanceof RelNode) { continue; } put(map, value.left, value.right); } // omit 'inputs: ["3"]' if "3" is the preceding rel final List<Object> list = explainInputs(rel.getInputs()); if (list.size() != 1 || !list.get(0).equals(previousId)) { map.put("inputs", list); } final String id = Integer.toString(relIdMap.size()); relIdMap.put(rel, id); map.put("id", id); relList.add(map); previousId = id; }