From 9dd3252a7468bba32dd3581f277da97c0dd20bcf Mon Sep 17 00:00:00 2001 From: stczwd Date: Sat, 12 Oct 2019 15:22:43 +0800 Subject: [PATCH 1/2] SQLQuery default print error instead of throwing error stack --- sparkmagic/sparkmagic/livyclientlib/sqlquery.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sparkmagic/sparkmagic/livyclientlib/sqlquery.py b/sparkmagic/sparkmagic/livyclientlib/sqlquery.py index 6f460810b..2df2124f3 100644 --- a/sparkmagic/sparkmagic/livyclientlib/sqlquery.py +++ b/sparkmagic/sparkmagic/livyclientlib/sqlquery.py @@ -5,7 +5,7 @@ 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): @@ -49,13 +49,19 @@ 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(): + if conf.shutdown_session_on_spark_statement_errors(): + self.spark_controller.cleanup() + raise SparkStatementException(records_text) + self.ipython_display.send_error(records_text) + 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)) From e4efcf00b19725fefcbd1ca8c2afb96f0d5e56e0 Mon Sep 17 00:00:00 2001 From: stczwd Date: Thu, 24 Oct 2019 19:36:56 +0800 Subject: [PATCH 2/2] Fix: add definition for IpythonDisplay --- sparkmagic/sparkmagic/livyclientlib/sqlquery.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sparkmagic/sparkmagic/livyclientlib/sqlquery.py b/sparkmagic/sparkmagic/livyclientlib/sqlquery.py index 2df2124f3..f8b54d963 100644 --- a/sparkmagic/sparkmagic/livyclientlib/sqlquery.py +++ b/sparkmagic/sparkmagic/livyclientlib/sqlquery.py @@ -1,4 +1,5 @@ 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 @@ -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 @@ -56,8 +58,6 @@ def execute(self, session): (success, records_text, mimetype) = command.execute(session) if not success: if conf.spark_statement_errors_are_fatal(): - if conf.shutdown_session_on_spark_statement_errors(): - self.spark_controller.cleanup() raise SparkStatementException(records_text) self.ipython_display.send_error(records_text) else: