Skip to content
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

Infer values from child notebook loaded via dbutils.notebook.run() call #2083

Conversation

ericvergnaud
Copy link
Contributor

@ericvergnaud ericvergnaud commented Jul 4, 2024

Changes

When linting notebooks, use AST from child notebooks loaded via dbutils.notebook.run() to infer values

Linked issues

Progresses #1205
Progresses #1901

Functionality

None

Tests

  • added unit tests

marginally improves not computed (-9/744) when running make solacc

@ericvergnaud ericvergnaud requested review from a team and HariGS-DB July 4, 2024 15:34
Copy link
Collaborator

@nfx nfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-process a collection of cells into a single tree and revert any refactoring that makes this PR hard to review.

@property
def is_append(self):
return self._is_append
def mutate_path_lookup(self, path_lookup: PathLookup):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def mutate_path_lookup(self, path_lookup: PathLookup):
def apply_to(self, path_lookup: PathLookup):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -192,191 +198,29 @@ def _get_attribute_value(cls, node: Attribute):
logger.debug(f"Missing handler for {name}")
return None

def infer_values(self, state: CurrentSessionState | None = None) -> Iterable[InferredValue]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is a bit more difficult to review, as methods are moved, the reasoning is not clear

Copy link
Contributor Author

@ericvergnaud ericvergnaud Jul 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code is moved to work around cyclic imports

@@ -0,0 +1,221 @@
from __future__ import annotations
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't mix refactoring and new features in the same PR. it's completely unclear to me what changed in these changes and what's the new code. please revert the introduction of this module in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was moved from python_ast to work around cyclic imports

src/databricks/labs/ucx/source_code/base.py Outdated Show resolved Hide resolved
@nfx nfx added the pr/do-not-merge this pull request is not ready to merge label Jul 5, 2024
…notebook-run-call

# Conflicts:
#	src/databricks/labs/ucx/source_code/base.py
#	src/databricks/labs/ucx/source_code/known.json
#	src/databricks/labs/ucx/source_code/linters/imports.py
#	src/databricks/labs/ucx/source_code/linters/python_ast.py
#	src/databricks/labs/ucx/source_code/notebooks/sources.py
#	tests/unit/source_code/linters/test_python_ast.py
#	tests/unit/source_code/test_notebook_linter.py
…notebook-run-call

# Conflicts:
#	src/databricks/labs/ucx/source_code/base.py
#	src/databricks/labs/ucx/source_code/jobs.py
#	src/databricks/labs/ucx/source_code/known.py
#	src/databricks/labs/ucx/source_code/linters/files.py
#	src/databricks/labs/ucx/source_code/notebooks/cells.py
#	src/databricks/labs/ucx/source_code/notebooks/sources.py
#	tests/unit/source_code/notebooks/test_sources.py
#	tests/unit/source_code/test_functional.py
#	tests/unit/source_code/test_notebook_linter.py
Copy link

github-actions bot commented Jul 9, 2024

✅ 160/160 passed, 1 flaky, 6 skipped, 3h39m15s total

Flaky tests:

  • 🤪 test_experimental_permissions_migration_for_group_with_same_name (2m15.958s)

Running from acceptance #4548

@ericvergnaud ericvergnaud enabled auto-merge July 9, 2024 11:14
@ericvergnaud
Copy link
Contributor Author

@nfx is something still blocking this PR?

@nfx nfx requested review from asnare and JCZuurmond and removed request for HariGS-DB July 10, 2024 12:16
@nfx nfx removed the pr/do-not-merge this pull request is not ready to merge label Jul 10, 2024
Copy link
Collaborator

@nfx nfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please verify in the real workspace

src/databricks/labs/ucx/source_code/base.py Outdated Show resolved Hide resolved
src/databricks/labs/ucx/source_code/notebooks/cells.py Outdated Show resolved Hide resolved
src/databricks/labs/ucx/source_code/notebooks/sources.py Outdated Show resolved Hide resolved
src/databricks/labs/ucx/source_code/notebooks/sources.py Outdated Show resolved Hide resolved
yield from self._mutate_path_lookup(base_node)
return
if isinstance(base_node, NotebookRunCall):
has_unresolved, paths = base_node.get_notebook_paths(self._session_state)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you 100% sure this behavior is necessary? dbutils.notebook.run() does not propagate variables to the parent notebook, only %run does. provide a screenshot from a real workspace environment to confirm this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, that was an incorrect assumption

# Databricks notebook source

dbutils.notebook.run("./values_across_notebooks_child.py")
spark.table(f"{a}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure this is the right logic? my hunch it does not compute on workspace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@ericvergnaud
Copy link
Contributor Author

closing in favor of #2091

auto-merge was automatically disabled July 10, 2024 14:24

Pull request was closed

@ericvergnaud ericvergnaud deleted the infer-values-from-child-notebook-in-dbutils-notebook-run-call branch July 11, 2024 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants