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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def read_collection(schema, collection):
pytest.param(INT_ARRAY, [], np.array([], dtype=np.int64), id="empty-array"),
pytest.param(INT_ARRAY, 7, np.array([7]), id="scalar-as-vector"),
pytest.param(
np.ndarray[None, np.dtype[np.int64]],
# Pathway supports None for unknown rank; NumPy 2 stubs require a tuple.
np.ndarray[None, np.dtype[np.int64]], # type: ignore[type-var, unused-ignore]
[[[1, 2]]],
np.array([[[1, 2]]]),
id="unknown-rank",
Expand Down
4 changes: 2 additions & 2 deletions python/pathway/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
AIRBYTE_FAKER_CONNECTION_REL_PATH,
SerializationTestHelper,
make_port_fixture,
only_with_license_key,
)


Expand Down Expand Up @@ -54,9 +53,10 @@ def local_pathway_config(environment_variables):


@pytest.fixture
@only_with_license_key
def requires_license() -> None:
"""Require a configured license key for a test or doctest."""
if not config.get_pathway_config().license_key:
pytest.skip("requires a Pathway license key")


environment_stash_key = pytest.StashKey[dict[str, str]]()
Expand Down
1 change: 1 addition & 0 deletions python/pathway/io/mysql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def read(
``{"price": 12.5, "content": "AQI="}``. Bytes inside the JSON value use base64,
even when the database also supports native binary columns.

>>> getfixture("requires_license") # NODOCS
>>> import pathway as pw
>>> class Payload(pw.Schema):
... price: float
Expand Down
146 changes: 146 additions & 0 deletions python/pathway/tests/test_fully_async_udf_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Copyright © 2026 Pathway

import asyncio
import threading

import pytest

import pathway as pw
from pathway.internals import api
from pathway.internals.parse_graph import G


@pytest.mark.parametrize(
("reinsert_same_value", "reinsert_before_completion", "same_batch_replacement"),
[
(False, False, False),
(False, True, False),
(False, True, True),
(True, False, False),
(True, True, False),
],
)
@pytest.mark.parametrize("as_transformer", [False, True])
def test_fully_async_udf_keeps_results_for_the_current_input(
reinsert_before_completion,
reinsert_same_value,
same_batch_replacement,
as_transformer,
):
"""A completed invocation must not revive or overwrite a deleted row."""
old_started = threading.Event()
old_can_finish = threading.Event()
old_finished = threading.Event()
deletion_seen = threading.Event()
reinsertion_seen = threading.Event()
probe_seen = threading.Event()
new_can_finish = threading.Event()
outputs = []
input_times = {}
new_value = 10 if reinsert_same_value else 12
calls_for_ten = 0

class InputSchema(pw.Schema):
a: int

class InputSubject(pw.io.python.ConnectorSubject):
def run(self):
self._add_inner(api.ref_scalar(3), {"a": 10})
self.commit()
assert old_started.wait(10), "first UDF did not start"
if same_batch_replacement:
self._disable_commits()
self._remove_inner(api.ref_scalar(3), {"a": 10})
if same_batch_replacement:
self._add_inner(api.ref_scalar(3), {"a": new_value})
self._enable_commits()
self.commit()
assert deletion_seen.wait(10), "input deletion was not observed"
if reinsert_before_completion:
if not same_batch_replacement:
self._add_inner(api.ref_scalar(3), {"a": new_value})
self.commit()
assert reinsertion_seen.wait(10), "input reinsertion was not observed"
old_can_finish.set()
assert old_finished.wait(10), "first UDF did not finish"
# A separate key observes progress through the async output stream.
self._add_inner(api.ref_scalar(4), {"a": 20})
self.commit()
assert probe_seen.wait(10), "async output did not reach the probe"
if not reinsert_before_completion:
self._add_inner(api.ref_scalar(3), {"a": new_value})
self.commit()
new_can_finish.set()

async def compute_value(a: int) -> int:
nonlocal calls_for_ten
if a == 10:
calls_for_ten += 1
if calls_for_ten == 1:
old_started.set()
assert await asyncio.to_thread(old_can_finish.wait, 10)
old_finished.set()
return 101
assert await asyncio.to_thread(new_can_finish.wait, 10)
return 102
if a == 12:
assert await asyncio.to_thread(new_can_finish.wait, 10)
return 1201
return 2001

def observe_input(key, row, time, is_addition):
if key == api.ref_scalar(3):
if not is_addition:
input_times["deletion"] = time
deletion_seen.set()
elif deletion_seen.is_set():
input_times["reinsertion"] = time
reinsertion_seen.set()

def observe_output(key, row, time, is_addition):
outputs.append((key, row, is_addition))
if key == api.ref_scalar(4) and is_addition:
probe_seen.set()

table = pw.io.python.read(
InputSubject(), schema=InputSchema, autocommit_duration_ms=10
)
pw.io.subscribe(table, on_change=observe_input)
if as_transformer:

class OutputSchema(pw.Schema):
result: int

class Transformer(pw.AsyncTransformer, output_schema=OutputSchema):
async def invoke(self, a: int) -> dict[str, int]:
return {"result": await compute_value(a)}

result = Transformer(table, autocommit_duration_ms=10).successful
else:
compute = pw.udf(
compute_value,
executor=pw.udfs.fully_async_executor(autocommit_duration_ms=10),
)
result = table.select(a=table.a, result=compute(table.a)).await_futures()
pw.io.subscribe(result, on_change=observe_output)
try:
pw.run(monitoring_level=pw.MonitoringLevel.NONE)
finally:
G.clear()

if same_batch_replacement:
assert input_times["deletion"] == input_times["reinsertion"]
expected_value = 102 if reinsert_same_value else 1201
additions = [(key, row) for key, row, added in outputs if added]
assert any(
key == api.ref_scalar(3) and row["result"] == expected_value
for key, row in additions
)
assert any(
key == api.ref_scalar(4) and row["result"] == 2001 for key, row in additions
)
assert all(
key != api.ref_scalar(3)
or (row["result"] == expected_value and row.get("a", new_value) == new_value)
for key, row in additions
), additions
2 changes: 1 addition & 1 deletion python/pathway/tests/test_nested_lake_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


@pytest.fixture(params=[False, True], ids=["parquet", "arrow-backfill"])
def lake_reader(request, tmp_path):
def lake_reader(request, tmp_path, requires_license):
def read(rows, arrow_type, schema):
location = tmp_path / "lake"
write_deltalake(
Expand Down
12 changes: 11 additions & 1 deletion python/pathway/tests/test_nested_schema_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@
)
@pytest.mark.parametrize("clean_docstring", [False, True])
def test_nested_schema_read_docstring_example(
connector, clean_docstring, tmp_path, monkeypatch
connector, clean_docstring, tmp_path, monkeypatch, request
):
if connector in {
"deltalake",
"elasticsearch",
"kinesis",
"mssql",
"mysql",
"postgres",
"rabbitmq",
}:
request.getfixturevalue("requires_license")
reader = getattr(pw.io, connector).read
# Python 3.13+ can strip the common indentation when compiling docstrings.
doc = inspect.cleandoc(reader.__doc__) if clean_docstring else reader.__doc__
Expand Down
Loading
Loading