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

[ADAP-558] Wrap AnalysisException into DbtRuntimeError #782

Merged
merged 15 commits into from
Aug 10, 2023
Merged
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230517-142331.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Wrap AnalysisException into DbtRuntimeError
time: 2023-05-17T14:23:31.263799+02:00
custom:
Author: Fokko
Issue: "782"
11 changes: 9 additions & 2 deletions dbt/adapters/spark/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from types import TracebackType
from typing import Any, Dict, List, Optional, Tuple, Union, Sequence

from dbt.adapters.spark.connections import SparkConnectionWrapper
from dbt.events import AdapterLogger
from dbt.utils import DECIMALS
from dbt.exceptions import DbtRuntimeError
from pyspark.sql import DataFrame, Row, SparkSession
from dbt.adapters.spark.connections import SparkConnectionWrapper
from pyspark.sql.utils import AnalysisException


logger = AdapterLogger("Spark")
Expand Down Expand Up @@ -110,13 +112,18 @@ def execute(self, sql: str, *parameters: Any) -> None:
"""
if len(parameters) > 0:
sql = sql % parameters

builder = SparkSession.builder.enableHiveSupport()

for parameter, value in self.server_side_parameters.items():
builder = builder.config(parameter, value)

spark_session = builder.getOrCreate()
self._df = spark_session.sql(sql)

try:
self._df = spark_session.sql(sql)
except AnalysisException as exc:
raise DbtRuntimeError(str(exc)) from exc

def fetchall(self) -> Optional[List[Row]]:
"""
Expand Down