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 #1063

Open
wants to merge 1 commit 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: 2 additions & 0 deletions dbt/adapters/spark/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from dbt.adapters.spark.python_submissions import (
JobClusterPythonJobHelper,
AllPurposeClusterPythonJobHelper,
SessionHelper
)
from dbt.adapters.base import BaseRelation
from dbt.adapters.contracts.relation import RelationType, RelationConfig
Expand Down Expand Up @@ -493,6 +494,7 @@ def python_submission_helpers(self) -> Dict[str, Type[PythonJobHelper]]:
return {
"job_cluster": JobClusterPythonJobHelper,
"all_purpose_cluster": AllPurposeClusterPythonJobHelper,
"session": SessionHelper,
}

def standardize_grants_dict(self, grants_table: "agate.Table") -> dict:
Expand Down
13 changes: 13 additions & 0 deletions dbt/adapters/spark/python_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,16 @@ def submit(self, compiled_code: str) -> None:
)
finally:
context.destroy(context_id)


class SessionHelper(PythonJobHelper):
def __init__(self, parsed_model: Dict, credentials: SparkCredentials) -> 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}")
Loading