Skip to content
Open
Changes from 2 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
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