Class PigRelSqlUdfs


  • public class PigRelSqlUdfs
    extends java.lang.Object
    User-defined functions (UDFs) needed for Pig-to-RelNode translation.
    • Field Detail

      • MULTISET_PROJECTION_FUNC

        private static final ScalarFunction MULTISET_PROJECTION_FUNC
      • MULTISET_PROJECTION

        static final SqlUserDefinedFunction MULTISET_PROJECTION
        Multiset projection projects a subset of columns from the component type of a multiset type. The result is still a multiset but the component type only has a subset of columns of the original component type

        For example, given a multiset type M = [(A: int, B: double, C: varchar)], a projection MULTISET_PROJECTION(M, A, C) gives a new multiset N = [(A: int, C: varchar)].

    • Constructor Detail

      • PigRelSqlUdfs

        private PigRelSqlUdfs()
    • Method Detail

      • createPigTupleUDF

        static SqlUserDefinedFunction createPigTupleUDF​(com.google.common.collect.ImmutableList<RexNode> operands)
        Creates a Pig Tuple from a list of relational operands.
        Parameters:
        operands - Relational operands
        Returns:
        Pig Tuple SqlUDF
      • createPigBagUDF

        static SqlUserDefinedFunction createPigBagUDF​(com.google.common.collect.ImmutableList<RexNode> operands)
        Creates a Pig DataBag from a list of relational operands.
        Parameters:
        operands - Relational operands
        Returns:
        Pig DataBag SqlUDF
      • createGeneralPigUdf

        static SqlUserDefinedFunction createGeneralPigUdf​(java.lang.String udfName,
                                                          java.lang.reflect.Method method,
                                                          org.apache.pig.FuncSpec funcSpec,
                                                          RelDataType inputType,
                                                          RelDataType returnType)
        Creates a generic SqlUDF operator from a Pig UDF.
        Parameters:
        udfName - Name of the UDF
        method - Method "exec" for implementing the UDF
        funcSpec - Pig Funcspec
        inputType - Argument type for the input
        returnType - Function return data type
      • getTypeFamilies

        private static java.util.List<SqlTypeFamily> getTypeFamilies​(com.google.common.collect.ImmutableList<RexNode> operands)
        Helper method to return a list of SqlTypeFamily for a given list of relational operands
        Parameters:
        operands - List of relational operands
        Returns:
        List of SqlTypeFamilies
      • getRelDataTypes

        private static java.util.List<RelDataType> getRelDataTypes​(com.google.common.collect.ImmutableList<RexNode> operands)
        Helper method to return a list of RelDataType for a given list of relational operands
        Parameters:
        operands - List of relational operands
        Returns:
        List of RelDataTypes
      • infer

        private static SqlReturnTypeInference infer​(ScalarFunction function)
        Gets the SqlReturnTypeInference that can infer the return type from a function.
        Parameters:
        function - ScalarFunction
        Returns:
        SqlReturnTypeInference
      • getRelDataType

        private static RelDataType getRelDataType​(ScalarFunction function)
        Gets the return data type for a given function.
        Parameters:
        function - ScalarFunction
        Returns:
        returned data type
      • buildTuple

        public static org.apache.pig.data.Tuple buildTuple​(java.lang.Object... elements)
        Implementation for PIG_TUPLE functions. Builds a Pig Tuple from an array of objects
        Parameters:
        elements - Array of element objects
        Returns:
        Pig Tuple
      • buildBag

        public static org.apache.pig.data.Tuple buildBag​(java.lang.Object... elements)
        Implementation for PIG_BAG functions. Builds a Pig DataBag from the corresponding input
        Parameters:
        elements - Input that contains a bag
        Returns:
        Pig Tuple
      • projectMultiset

        public static java.util.List projectMultiset​(java.lang.Object... objects)
        Implementation for BAG_PROJECTION functions. Builds a new multiset by projecting certain columns from another multiset.
        Parameters:
        objects - Input argument, the first one is a multiset, the remaining are indexes of column to project.
        Returns:
        The projected multiset