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)
def test_create_udf(self): stmt = ddl.CreateFunction('/foo/bar.so', 'testFunc', self.inputs, self.output, self.name) result = stmt.compile() expected = ("CREATE FUNCTION test_name(string, string) returns bigint " "location '/foo/bar.so' symbol='testFunc'") assert result == expected
def test_create_udf_type_conversions(self): stmt = ddl.CreateFunction('/foo/bar.so', 'testFunc', ['string', 'int8', 'int16', 'int32'], self.output, self.name) result = stmt.compile() expected = ("CREATE FUNCTION `test_name`(string, tinyint, " "smallint, int) returns bigint " "location '/foo/bar.so' symbol='testFunc'") assert result == expected
def create_udf(self, udf_info, name=None, database=None): """ Creates a function within Impala Parameters ---------- udf_info : UDFCreator object name : string (optional) database : string (optional) """ if name is None: name = udf_info.get_name() statement = ddl.CreateFunction(udf_info.hdfs_file, udf_info.so_symbol, udf_info.inputs, udf_info.output, name, database) self._execute(statement)