-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new queries to the Database (#356)
This commit adds new queries to the Database to: - Get the `Port` row of the `Token` defined in the parameter - Get the `Step` rows which have a dependency with the `Port` defined in the parameter Moreover, this commit adds two methods to create the `Token` objects after the queries `get_dependees` and `get_dependers`
- Loading branch information
1 parent
09d7058
commit ac8f41a
Showing
7 changed files
with
146 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import asyncio | ||
|
||
from streamflow.core.context import StreamFlowContext | ||
from streamflow.core.persistence import DatabaseLoadingContext | ||
|
||
|
||
async def load_depender_tokens( | ||
persistent_id: int, | ||
context: StreamFlowContext, | ||
loading_context: DatabaseLoadingContext, | ||
): | ||
rows = await context.database.get_dependers(persistent_id) | ||
return await asyncio.gather( | ||
*( | ||
asyncio.create_task(loading_context.load_token(context, row["depender"])) | ||
for row in rows | ||
) | ||
) | ||
|
||
|
||
async def load_dependee_tokens( | ||
persistent_id: int, | ||
context: StreamFlowContext, | ||
loading_context: DatabaseLoadingContext, | ||
): | ||
rows = await context.database.get_dependees(persistent_id) | ||
return await asyncio.gather( | ||
*( | ||
asyncio.create_task(loading_context.load_token(context, row["dependee"])) | ||
for row in rows | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest | ||
|
||
from streamflow.core import utils | ||
from streamflow.core.context import StreamFlowContext | ||
from streamflow.workflow.step import ExecuteStep | ||
from tests.utils.workflow import create_workflow | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_steps_queries(context: StreamFlowContext): | ||
"""Test get_input_steps and get_output_steps queries""" | ||
workflow, (port_a, job_port, job_port_2, port_b, port_c) = await create_workflow( | ||
context, num_port=5 | ||
) | ||
step = workflow.create_step( | ||
cls=ExecuteStep, name=utils.random_name(), job_port=job_port | ||
) | ||
step_2 = workflow.create_step( | ||
cls=ExecuteStep, name=utils.random_name(), job_port=job_port_2 | ||
) | ||
step.add_input_port("in", port_a) | ||
step.add_output_port("out", port_b) | ||
step_2.add_input_port("in2", port_b) | ||
step_2.add_output_port("out2", port_c) | ||
await workflow.save(context) | ||
|
||
input_steps_port_a = await context.database.get_input_steps(port_a.persistent_id) | ||
assert len(input_steps_port_a) == 0 | ||
output_steps_port_a = await context.database.get_output_steps(port_a.persistent_id) | ||
assert len(output_steps_port_a) == 1 | ||
assert output_steps_port_a[0]["step"] == step.persistent_id | ||
|
||
input_steps_port_b = await context.database.get_input_steps(port_b.persistent_id) | ||
assert len(input_steps_port_b) == 1 | ||
assert input_steps_port_b[0]["step"] == step.persistent_id | ||
output_steps_port_b = await context.database.get_output_steps(port_b.persistent_id) | ||
assert len(output_steps_port_b) == 1 | ||
assert output_steps_port_b[0]["step"] == step_2.persistent_id | ||
|
||
input_steps_port_c = await context.database.get_input_steps(port_c.persistent_id) | ||
assert len(input_steps_port_c) == 1 | ||
assert input_steps_port_c[0]["step"] == step_2.persistent_id | ||
output_steps_port_c = await context.database.get_output_steps(port_c.persistent_id) | ||
assert len(output_steps_port_c) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters