exasol-udf-mock-python


Nameexasol-udf-mock-python JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/exasol/udf-mock-python
SummaryMocking framework for Exasol Python UDFs
upload_time2023-11-22 10:38:39
maintainer
docs_urlNone
authorTorsten Kilias
requires_python>=3.8
licenseMIT
keywords exasol udf mock testing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # UDF Mock for Python

This projects provides a mock runner for Python3 UDFs which allows you
to test your UDFs locally without a database.

**Note:** This project is in a very early development phase.
Please, be aware that the behavior of the mock runner doesn't perfectly
reflect the behaviors of the UDFs inside the database and that the interface still can change.
In any case, you need to verify your UDFs with integrations test inside the database.

## Getting started

**Attention:** We changed the default branch to main and the master branch is deprecated.

### Installing via pip
```
pip install udf-mock-python
```

### Installing via poetry
Add it to your `tool.poetry.dependencies` or `tool.poetry.dev-dependencies`

```
[tool.poetry.dev-dependencies]
udf-mock-python = "^0.1.0"
...
```

### How to use the Mock

The mock runner runs your python UDF in a python environment in which
no external variables, functions or classes are visble.
This means in practice, you can only use things you defined inside your
UDF and what gets provided by the UDF frameworks,
such as exa.meta and the context for the run function.
This includes imports, variables, functions, classes and so on.

You define a UDF in this framework within in a wrapper function.
This wrapper function then contains all necessary imports, functions,
variables and classes.
You then handover the wrapper function to the `UDFMockExecutor`
which runs the UDF inside if the isolated python environment.
The following example shows, how you use this framework:
The following example shows the general setup for a test with the Mock:

```
def udf_wrapper():

    def run(ctx):
        return ctx.t1+1, ctx.t2+1.1, ctx.t3+"1"

executor = UDFMockExecutor()
meta = MockMetaData(
    script_code_wrapper_function=udf_wrapper,
    input_type="SCALAR",
    input_columns=[Column("t1", int, "INTEGER"),
                   Column("t2", float, "FLOAT"),
                   Column("t3", str, "VARCHAR(20000)")],
    output_type="RETURNS",
    output_columns=[Column("t1", int, "INTEGER"),
                    Column("t2", float, "FLOAT"),
                    Column("t3", str, "VARCHAR(20000)")]
)
exa = MockExaEnvironment(meta)
result = executor.run([Group([(1,1.0,"1"), (5,5.0,"5"), (6,6.0,"6")])], exa)
```

**Checkout the [tests](tests) for more information about, how to use the Mock.**

## Limitations or missing features

Some of the following limitations are fundamental, other are missing
feature and might get removed by later releases:

- Data type checks for outputs are more strict as in real UDFs
- No support for Import or Export Specification or Virtual Schema adapter
- No support for dynamic input and output parameters
- No support for exa.import_script
- No BucketFS
- Execution is not isolated in a container
  - Can access and manipulate the file system of the system running the Mock
    - UDF inside of the database only can write /tmp to tmp and
      only see the file system of the script-language container and the mounted bucketfs
  - Can use all python package available in the system running the Mock
    - If you use package which are currently not available in the script-language containers,
      you need create your own container for testing inside of the database
  - Does not emulate the ressource limitations which get a applied in the database
