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

SQLQuery default print error instead of throwing error stack #581

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions sparkmagic/sparkmagic/livyclientlib/sqlquery.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from hdijupyterutils.guid import ObjectWithGuid
from hdijupyterutils.ipythondisplay import IpythonDisplay

from sparkmagic.utils.utils import coerce_pandas_df_to_numeric_datetime, records_to_dataframe
import sparkmagic.utils.configuration as conf
import sparkmagic.utils.constants as constants
from sparkmagic.utils.sparkevents import SparkEvents
from .command import Command
from .exceptions import DataFrameParseException, BadUserDataException
from .exceptions import DataFrameParseException, BadUserDataException, SparkStatementException


class SQLQuery(ObjectWithGuid):
Expand All @@ -25,6 +26,7 @@ def __init__(self, query, samplemethod=None, maxrows=None, samplefraction=None,
raise BadUserDataException(u'maxrows (-n) must be an integer')
if not 0.0 <= samplefraction <= 1.0:
raise BadUserDataException(u'samplefraction (-r) must be a float between 0.0 and 1.0')
self.ipython_display = IpythonDisplay()

self.query = query
self.samplemethod = samplemethod
Expand All @@ -49,13 +51,17 @@ def execute(self, session):
self._spark_events.emit_sql_execution_start_event(session.guid, session.kind, session.id, self.guid,
self.samplemethod, self.maxrows, self.samplefraction)
command_guid = ''
result = None
try:
command = self.to_command(session.kind, session.sql_context_variable_name)
command_guid = command.guid
(success, records_text, mimetype) = command.execute(session)
if not success:
raise BadUserDataException(records_text)
result = records_to_dataframe(records_text, session.kind, self._coerce)
if conf.spark_statement_errors_are_fatal():
raise SparkStatementException(records_text)
self.ipython_display.send_error(records_text)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If conf.spark_statement_errors_are_fatal() == False and a SparkStatementException is raised then wouldn't this be handled and displayed by handle_expected_exceptions?

else:
result = records_to_dataframe(records_text, session.kind, self._coerce)
except Exception as e:
self._spark_events.emit_sql_execution_end_event(session.guid, session.kind, session.id, self.guid,
command_guid, False, e.__class__.__name__, str(e))
Expand Down