Java Code Examples for org.apache.calcite.rel.RelNode#getRelTypeName()

The following examples show how to use org.apache.calcite.rel.RelNode#getRelTypeName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RelXmlWriter.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Generates specific XML (sometimes called 'attribute-oriented XML'). Like
 * this:
 *
 * <blockquote><pre>
 * &lt;Join condition="EMP.DEPTNO = DEPT.DEPTNO"&gt;
 *   &lt;Project expr1="x + y" expr2="42"&gt;
 *   &lt;TableAccess table="SALES.EMPS"&gt;
 * &lt;/Join&gt;
 * </pre></blockquote>
 *
 * @param rel    Relational expression
 * @param values List of term-value pairs
 */
private void explainSpecific(
    RelNode rel,
    List<Pair<String, Object>> values) {
  String tagName = rel.getRelTypeName();
  xmlOutput.beginBeginTag(tagName);
  xmlOutput.attribute("id", rel.getId() + "");

  for (Pair<String, Object> value : values) {
    if (value.right instanceof RelNode) {
      continue;
    }
    xmlOutput.attribute(
        value.left,
        value.right.toString());
  }
  xmlOutput.endBeginTag(tagName);
  spacer.add(2);
  for (RelNode input : rel.getInputs()) {
    input.explain(this);
  }
  spacer.subtract(2);
}
 
Example 2
Source File: RelXmlWriter.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Generates specific XML (sometimes called 'attribute-oriented XML'). Like
 * this:
 *
 * <blockquote><pre>
 * &lt;Join condition="EMP.DEPTNO = DEPT.DEPTNO"&gt;
 *   &lt;Project expr1="x + y" expr2="42"&gt;
 *   &lt;TableAccess table="SALES.EMPS"&gt;
 * &lt;/Join&gt;
 * </pre></blockquote>
 *
 * @param rel    Relational expression
 * @param values List of term-value pairs
 */
private void explainSpecific(
    RelNode rel,
    List<Pair<String, Object>> values) {
  String tagName = rel.getRelTypeName();
  xmlOutput.beginBeginTag(tagName);
  xmlOutput.attribute("id", rel.getId() + "");

  for (Pair<String, Object> value : values) {
    if (value.right instanceof RelNode) {
      continue;
    }
    xmlOutput.attribute(
        value.left,
        value.right.toString());
  }
  xmlOutput.endBeginTag(tagName);
  spacer.add(2);
  for (RelNode input : rel.getInputs()) {
    input.explain(this);
  }
  spacer.subtract(2);
}
 
Example 3
Source File: RelXmlWriter.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Generates generic XML (sometimes called 'element-oriented XML'). Like
 * this:
 *
 * <blockquote>
 * <code>
 * &lt;RelNode id="1" type="Join"&gt;<br>
 * &nbsp;&nbsp;&lt;Property name="condition"&gt;EMP.DEPTNO =
 * DEPT.DEPTNO&lt;/Property&gt;<br>
 * &nbsp;&nbsp;&lt;Inputs&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&lt;RelNode id="2" type="Project"&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Property name="expr1"&gt;x +
 * y&lt;/Property&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Property
 * name="expr2"&gt;45&lt;/Property&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&lt;/RelNode&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&lt;RelNode id="3" type="TableAccess"&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Property
 * name="table"&gt;SALES.EMP&lt;/Property&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&lt;/RelNode&gt;<br>
 * &nbsp;&nbsp;&lt;/Inputs&gt;<br>
 * &lt;/RelNode&gt;</code>
 * </blockquote>
 *
 * @param rel    Relational expression
 * @param values List of term-value pairs
 */
