-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add DirectFsAccess
progress encoder
#3315
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d5654d0
Add direct fs access progress
JCZuurmond a9e6b3c
Add id attributes to direct fs access
JCZuurmond 099bf88
Test direct fs access progress encoder
JCZuurmond 7edee0c
Add direct fs access progress encoder to runtime context
JCZuurmond f94168d
Append inventory snapshot in assess dashboards
JCZuurmond 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 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,45 @@ | ||||||
from dataclasses import replace | ||||||
|
||||||
from databricks.labs.lsql.backends import SqlBackend | ||||||
|
||||||
from databricks.labs.ucx.progress.history import ProgressEncoder | ||||||
from databricks.labs.ucx.progress.install import Historical | ||||||
from databricks.labs.ucx.source_code.base import DirectFsAccess | ||||||
from databricks.labs.ucx.source_code.directfs_access import DirectFsAccessOwnership | ||||||
|
||||||
|
||||||
class DirectFsAccessProgressEncoder(ProgressEncoder[DirectFsAccess]): | ||||||
"""Encoder class:DirectFsAccess to class:History. | ||||||
|
||||||
A direct filesystem is by definition a failure as it is not supported in Unity Catalog. | ||||||
""" | ||||||
|
||||||
def __init__( | ||||||
self, | ||||||
sql_backend: SqlBackend, | ||||||
ownership: DirectFsAccessOwnership, | ||||||
run_id: int, | ||||||
workspace_id: int, | ||||||
catalog: str, | ||||||
schema: str = "multiworkspace", | ||||||
table: str = "historical", | ||||||
) -> None: | ||||||
super().__init__( | ||||||
sql_backend, | ||||||
ownership, | ||||||
DirectFsAccess, | ||||||
run_id, | ||||||
workspace_id, | ||||||
catalog, | ||||||
schema, | ||||||
table, | ||||||
) | ||||||
|
||||||
def _encode_record_as_historical(self, record: DirectFsAccess) -> Historical: | ||||||
"""Encode record as historical. | ||||||
|
||||||
A direct filesystem is by definition a failure as it is not supported in Unity Catalog. | ||||||
""" | ||||||
historical = super()._encode_record_as_historical(record) | ||||||
failure = "Direct filesystem access is not supported in Unity Catalog" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and add it to a notebook/view/sql query/dashboard |
||||||
return replace(historical, failures=historical.failures + [failure]) |
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,37 @@ | ||
import datetime as dt | ||
from unittest.mock import create_autospec | ||
|
||
from databricks.labs.ucx.framework.owners import Ownership | ||
from databricks.labs.ucx.framework.utils import escape_sql_identifier | ||
from databricks.labs.ucx.progress.directfs_access import DirectFsAccessProgressEncoder | ||
from databricks.labs.ucx.source_code.base import DirectFsAccess, LineageAtom | ||
|
||
|
||
def test_direct_filesystem_access_progress_encoder_failures(mock_backend) -> None: | ||
"""A direct filesystem access is a failure by definition as it is not supported by Unity Catalog.""" | ||
direct_filesystem_access = DirectFsAccess( | ||
path="dbfs://folder/file.csv", | ||
is_read=True, | ||
is_write=False, | ||
source_id="path/to/file.py", | ||
source_lineage=[LineageAtom(object_type="FILE", object_id="path/to/file.py")], | ||
source_timestamp=dt.datetime.now(dt.timezone.utc), | ||
assessment_start_timestamp=dt.datetime.now(dt.timezone.utc), | ||
assessment_end_timestamp=dt.datetime.now(dt.timezone.utc), | ||
) | ||
ownership = create_autospec(Ownership) | ||
ownership.owner_of.return_value = "user" | ||
encoder = DirectFsAccessProgressEncoder( | ||
mock_backend, | ||
ownership, | ||
run_id=1, | ||
workspace_id=123456789, | ||
catalog="test", | ||
) | ||
|
||
encoder.append_inventory_snapshot([direct_filesystem_access]) | ||
|
||
rows = mock_backend.rows_written_for(escape_sql_identifier(encoder.full_name), "append") | ||
assert len(rows) > 0, f"No rows written for: {encoder.full_name}" | ||
assert rows[0].failures == ["Direct filesystem access is not supported in Unity Catalog"] | ||
ownership.owner_of.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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it belong to a notebook/sql query/dashboard, rather than being it's own top-level entity?