Class PigRelBuilder

    • Field Detail

      • reverseAliasMap

        private final java.util.Map<RelNode,​java.lang.String> reverseAliasMap
      • aliasMap

        private final java.util.Map<java.lang.String,​RelNode> aliasMap
      • pigRelMap

        private final java.util.Map<org.apache.pig.newplan.Operator,​RelNode> pigRelMap
      • relPigMap

        private final java.util.Map<RelNode,​org.apache.pig.newplan.Operator> relPigMap
      • storeMap

        private final java.util.Map<java.lang.String,​RelNode> storeMap
      • nextCorrelId

        private int nextCorrelId
    • Method Detail

      • getRel

        public RelNode getRel​(java.lang.String alias)
      • getRel

        public RelNode getRel​(org.apache.pig.newplan.Operator pig)
      • getPig

        org.apache.pig.newplan.Operator getPig​(RelNode rel)
      • getAlias

        java.lang.String getAlias​(RelNode rel)
      • nextCorrelId

        CorrelationId nextCorrelId()
        Gets the next correlation id.
        Returns:
        The correlation id
      • shouldMergeProject

        protected boolean shouldMergeProject()
        Description copied from class: RelBuilder
        Whether to attempt to merge consecutive Project operators.

        The default implementation returns true; sub-classes may disable merge by overriding to return false.

        Overrides:
        shouldMergeProject in class RelBuilder
      • getAlias

        public java.lang.String getAlias()
      • clear

        public void clear()
        Description copied from class: RelBuilder
        Clears the stack.

        The builder's state is now the same as when it was created.

        Overrides:
        clear in class RelBuilder
      • checkMap

        public boolean checkMap​(org.apache.pig.newplan.logical.relational.LogicalRelationalOperator pigOp)
        Checks if a Pig logical operator has been translated before. If it has, push the corresponding relational algebra operator on top instead of doing the translation work again.
        Parameters:
        pigOp - The Pig logical operator to check.
        Returns:
        true iff the pigOp has been processed before.
      • updateAlias

        public void updateAlias​(org.apache.pig.newplan.Operator pigOp,
                                java.lang.String alias,
                                boolean updatePigRelMap)
        Updates the Pig logical operator and its alias with the top relational algebra node.
        Parameters:
        pigOp - the Pig logical operator
        alias - the alias
        updatePigRelMap - whether to update the PigRelMap
      • register

        void register​(org.apache.pig.newplan.logical.relational.LogicalRelationalOperator pigOp)
        Registers the Pig logical operator with the top relational algebra node.
        Parameters:
        pigOp - the Pig logical operator
      • registerPigUDF

        void registerPigUDF​(java.lang.String className,
                            org.apache.pig.FuncSpec pigFunc)
      • replaceTop

        void replaceTop​(RelNode newRel)
        Replaces the relational algebra operator at the top of the stack with a new one.
        Parameters:
        newRel - the new relational algebra operator to replace
      • scan

        public RelBuilder scan​(RelOptTable userSchema,
                               java.lang.String... tableNames)
        Scans a table with its given schema and names.
        Parameters:
        userSchema - The schema of the table to scan
        tableNames - The names of the table to scan
        Returns:
        This builder
      • scan

        private RelBuilder scan​(RelOptTable tableSchema)
        Scans a table with a given schema.
        Parameters:
        tableSchema - The table schema
        Returns:
        This builder
      • scan

        public RelBuilder scan​(RelDataType rowType,
                               java.lang.String... tableNames)
        Makes a table scan operator for a given row type and names
        Parameters:
        rowType - Row type
        tableNames - Table names
        Returns:
        This builder
      • scan

        public RelBuilder scan​(RelDataType rowType,
                               java.util.List<java.lang.String> tableNames)
        Makes a table scan operator for a given row type and names
        Parameters:
        rowType - Row type
        tableNames - Table names
        Returns:
        This builder
      • project

        public RelNode project​(RelNode input,
                               RelDataType outputType)
        Projects a specific row type out of a relation algebra operator. For any field in output type, if there is no matching input field, we project null value of the corresponding output field type.

        For example, given:

        • Input rel A with A_type(X: int, Y: varchar)
        • Output type B_type(X: int, Y: varchar, Z: boolean, W: double)

        project(A, B_type) gives new relation C(X: int, Y: varchar, null, null).

        Parameters:
        input - The relation algebra operator to be projected
        outputType - The data type for the projected relation algebra operator
        Returns:
        The projected relation algebra operator
      • projects

        private java.util.List<RexNode> projects​(RelDataType inputType,
                                                 RelDataType outputType)
        Builds the projection expressions for a data type on top of an input data type. For any field in output type, if there is no matching input field, we build the literal null expression with the corresponding output field type.
        Parameters:
        inputType - The input data type
        outputType - The output data type that defines the types of projection expressions
        Returns:
        List of projection expressions
      • cogroup

        public RelBuilder cogroup​(java.lang.Iterable<? extends RelBuilder.GroupKey> groupKeys)
        Cogroups relations on top of the stack. The number of relations and the group key are specified in groupKeys
        Parameters:
        groupKeys - Lists of group keys of relations to be cogrouped.
        Returns:
        This builder
      • multiSetFlatten

        public RelBuilder multiSetFlatten​(java.util.List<java.lang.Integer> flattenCols,
                                          java.util.List<java.lang.String> flattenOutputAliases)
        Flattens the top relation on provided columns.
        Parameters:
        flattenCols - Indexes of columns to be flattened. These columns should have multiset type.
        Returns:
        This builder
      • multiSetFlatten

        public RelBuilder multiSetFlatten()
        Flattens the top relation will all multiset columns. Call this method only if the top relation contains multiset columns only.
        Returns:
        This builder.
      • correl

        public RexNode correl​(java.util.List<RelDataTypeField> inputFields,
                              CorrelationId correlId)
        Makes the correlated expression from rel input fields and correlation id.
        Parameters:
        inputFields - Rel input field list
        correlId - Correlation id
        Returns:
        This builder
      • collect

        public RelBuilder collect()
        Collects all rows of the top rel into a single multiset value.
        Returns:
        This builder
      • store

        RelBuilder store​(java.lang.String storeAlias)
        Save the store alias with the corresponding relational algebra node
        Parameters:
        storeAlias - alias of the Pig store operator
        Returns:
        This builder
      • getRelsForStores

        public java.util.List<RelNode> getRelsForStores()
        Gets all relational plans corresponding to Pig Store operators.
      • getFields

        public com.google.common.collect.ImmutableList<RexNode> getFields​(int inputCount,
                                                                          int inputOrdinal,
                                                                          int fieldOrdinal)
      • compatibleType

        public static boolean compatibleType​(RelDataType t1,
                                             RelDataType t2)
        Checks if two relational data types are compatible.
        Parameters:
        t1 - first type
        t2 - second type
        Returns:
        true if t1 is compatible with t2