Exemple #1
0
def function_call_from_mapping(cursor, mapping_id):
    function_mapping = FunctionMapping.load(mapping_id)(cursor)

    arg_columns = ",".join(function_mapping.signature_columns)

    if function_mapping.name is None:
        if len(function_mapping.signature_columns) > 1:
            raise Exception("cannot specify multiple columns in signature without a transforming function")

        return Column(function_mapping.signature_columns[0])
    else:
        # deal with native (e.g. SUM, MAX) and custom transform functions
        if is_custom_function(cursor, SCHEMA, function_mapping.name):
            function = Function(SCHEMA, function_mapping.name)
        else:
            function = Function(function_mapping.name)

        def signature_column_to_arg(c):
            try:
                int_val = int(c)
            except ValueError:
                return Column(c)
            else:
                return Value(int_val)

        args = map(signature_column_to_arg, function_mapping.signature_columns)

        return function.call(*args)
Exemple #2
0
def test_function():
    dummy_function = Function("add_many")

    col_a = Column("counter_a")
    col_b = Column("counter_b")

    call = dummy_function.call(col_a, col_b)

    eq_(call.render(), "add_many(counter_a, counter_b)")