Ejemplo n.º 1
0
    def __init__(self, function_type, *args):
        """Build the Each constructor for the Python function.

        Arguments:
        function_type -- CascadingFunctionWrapper or CascadingFilterWrapper,
            whether we are calling Each with a function or filter
        *args -- the arguments passed on to Cascading Each
        """
        Operation.__init__(self)

        self.__function = None
        # The default argument selector is Fields.ALL (per Cascading sources
        # for Operator.java)
        self.__argument_selector = None
        # The default output selector is Fields.RESULTS (per Cascading sources
        # for Operator.java)
        self.__output_selector = None

        if len(args) == 1:
            self.__function = args[0]
        elif len(args) == 2:
            (self.__argument_selector, self.__function) = args
        elif len(args) == 3:
            (self.__argument_selector, self.__function,
             self.__output_selector) = args
        else:
            raise Exception('The number of parameters to Apply/Filter ' \
                            'should be between 1 and 3')
        # This is the Cascading Function type
        self.__function = wrap_function(self.__function, function_type)
Ejemplo n.º 2
0
    def __init__(self, function_type, *args):
        """Build the Each constructor for the Python function.

        Arguments:
        function_type -- CascadingFunctionWrapper or CascadingFilterWrapper,
            whether we are calling Each with a function or filter
        *args -- the arguments passed on to Cascading Each
        """
        Operation.__init__(self)

        self.__function = None
        # The default argument selector is Fields.ALL (per Cascading sources
        # for Operator.java)
        self.__argument_selector = None
        # The default output selector is Fields.RESULTS (per Cascading sources
        # for Operator.java)
        self.__output_selector = None

        if len(args) == 1:
            self.__function = args[0]
        elif len(args) == 2:
            (self.__argument_selector, self.__function) = args
        elif len(args) == 3:
            (self.__argument_selector, self.__function,
             self.__output_selector) = args
        else:
            raise Exception('The number of parameters to Apply/Filter ' \
                            'should be between 1 and 3')
        # This is the Cascading Function type
        self.__function = wrap_function(self.__function, function_type)
Ejemplo n.º 3
0
    def __create_args(self,
                      pipe=None,
                      aggregator=None,
                      output_selector=None,
                      assertion_level=None,
                      assertion=None,
                      buffer=None,
                      argument_selector=None):
        if self.__args:
            # If we pass in an unnamed argument, try to determine its type
            if isinstance(self.__args[0], cascading.operation.Aggregator):
                aggregator = self.__args[0]
            else:
                buffer = self.__args[0]
        # Set up some defaults
        if argument_selector is None:
            argument_selector = cascading.tuple.Fields.ALL
        if output_selector is None:
            if aggregator is not None:
                # In the case of aggregators, we want to return both the
                # groupings and the results
                output_selector = cascading.tuple.Fields.ALL
            else:
                output_selector = cascading.tuple.Fields.RESULTS

        args = []
        args.append(pipe.get_assembly())
        if argument_selector is not None:
            args.append(coerce_to_fields(argument_selector))
        if aggregator is not None:
            # for now we assume it's a Cascading aggregator straight
            args.append(wrap_function(aggregator, CascadingAggregatorWrapper))
            if output_selector:
                args.append(coerce_to_fields(output_selector))
        if assertion_level is not None:
            args.append(assertion_level)
            args.append(assertion)
        if buffer is not None:
            args.append(wrap_function(buffer, CascadingBufferWrapper))
            if output_selector:
                args.append(coerce_to_fields(output_selector))
        return args
Ejemplo n.º 4
0
    def __create_args(self,
                      pipe=None,
                      aggregator=None, output_selector=None,
                      assertion_level=None, assertion=None,
                      buffer=None,
                      argument_selector=None):
        if self.__args:
            # If we pass in an unnamed argument, try to determine its type
            if isinstance(self.__args[0], cascading.operation.Aggregator):
                aggregator = self.__args[0]
            else:
                buffer = self.__args[0]
        # Set up some defaults
        if argument_selector is None:
            argument_selector = cascading.tuple.Fields.ALL
        if output_selector is None:
            if aggregator is not None:
                # In the case of aggregators, we want to return both the
                # groupings and the results
                output_selector = cascading.tuple.Fields.ALL
            else:
                output_selector = cascading.tuple.Fields.RESULTS

        args = []
        args.append(pipe.get_assembly())
        if argument_selector is not None:
            args.append(coerce_to_fields(argument_selector))
        if aggregator is not None:
            # for now we assume it's a Cascading aggregator straight
            args.append(wrap_function(aggregator, CascadingAggregatorWrapper))
            if output_selector:
                args.append(coerce_to_fields(output_selector))
        if assertion_level is not None:
            args.append(assertion_level)
            args.append(assertion)
        if buffer is not None:
            args.append(wrap_function(buffer, CascadingBufferWrapper))
            if output_selector:
                args.append(coerce_to_fields(output_selector))
        return args