Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/check_setup_py.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6]
python-version: [3.8]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: abatilo/actions-poetry@v2.0.0
- uses: abatilo/actions-poetry@v2.1.4
- name: Run packaging update
run: bash githooks/update_setup_py.sh
- name: Show changes on working copy
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6]
python-version: [3.8]
runs-on: ubuntu-latest

steps:
Expand All @@ -16,10 +16,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: abatilo/actions-poetry@v2.0.0
- name: Install lapack/blas for Numpy from source
run: sudo apt-get update && sudo apt-get install -y liblapack-dev libblas-dev
#highly recommended for numpy from source, check https://numpy.org/devdocs/user/building.html#prerequisites
uses: abatilo/actions-poetry@v2.1.4
- name: Install dependencies
run: poetry install
- name: Run pytest
Expand Down
11 changes: 8 additions & 3 deletions exasol_udf_mock_python/mock_context_run_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

def _disallowed_function(*args, **kw):
raise RuntimeError(
"F-UDF-CL-SL-PYTHON-1107: next(), reset() and emit() functions are not allowed in scalar context")
"F-UDF-CL-SL-PYTHON-1107: next(), reset() and emit() "
"functions are not allowed in scalar context")


class MockContextRunWrapper:

def __init__(self, mock_context: MockContext, input_type: str, output_type: str):
def __init__(
self, mock_context: MockContext, input_type: str, output_type: str):
self._output_type = output_type
self._input_type = input_type
self._mock_context = mock_context
Expand All @@ -24,6 +27,8 @@ def __init__(self, mock_context: MockContext, input_type: str, output_type: str)
self.get_dataframe = self._mock_context.get_dataframe
self.size = self._mock_context.size


def __getattr__(self, name):
return self._mock_context.__getattr__(name)

def __getitem__(self, item):
return self._mock_context._data[item]
4 changes: 2 additions & 2 deletions exasol_udf_mock_python/mock_meta_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def input_type(self):
return self._input_type

@property
def input_columns_count(self):
def input_column_count(self):
return self._input_column_count

@property
Expand All @@ -166,7 +166,7 @@ def output_type(self):
return self._output_type

@property
def output_columns_count(self):
def output_column_count(self):
return self._output_column_count

@property
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ homepage = "https://github.com/exasol/udf-mock-python"
keywords = ['exasol', 'udf', 'mock', 'testing']

[tool.poetry.dependencies]
python = ">=3.6.1"
pandas = "1.1.5"# last version with support for python 3.6
numpy = { git = "https://github.com/numpy/numpy.git", branch = "maintenance/1.19.x" } # last version with support for python 3.6 + latest security fixes
python = ">=3.8"
pandas = "^1.4"
numpy = "^1.22"
dill = "^0.3.2"

[tool.poetry.dev-dependencies]
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
{'': ['*']}

install_requires = \
['dill>=0.3.2,<0.4.0',
'numpy @ git+https://github.com/numpy/numpy.git@maintenance/1.19.x',
'pandas==1.1.5']
['dill>=0.3.2,<0.4.0', 'numpy>=1.22,<2.0', 'pandas>=1.4,<2.0']

setup_kwargs = {
'name': 'exasol-udf-mock-python',
Expand All @@ -25,7 +23,7 @@
'packages': packages,
'package_data': package_data,
'install_requires': install_requires,
'python_requires': '>=3.6.1',
'python_requires': '>=3.8',
}


Expand Down
31 changes: 31 additions & 0 deletions tests/test_executor_context_set_emits.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,34 @@ def run(ctx):
exa = MockExaEnvironment(meta)
with pytest.raises(TypeError):
result = executor.run([Group([(1,), (2,), (3,), (4,), (5,), (6,)])], exa)


def test_context_parameters():
def udf_wrapper():
def run(ctx):
ctx.emit(ctx[0], ctx.t1)
ctx.emit(ctx[1], ctx.t2)
ctx.emit(ctx[2], ctx.t3)

input_columns = [Column("t1", int, "INTEGER"),
Column("t2", int, "INTEGER"),
Column("t3", int, "INTEGER")]
output_columns = [Column("o1", int, "INTEGER"),
Column("o2", int, "INTEGER")]
meta = MockMetaData(
script_code_wrapper_function=udf_wrapper,
input_type="SET",
input_columns=input_columns,
output_type="EMITS",
output_columns=output_columns
)
input_data = [(1, 2, 3), (4, 5, 6)]
exa = MockExaEnvironment(meta)
executor = UDFMockExecutor()
result = executor.run([Group(input_data)], exa)
for i, group in enumerate(result):
result_row = group.rows
assert len(result_row) == len(input_columns)
for j in range(len(result_row)):
assert len(result_row[j]) == len(output_columns)
assert input_data[i][j] == result_row[j][0] == result_row[j][1]
29 changes: 29 additions & 0 deletions tests/test_executor_exa_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,32 @@ def run(ctx):
exa = MockExaEnvironment(meta, connections={"TEST_CON": Connection(address="https://test.de")})
result = executor.run([Group([(1,)])], exa)
assert result == [Group([("https://test.de",)])]


def test_exa_meta_column_count():
def udf_wrapper():
script_code = exa.meta.script_code

def run(ctx):
ctx.emit(script_code)

input_columns = [Column("t1", int, "INTEGER"),
Column("t2", int, "INTEGER"),
Column("t3", int, "INTEGER")]
output_columns = [Column("o1", str, "VARCHAR(2000)"),
Column("o2", str, "VARCHAR(2000)")]
meta = MockMetaData(
script_code_wrapper_function=udf_wrapper,
input_type="SET",
input_columns=input_columns,
output_type="EMITS",
output_columns=output_columns
)
exa = MockExaEnvironment(meta)

assert exa.meta.input_column_count == len(input_columns)
assert len(exa.meta.input_columns) == len(input_columns)
assert exa.meta.input_columns == input_columns
assert exa.meta.output_column_count == len(output_columns)
assert len(exa.meta.output_columns) == len(output_columns)
assert exa.meta.output_columns == output_columns