|
| 1 | + |
| 2 | +UDF Mock for Python |
| 3 | +=================== |
| 4 | + |
| 5 | +This projects provides a mock runner for Python3 UDFs which allows you |
| 6 | +to test your UDFs locally without a database. |
| 7 | + |
| 8 | +**Note:** This project is in a very early development phase. |
| 9 | +Please, be aware that the behavior of the mock runner doesn't perfectly |
| 10 | +reflect the behaviors of the UDFs inside the database and that the interface still can change. |
| 11 | +In any case, you need to verify your UDFs with integrations test inside the database. |
| 12 | + |
| 13 | +Getting started |
| 14 | +--------------- |
| 15 | + |
| 16 | +Installing via pip |
| 17 | +^^^^^^^^^^^^^^^^^^ |
| 18 | + |
| 19 | +.. code-block:: |
| 20 | +
|
| 21 | + pip install git+https://github.com/exasol/exasol-udf-mock-python.git@master |
| 22 | +
|
| 23 | +Installing via poetry |
| 24 | +^^^^^^^^^^^^^^^^^^^^^ |
| 25 | + |
| 26 | +Add it to your ``tool.poetry.dependencies`` or ``tool.poetry.dev-dependencies`` |
| 27 | + |
| 28 | +.. code-block:: |
| 29 | +
|
| 30 | + [tool.poetry.dev-dependencies] |
| 31 | + exasol-udf-mock-python = { git = "https://github.com/exasol/exasol-udf-mock-python.git", branch = "master" } |
| 32 | + ... |
| 33 | +
|
| 34 | +How to use the Mock |
| 35 | +^^^^^^^^^^^^^^^^^^^ |
| 36 | + |
| 37 | +The mock runner runs your python UDF in a python environment in which |
| 38 | +no external variables, functions or classes are visble. |
| 39 | +This means in practice, you can only use things you defined inside your |
| 40 | +UDF and what gets provided by the UDF frameworks, |
| 41 | +such as exa.meta and the context for the run function. |
| 42 | +This includes imports, variables, functions, classes and so on. |
| 43 | + |
| 44 | +You define a UDF in this framework within in a wrapper function. |
| 45 | +This wrapper function then contains all necessary imports, functions, |
| 46 | +variables and classes. |
| 47 | +You then handover the wrapper function to the ``UDFMockExecutor`` |
| 48 | +which runs the UDF inside if the isolated python environment. |
| 49 | +The following example shows, how you use this framework: |
| 50 | +The following example shows the general setup for a test with the Mock: |
| 51 | + |
| 52 | +.. code-block:: |
| 53 | +
|
| 54 | + def udf_wrapper(): |
| 55 | +
|
| 56 | + def run(ctx): |
| 57 | + return ctx.t1+1, ctx.t2+1.1, ctx.t3+"1" |
| 58 | +
|
| 59 | + executor = UDFMockExecutor() |
| 60 | + meta = MockMetaData( |
| 61 | + script_code_wrapper_function=udf_wrapper, |
| 62 | + input_type="SCALAR", |
| 63 | + input_columns=[Column("t1", int, "INTEGER"), |
| 64 | + Column("t2", float, "FLOAT"), |
| 65 | + Column("t3", str, "VARCHAR(20000)")], |
| 66 | + output_type="RETURNS", |
| 67 | + output_columns=[Column("t1", int, "INTEGER"), |
| 68 | + Column("t2", float, "FLOAT"), |
| 69 | + Column("t3", str, "VARCHAR(20000)")] |
| 70 | + ) |
| 71 | + exa = MockExaEnvironment(meta) |
| 72 | + result = executor.run([Group([(1,1.0,"1"), (5,5.0,"5"), (6,6.0,"6")])], exa) |
| 73 | +
|
| 74 | +**Checkout the `tests <tests>`_ for more information about, how to use the Mock.** |
| 75 | + |
| 76 | +Limitations or missing features |
| 77 | +------------------------------- |
| 78 | + |
| 79 | +Some of the following limitations are fundamental, other are missing |
| 80 | +feature and might get removed by later releases: |
| 81 | + |
| 82 | + |
| 83 | +* Data type checks for outputs are more strict as in real UDFs |
| 84 | +* No support for Import or Export Specification or Virtual Schema adapter |
| 85 | +* No support for dynamic input and output parameters |
| 86 | +* No support for exa.import_script |
| 87 | +* No BucketFS |
| 88 | +* Execution is not isolated in a container |
| 89 | + |
| 90 | + * Can access and manipulate the file system of the system running the Mock |
| 91 | + |
| 92 | + * UDF inside of the database only can write /tmp to tmp and |
| 93 | + only see the file system of the script-language container and the mounted bucketfs |
| 94 | + |
| 95 | + * Can use all python package available in the system running the Mock |
| 96 | + |
| 97 | + * If you use package which are currently not available in the script-language containers, |
| 98 | + you need create your own container for testing inside of the database |
| 99 | + |
| 100 | + * Does not emulate the ressource limitations which get a applied in the database |
| 101 | + |
| 102 | +* Only one instance of the UDF gets executed |
| 103 | +* No support for Python2, because Python2 is officially End of Life |
0 commit comments