-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vdk-notebook: Support for "%%vdkingest" cell type in Notebook Steps
This commit introduces the ability to recognize and execute cells with the `%%vdkingest` magic function in notebook-based data jobs. Previously, notebook steps only supported Python and SQL cell types (`%%vdksql`). This addition enriches the functionality of notebook-based steps by providing users the capability to define ingestion tasks directly within a Jupyter notebook, enhancing flexibility and usability.
- Loading branch information
1 parent
745b14d
commit b4eb6d3
Showing
10 changed files
with
126 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ click | |
pytest | ||
requests | ||
vdk-core | ||
vdk-data-sources | ||
vdk-sqlite | ||
vdk-test-utils |
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
27 changes: 27 additions & 0 deletions
27
projects/vdk-plugins/vdk-notebook/src/vdk/plugin/notebook/vdk_ingest.py
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,27 @@ | ||
# Copyright 2021-2023 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from vdk.api.job_input import IJobInput | ||
|
||
|
||
TYPE_INGEST = "ingest" | ||
|
||
|
||
def run_ingest_step(step: "NotebookCellStep", job_input: IJobInput) -> bool: | ||
""" | ||
Run ingest data flow step. Only if vdk-data-sources is installed. | ||
""" | ||
try: | ||
from vdk.plugin.data_sources.mapping.data_flow import DataFlowInput | ||
from vdk.plugin.data_sources.mapping import toml_parser | ||
except ImportError: | ||
raise ImportError( | ||
"vdk-data-sources is not installed. ingestion step is not available without it" | ||
) | ||
|
||
import toml | ||
|
||
parsed_toml = toml.loads(step.source) | ||
definitions = toml_parser.definitions_from_dict(parsed_toml) | ||
|
||
with DataFlowInput(job_input) as flow_input: | ||
flow_input.start_flows(definitions) |
63 changes: 63 additions & 0 deletions
63
projects/vdk-plugins/vdk-notebook/tests/jobs/ingest-data-flow-job/steps.ipynb
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,63 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "654db028-2d0e-4f95-a377-e1fac1255f08", | ||
"metadata": { | ||
"tags": [ | ||
"vdk" | ||
], | ||
"pycharm": { | ||
"name": "#%%\n" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%%vdkingest\n", | ||
"[sources]\n", | ||
"s1 = {name = \"auto-generated-data\"}\n", | ||
"\n", | ||
"[destinations]\n", | ||
"d1 = {method = \"memory\"}\n", | ||
"\n", | ||
"[[flows]]\n", | ||
"from=\"s1\"\n", | ||
"to=\"d1\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "532975cd-2e85-465f-b510-bdfd264192cf", | ||
"metadata": { | ||
"tags": [ | ||
"vdk" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
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,24 @@ | ||
# Copyright 2021-2023 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from click.testing import Result | ||
from vdk.plugin.data_sources import plugin_entry as data_sources_plugin_entry | ||
from vdk.plugin.notebook import notebook_plugin | ||
from vdk.plugin.test_utils.util_funcs import cli_assert_equal | ||
from vdk.plugin.test_utils.util_funcs import CliEntryBasedTestRunner | ||
from vdk.plugin.test_utils.util_funcs import jobs_path_from_caller_directory | ||
from vdk.plugin.test_utils.util_plugins import IngestIntoMemoryPlugin | ||
|
||
|
||
def test_ingest_vdkingest(): | ||
ingest_plugin = IngestIntoMemoryPlugin() | ||
runner = CliEntryBasedTestRunner( | ||
ingest_plugin, data_sources_plugin_entry, notebook_plugin | ||
) | ||
|
||
result: Result = runner.invoke( | ||
["run", jobs_path_from_caller_directory("ingest-data-flow-job")] | ||
) | ||
|
||
cli_assert_equal(0, result) | ||
|
||
assert len(ingest_plugin.payloads) > 0 |