-
Notifications
You must be signed in to change notification settings - Fork 76
Add method to upload DuckDB files to Unity Catalog Volume with tests #2024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
radhikaathalye-db
wants to merge
3
commits into
feature/add_local_dashboards
Choose a base branch
from
feature/upload_duckdb_extract
base: feature/add_local_dashboards
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
f8982dd
Add method to upload DuckDB files to Unity Catalog Volume with tests
radhikaathalye-db 8370ef6
Merge latest from feature/add_local_dashboards into feature/upload_du…
radhikaathalye-db 72c3f87
refactor: use workspaceClient instead of requests; fix error logging
radhikaathalye-db 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
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,24 +1,56 @@ | ||
import os | ||
import io | ||
import pytest | ||
|
||
from .utils.profiler_extract_utils import build_mock_synapse_extract | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def mock_synapse_profiler_extract(): | ||
synapse_extract_path = build_mock_synapse_extract("mock_profiler_extract") | ||
return synapse_extract_path | ||
|
||
|
||
# Step One: | ||
# Fetch environment variables for Databricks workspace URL, token, catalog, schema, volume name | ||
# This will be moved into CLI prompts | ||
|
||
# Step Two: | ||
# Test that the DuckDB file can be uploaded to a target UC Volume | ||
# TODO: Create class/function for uploading Duck DB file | ||
|
||
# Step Three: | ||
# Test that the job can be deployed to Databricks workspace | ||
|
||
# Step Four: | ||
# Test that the dashboard can be deployed to the workspace | ||
from unittest.mock import MagicMock, patch | ||
from databricks.labs.lakebridge.assessments.dashboards.dashboard_manager import DashboardManager | ||
|
||
@pytest.fixture | ||
def mock_workspace_client(): | ||
return MagicMock() | ||
|
||
@pytest.fixture | ||
def mock_user(): | ||
return MagicMock() | ||
|
||
@pytest.fixture | ||
def dashboard_manager(mock_workspace_client, mock_user): | ||
return DashboardManager(ws=mock_workspace_client, current_user=mock_user) | ||
|
||
@patch("os.path.exists") | ||
def test_upload_duckdb_to_uc_volume_file_not_found(mock_exists, dashboard_manager): | ||
mock_exists.return_value = False | ||
result = dashboard_manager.upload_duckdb_to_uc_volume("non_existent_file.duckdb", "/Volumes/catalog/schema/volume/myfile.duckdb") | ||
assert result is False | ||
dashboard_manager._ws.files.upload.assert_not_called() | ||
|
||
def test_upload_duckdb_to_uc_volume_invalid_volume_path(dashboard_manager): | ||
result = dashboard_manager.upload_duckdb_to_uc_volume("file.duckdb", "invalid_path/myfile.duckdb") | ||
assert result is False | ||
dashboard_manager._ws.files.upload.assert_not_called() | ||
|
||
@patch("os.path.exists") | ||
@patch("builtins.open", new_callable=MagicMock) | ||
def test_upload_duckdb_to_uc_volume_success(mock_open, mock_exists, dashboard_manager): | ||
mock_exists.return_value = True | ||
mock_open.return_value.__enter__.return_value.read.return_value = b"test_data" | ||
dashboard_manager._ws.files.upload = MagicMock() | ||
|
||
result = dashboard_manager.upload_duckdb_to_uc_volume("file.duckdb", "/Volumes/catalog/schema/volume/myfile.duckdb") | ||
assert result is True | ||
dashboard_manager._ws.files.upload.assert_called_once() | ||
args, kwargs = dashboard_manager._ws.files.upload.call_args | ||
assert args[0] == "/Volumes/catalog/schema/volume/myfile.duckdb" | ||
assert isinstance(args[1], io.BytesIO) | ||
assert args[1].getvalue() == b"test_data" | ||
assert kwargs["overwrite"] is True | ||
|
||
@patch("os.path.exists") | ||
@patch("builtins.open", new_callable=MagicMock) | ||
def test_upload_duckdb_to_uc_volume_failure(mock_open, mock_exists, dashboard_manager): | ||
mock_exists.return_value = True | ||
mock_open.return_value.__enter__.return_value.read.return_value = b"test_data" | ||
dashboard_manager._ws.files.upload = MagicMock(side_effect=Exception("Upload failed")) | ||
|
||
result = dashboard_manager.upload_duckdb_to_uc_volume("file.duckdb", "/Volumes/catalog/schema/volume/myfile.duckdb") | ||
assert result is False | ||
dashboard_manager._ws.files.upload.assert_called_once() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.