예제 #1
0
    def create_function(self, func, name=None, database=None):
        """
        Creates a function within Impala

        Parameters
        ----------
        func : ImpalaUDF or ImpalaUDA
          Created with wrap_udf or wrap_uda
        name : string (optional)
        database : string (optional)
        """
        if name is None:
            name = func.name
        database = database or self.current_database

        if isinstance(func, udf.ImpalaUDF):
            stmt = ddl.CreateFunction(func.lib_path, func.so_symbol,
                                      func.input_type, func.output, name,
                                      database)
        elif isinstance(func, udf.ImpalaUDA):
            stmt = ddl.CreateAggregateFunction(func.lib_path, func.input_type,
                                               func.output, func.update_fn,
                                               func.init_fn, func.merge_fn,
                                               func.serialize_fn,
                                               func.finalize_fn, name,
                                               database)
        else:
            raise TypeError(func)
        self._execute(stmt)
예제 #2
0
 def test_create_uda(self):
     stmt = ddl.CreateAggregateFunction('/foo/bar.so', self.inputs,
                                        self.output, 'Init', 'Update',
                                        'Merge', 'Finalize', self.name)
     result = stmt.compile()
     expected = ("CREATE AGGREGATE FUNCTION test_name(string, string)"
                 " returns bigint location '/foo/bar.so'"
                 " init_fn='Init' update_fn='Update'"
                 " merge_fn='Merge' finalize_fn='Finalize'")
     assert result == expected
예제 #3
0
파일: test_udf.py 프로젝트: tvial/ibis
    def test_create_uda(self):
        def make_ex(serialize=False):
            if serialize:
                serialize = "\nserialize_fn='Serialize'"
            else:
                serialize = ""
            return (("CREATE AGGREGATE FUNCTION "
                     "bar.`test_name`(string, string)"
                     " returns bigint location '/foo/bar.so'"
                     "\ninit_fn='Init'"
                     "\nupdate_fn='Update'"
                     "\nmerge_fn='Merge'") + serialize +
                    ("\nfinalize_fn='Finalize'"))

        for ser in [True, False]:
            stmt = ddl.CreateAggregateFunction('/foo/bar.so', self.inputs,
                                               self.output, 'Update', 'Init',
                                               'Merge',
                                               'Serialize' if ser else None,
                                               'Finalize', self.name, 'bar')
            result = stmt.compile()
            expected = make_ex(ser)
            assert result == expected
예제 #4
0
파일: client.py 프로젝트: zuxfoucault/ibis
    def create_uda(self, uda_info, name=None, database=None):
        """
        Creates a user-defined aggregate function within Impala

        Parameters
        ----------
        uda_info : UDAInfo object
        name : string (optional)
        database : string (optional)
        """
        if name is None:
            name = uda_info.get_name()

        statement = ddl.CreateAggregateFunction(uda_info.hdfs_file,
                                                uda_info.inputs,
                                                uda_info.output,
                                                uda_info.init_fn,
                                                uda_info.update_fn,
                                                uda_info.merge_fn,
                                                uda_info.finalize_fn,
                                                name,
                                                database=database)
        self._execute(statement)