private void explainGeneric(
    RelNode rel,
    List<Pair<String, Object>> values) {
  String relType = rel.getRelTypeName();
  xmlOutput.beginBeginTag("RelNode");
  xmlOutput.attribute("type", relType);

  xmlOutput.endBeginTag("RelNode");

  final List<RelNode> inputs = new ArrayList<>();
  for (Pair<String, Object> pair : values) {
    if (pair.right instanceof RelNode) {
      inputs.add((RelNode) pair.right);
      continue;
    }
    if (pair.right == null) {
      continue;
    }
    xmlOutput.beginBeginTag("Property");
    xmlOutput.attribute("name", pair.left);
    xmlOutput.endBeginTag("Property");
    xmlOutput.cdata(pair.right.toString());
    xmlOutput.endTag("Property");
  }
  xmlOutput.beginTag("Inputs", null);
  spacer.add(2);
  for (RelNode input : inputs) {
    input.explain(this);
  }
  spacer.subtract(2);
  xmlOutput.endTag("Inputs");
  xmlOutput.endTag("RelNode");
}
 
Example 4
Source File: RelDescriptionWriterImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
private String getNodeTypeName(RelNode rel) {
	String typeName = rel.getRelTypeName();
	for (String prefix : REL_TYPE_NAME_PREFIXES) {
		if (typeName.startsWith(prefix)) {
			return typeName.substring(prefix.length());
		}
	}
	throw new IllegalStateException("Unsupported RelNode class name '" + typeName + "'");
}
 
Example 5
Source File: RelDescriptionWriterImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
private String getNodeTypeName(RelNode rel) {
	String typeName = rel.getRelTypeName();
	for (String prefix : REL_TYPE_NAME_PREFIXES) {
		if (typeName.startsWith(prefix)) {
			return typeName.substring(prefix.length());
		}
	}
	throw new IllegalStateException("Unsupported RelNode class name '" + typeName + "'");
}
 
Example 6
Source File: RelXmlWriter.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Generates generic XML (sometimes called 'element-oriented XML'). Like
 * this:
 *
 * <blockquote>
 * <code>
 * &lt;RelNode id="1" type="Join"&gt;<br>
 * &nbsp;&nbsp;&lt;Property name="condition"&gt;EMP.DEPTNO =
 * DEPT.DEPTNO&lt;/Property&gt;<br>
 * &nbsp;&nbsp;&lt;Inputs&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&lt;RelNode id="2" type="Project"&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Property name="expr1"&gt;x +
 * y&lt;/Property&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Property
 * name="expr2"&gt;45&lt;/Property&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&lt;/RelNode&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&lt;RelNode id="3" type="TableAccess"&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Property
 * name="table"&gt;SALES.EMP&lt;/Property&gt;<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&lt;/RelNode&gt;<br>
 * &nbsp;&nbsp;&lt;/Inputs&gt;<br>
 * &lt;/RelNode&gt;</code>
 * </blockquote>
 *
 * @param rel    Relational expression
 * @param values List of term-value pairs
 */
private void explainGeneric(
    RelNode rel,
    List<Pair<String, Object>> values) {
  String relType = rel.getRelTypeName();
  xmlOutput.beginBeginTag("RelNode");
  xmlOutput.attribute("type", relType);

  xmlOutput.endBeginTag("RelNode");

  final List<RelNode> inputs = new ArrayList<>();
  for (Pair<String, Object> pair : values) {
    if (pair.right instanceof RelNode) {
      inputs.add((RelNode) pair.right);
      continue;
    }
    if (pair.right == null) {
      continue;
    }
    xmlOutput.beginBeginTag("Property");
    xmlOutput.attribute("name", pair.left);
    xmlOutput.endBeginTag("Property");
    xmlOutput.cdata(pair.right.toString());
    xmlOutput.endTag("Property");
  }
  xmlOutput.beginTag("Inputs", null);
  spacer.add(2);
  for (RelNode input : inputs) {
    input.explain(this);
  }
  spacer.subtract(2);
  xmlOutput.endTag("Inputs");
  xmlOutput.endTag("RelNode");
}
 
Example 7
Source File: RelNodeConvertor.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
public static Schema convertRelNode(RelNode relNode) {

        List<RelNode> inputs = relNode.getInputs();
        String relTypeName = relNode.getRelTypeName();
        String correlVariable = relNode.getCorrelVariable();
        RelOptTable table = relNode.getTable();
        Set<CorrelationId> variablesSet = relNode.getVariablesSet();
        switch (relTypeName) {
            case "LogicalValues": {
                return logicValues(relNode);
            }
            case "LogicalProject": {
                return logicProject(relNode);
            }
            case "LogicalAggregate": {
                return logicalAggregate(relNode);
            }
            case "LogicalTableScan": {
                return logicalTableScan(relNode);
            }
            case "LogicalIntersect":
            case "LogicalMinus":
            case "LogicalUnion": {
                return logicalSetOp(relNode);
            }
            case "LogicalSort": {
                return logicalSort(relNode);
            }
            case "LogicalFilter": {
                return logicalFilter(relNode);
            }
            case "LogicalJoin": {
                return logicalJoin(relNode);
            }
            case "LogicalCorrelate": {
                return logicalCorrelate(relNode);
            }
        }
        if (relNode instanceof TableScan) {
            List<FieldType> fields = getFields(relNode);
            TableScan relNode1 = (TableScan) relNode;
            MycatSQLTableScan unwrap = relNode1.getTable().unwrap(MycatSQLTableScan.class);
            if (unwrap != null) {
                return new FromSqlSchema(fields, unwrap.getTargetName(), unwrap.getSql());
            }
        }
        throw new UnsupportedOperationException();
    }
 
Example 8
Source File: RelNodeVisitor.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
/**
 * This is the main method in this relational node visitor which traverses the relational algebra in reverse direction
 * and populate the given underlying DAG object.
 *
 * @param relNode RelNode which needs to be traversed.
 *
 * @return RelInfo representing information of current stage
 * @throws Exception
 */
public final RelInfo traverse(RelNode relNode) throws Exception
{
  List<RelInfo> inputStreams = new ArrayList<>();
  for (RelNode input : relNode.getInputs()) {
    inputStreams.add(traverse(input));
  }

  ApexRelNode.RelContext relContext = new ApexRelNode.RelContext(dag, typeFactory, tupleSchemaRegistry);

  RelInfo currentNodeRelInfo;
  ApexRelNode apexRelNode = ApexRelNode.relNodeMapping.get(relNode.getClass());
  if (apexRelNode == null) {
    throw new UnsupportedOperationException("RelNode " + relNode.getRelTypeName() + " is not supported.");
  }
  currentNodeRelInfo = apexRelNode.visit(relContext, relNode, inputStreams);

  if (currentNodeRelInfo != null && inputStreams.size() != 0) {
    for (int i = 0; i < inputStreams.size(); i++) {
      RelInfo inputStream = inputStreams.get(i);
      Operator.OutputPort outputPort = inputStream.getOutPort();
      Operator.InputPort inputPort = currentNodeRelInfo.getInputPorts().get(i);

      String streamName = OperatorUtils.getUniqueStreamName(inputStream.getRelName(),
          currentNodeRelInfo.getRelName());
      Class schema;
      if (inputStream.getOutRelDataType() != null) {
        schema = TupleSchemaRegistry.getSchemaForRelDataType(tupleSchemaRegistry, streamName,
            inputStream.getOutRelDataType());
      } else if (inputStream.getClazz() != null) {
        schema = inputStream.getClazz();
      } else {
        throw new RuntimeException("Unexpected condition reached.");
      }
      dag.setOutputPortAttribute(outputPort, Context.PortContext.TUPLE_CLASS, schema);
      dag.setInputPortAttribute(inputPort, Context.PortContext.TUPLE_CLASS, schema);
      dag.addStream(streamName, outputPort, inputPort);
    }
  }

  if (currentNodeRelInfo.getOutPort() == null) {
    // End of the pipeline.
    String schemaJar = tupleSchemaRegistry.generateCommonJar();

    String jars = dag.getAttributes().get(Context.DAGContext.LIBRARY_JARS);
    dag.setAttribute(Context.DAGContext.LIBRARY_JARS,
        ((jars != null) && (jars.length() != 0)) ? jars + "," + schemaJar : schemaJar);
  }

  return currentNodeRelInfo;
}