exasol / advanced-analytics-framework

Framework for building complex data analysis algorithms with Exasol
MIT License
0 stars 0 forks source link

Generate dynamic module for custom UDF #190

Closed ckunki closed 1 month ago

ckunki commented 1 month ago

Factory on the fly

See

Tasks

ckunki commented 1 month ago

Currently when using

--/
CREATE OR REPLACE PYTHON3_AAF SET SCRIPT "MY_SCHEMA"."MY_QUERY_HANDLER_UDF"(...)
EMITS (outputs VARCHAR(2000000)) AS
xyz = create_module("xyz", [ExampleQueryHandler, ExampleQueryHandlerFactory])
/ 

and

EXECUTE SCRIPT MY_SCHEMA.AAF_RUN_QUERY_HANDLER('{
    "query_handler": {
        "factory_class": {
            "module": "xyz",
            "name": "ExampleQueryHandlerFactory"
        },

I get the error message

udf_framework/query_handler_runner_udf.py", line 215, in _create_state
    module = importlib.import_module(self.parameter.python_class_module)
    ModuleNotFoundError: No module named 'xyz'

Maybe we need to call create_module() in query_handler_runner_udf.py?

ckunki commented 1 month ago

Now, when using

new_module = DynamicModule("xyz").add(ExampleQueryHandler)
import xyz

class ExampleQueryHandlerFactory:
    def create(self, parameter: str, query_handler_context: QueryHandlerContext):
        return xyz.ExampleQueryHandler(parameter, query_handler_context)

new_module.add(ExampleQueryHandlerFactory)

... I get the error message

_pickle.PicklingError: Can't pickle <class 'ExampleQueryHandler'>: 
it's not found as builtins.ExampleQueryHandler
'" caught in script "MY_SCHEMA"."AAF_RUN_QUERY_HANDLER"
 at line 628 
ckunki commented 1 month ago

I only was successful when using the module builtins:

new_module = DynamicModule("builtins").add(ExampleQueryHandler)
import builtins

class ExampleQueryHandlerFactory:
    def create(self, parameter: str, query_handler_context: QueryHandlerContext):
        return builtins.ExampleQueryHandler(parameter, query_handler_context)

new_module.add(ExampleQueryHandlerFactory)
ckunki commented 1 month ago

Obsolete tasks from initial plan

My initial plan included the following tasks

These tasks have now been replaced

New plan

Remove sentence

For this the proxy maintains a reference counter.

As this is an irrelevant implementation detail and also not 100% correct in this place