- Only one instance of the UDF gets executed
- No support for Python2, because Python2 is officially End of Life

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/exasol/udf-mock-python",
    "name": "exasol-udf-mock-python",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "exasol,udf,mock,testing",
    "author": "Torsten Kilias",
    "author_email": "torsten.kilias@exasol.com",
    "download_url": "https://files.pythonhosted.org/packages/71/5d/71eff363259bb1585867d30563bcef5cbfcc63d68eefcd473ffa6ef7ac5c/exasol_udf_mock_python-0.1.0.tar.gz",
    "platform": null,
    "description": "# UDF Mock for Python\n\nThis projects provides a mock runner for Python3 UDFs which allows you\nto test your UDFs locally without a database.\n\n**Note:** This project is in a very early development phase.\nPlease, be aware that the behavior of the mock runner doesn't perfectly\nreflect the behaviors of the UDFs inside the database and that the interface still can change.\nIn any case, you need to verify your UDFs with integrations test inside the database.\n\n## Getting started\n\n**Attention:** We changed the default branch to main and the master branch is deprecated.\n\n### Installing via pip\n```\npip install udf-mock-python\n```\n\n### Installing via poetry\nAdd it to your `tool.poetry.dependencies` or `tool.poetry.dev-dependencies`\n\n```\n[tool.poetry.dev-dependencies]\nudf-mock-python = \"^0.1.0\"\n...\n```\n\n### How to use the Mock\n\nThe mock runner runs your python UDF in a python environment in which\nno external variables, functions or classes are visble.\nThis means in practice, you can only use things you defined inside your\nUDF and what gets provided by the UDF frameworks,\nsuch as exa.meta and the context for the run function.\nThis includes imports, variables, functions, classes and so on.\n\nYou define a UDF in this framework within in a wrapper function.\nThis wrapper function then contains all necessary imports, functions,\nvariables and classes.\nYou then handover the wrapper function to the `UDFMockExecutor`\nwhich runs the UDF inside if the isolated python environment.\nThe following example shows, how you use this framework:\nThe following example shows the general setup for a test with the Mock:\n\n```\ndef udf_wrapper():\n\n    def run(ctx):\n        return ctx.t1+1, ctx.t2+1.1, ctx.t3+\"1\"\n\nexecutor = UDFMockExecutor()\nmeta = MockMetaData(\n    script_code_wrapper_function=udf_wrapper,\n    input_type=\"SCALAR\",\n    input_columns=[Column(\"t1\", int, \"INTEGER\"),\n                   Column(\"t2\", float, \"FLOAT\"),\n                   Column(\"t3\", str, \"VARCHAR(20000)\")],\n    output_type=\"RETURNS\",\n    output_columns=[Column(\"t1\", int, \"INTEGER\"),\n                    Column(\"t2\", float, \"FLOAT\"),\n                    Column(\"t3\", str, \"VARCHAR(20000)\")]\n)\nexa = MockExaEnvironment(meta)\nresult = executor.run([Group([(1,1.0,\"1\"), (5,5.0,\"5\"), (6,6.0,\"6\")])], exa)\n```\n\n**Checkout the [tests](tests) for more information about, how to use the Mock.**\n\n## Limitations or missing features\n\nSome of the following limitations are fundamental, other are missing\nfeature and might get removed by later releases:\n\n- Data type checks for outputs are more strict as in real UDFs\n- No support for Import or Export Specification or Virtual Schema adapter\n- No support for dynamic input and output parameters\n- No support for exa.import_script\n- No BucketFS\n- Execution is not isolated in a container\n  - Can access and manipulate the file system of the system running the Mock\n    - UDF inside of the database only can write /tmp to tmp and\n      only see the file system of the script-language container and the mounted bucketfs\n  - Can use all python package available in the system running the Mock\n    - If you use package which are currently not available in the script-language containers,\n      you need create your own container for testing inside of the database\n  - Does not emulate the ressource limitations which get a applied in the database\n- Only one instance of the UDF gets executed\n- No support for Python2, because Python2 is officially End of Life\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Mocking framework for Exasol Python UDFs",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/exasol/udf-mock-python",
        "Repository": "https://github.com/exasol/udf-mock-python"
    },
    "split_keywords": [
        "exasol",
        "udf",
        "mock",
        "testing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7d118132e01f189b59c080137b20292e0270391fc6ed08a03126644399567a02",
                "md5": "82cc005f307ff08e1e5113a1d7641e72",
                "sha256": "3c496b0d5a7e3dbef63fb48144a8ff9e9c417256248842f132f031f44578463b"
            },
            "downloads": -1,
            "filename": "exasol_udf_mock_python-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "82cc005f307ff08e1e5113a1d7641e72",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 13381,
            "upload_time": "2023-11-22T10:38:32",
            "upload_time_iso_8601": "2023-11-22T10:38:32.768259Z",
            "url": "https://files.pythonhosted.org/packages/7d/11/8132e01f189b59c080137b20292e0270391fc6ed08a03126644399567a02/exasol_udf_mock_python-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "715d71eff363259bb1585867d30563bcef5cbfcc63d68eefcd473ffa6ef7ac5c",
                "md5": "a0001fa6fc692bc8fc27fe2d799347bd",
                "sha256": "581cbf467afae7c2e395db41a625c63f27e40177969e0670de69991fd52da742"
            },
            "downloads": -1,
            "filename": "exasol_udf_mock_python-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a0001fa6fc692bc8fc27fe2d799347bd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 11088,
            "upload_time": "2023-11-22T10:38:39",
            "upload_time_iso_8601": "2023-11-22T10:38:39.569189Z",
            "url": "https://files.pythonhosted.org/packages/71/5d/71eff363259bb1585867d30563bcef5cbfcc63d68eefcd473ffa6ef7ac5c/exasol_udf_mock_python-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-22 10:38:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "exasol",
    "github_project": "udf-mock-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "exasol-udf-mock-python"
}
        
Elapsed time: 0.28444s