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

add python models session submission method #814

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dbt/adapters/databricks/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version: str = "1.8.6"
version: str = "1.8.6a1"
2 changes: 2 additions & 0 deletions dbt/adapters/databricks/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from dbt.adapters.databricks.connections import USE_LONG_SESSIONS
from dbt.adapters.databricks.python_submissions import (
DbtDatabricksAllPurposeClusterPythonJobHelper,
SessionHelper
)
from dbt.adapters.databricks.python_submissions import (
DbtDatabricksJobClusterPythonJobHelper,
Expand Down Expand Up @@ -611,6 +612,7 @@ def python_submission_helpers(self) -> Dict[str, Type[PythonJobHelper]]:
return {
"job_cluster": DbtDatabricksJobClusterPythonJobHelper,
"all_purpose_cluster": DbtDatabricksAllPurposeClusterPythonJobHelper,
"session": SessionHelper,
}

@available
Expand Down
13 changes: 13 additions & 0 deletions dbt/adapters/databricks/python_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,16 @@ def check_credentials(self) -> None:
"Databricks `http_path` or `cluster_id` of an all-purpose cluster is required "
"for the `all_purpose_cluster` submission method."
)


class SessionHelper(PythonJobHelper):
def __init__(self, parsed_model: Dict, credentials: DatabricksCredentials) -> None:
pass

def submit(self, compiled_code: str) -> Any:
try:
from pyspark.sql import SparkSession
spark = SparkSession.getActiveSession()
exec(compiled_code, {"spark": spark})
except Exception as e:
raise DbtRuntimeError(f"Python model failed with traceback as:\n{e}")