Class CalcRelSplitter


  • public class CalcRelSplitter
    extends java.lang.Object
    CalcRelSplitter operates on a Calc with multiple RexCall sub-expressions that cannot all be implemented by a single concrete RelNode.

    This is a copy of CalcRelSplitter modified to work with Beam. TODO(CALCITE-4538) consider contributing these changes back upstream.

    For example, the Java and Fennel calculator do not implement an identical set of operators. The Calc can be used to split a single Calc with mixed Java- and Fennel-only operators into a tree of Calc object that can each be individually implemented by either Java or Fennel.and splits it into several Calc instances.

    Currently the splitter is only capable of handling two "rel types". That is, it can deal with Java vs. Fennel Calcs, but not Java vs. Fennel vs. some other type of Calc.

    See ProjectToWindowRule for an example of how this class is used.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CalcRelSplitter.RelType
      Type of relational expression.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rex.RexProgram program  
      protected org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.tools.RelBuilder relBuilder  
    • Constructor Summary

      Constructors 
      Constructor Description
      CalcRelSplitter​(org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.core.Calc calc, org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.tools.RelBuilder relBuilder, CalcRelSplitter.RelType[] relTypes)
      Constructs a CalcRelSplitter.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean canImplement​(org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.logical.LogicalCalc rel, java.lang.String relTypeName)
      Returns whether a relational expression can be implemented solely in a given CalcRelSplitter.RelType.
      org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.RelNode execute()  
      protected java.util.List<java.util.Set<java.lang.Integer>> getCohorts()
      Returns a list of sets of expressions that should be on the same level.
      protected org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.RelNode handle​(org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.RelNode rel)
      Opportunity to further refine the relational expression created for a given level.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • program

        protected final org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rex.RexProgram program
      • relBuilder

        protected final org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.tools.RelBuilder relBuilder
    • Constructor Detail

      • CalcRelSplitter

        public CalcRelSplitter​(org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.core.Calc calc,
                               org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.tools.RelBuilder relBuilder,
                               CalcRelSplitter.RelType[] relTypes)
        Constructs a CalcRelSplitter.
        Parameters:
        calc - Calc to split
        relTypes - Array of rel types, e.g. {Java, Fennel}. Must be distinct.
    • Method Detail

      • execute

        public org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.RelNode execute()
      • handle

        protected org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.RelNode handle​(org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.RelNode rel)
        Opportunity to further refine the relational expression created for a given level. The default implementation returns the relational expression unchanged.
      • canImplement

        protected boolean canImplement​(org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.logical.LogicalCalc rel,
                                       java.lang.String relTypeName)
        Returns whether a relational expression can be implemented solely in a given CalcRelSplitter.RelType.
        Parameters:
        rel - Calculation relational expression
        relTypeName - Name of a CalcRelSplitter.RelType
        Returns:
        Whether relational expression can be implemented
      • getCohorts

        protected java.util.List<java.util.Set<java.lang.Integer>> getCohorts()
        Returns a list of sets of expressions that should be on the same level.

        For example, if this method returns { {3, 5}, {4, 7} }, it means that expressions 3 and 5, should be on the same level, and expressions 4 and 7 should be on the same level. The two cohorts do not need to be on the same level.

        The list is best effort. If it is not possible to arrange that the expressions in a cohort are on the same level, the execute() method will still succeed.

        The default implementation of this method returns the empty list; expressions will be put on the most suitable level. This is generally the lowest possible level, except for literals, which are placed at the level where they are used.

        Returns:
        List of cohorts, that is sets of expressions, that the splitting algorithm should attempt to place on the same level