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

[KYUUBI #5877][FOLLOWUP] Catch all exception when dump the result to json and fix typo #6039

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,21 @@ def main():
"content": {
"status": "error",
"ename": "ValueError",
"evalue": "cannot json-ify %s" % response,
"evalue": "cannot json-ify %s" % result,
"traceback": [],
},
}
)
except Exception:
exc_type, exc_value, tb = sys.exc_info()
result = json.dumps(
{
"msg_type": "inspect_reply",
"content": {
"status": "error",
"ename": str(exc_type.__name__),
"evalue": "cannot json-ify %s: %s"
% (result, str(exc_value)),
"traceback": [],
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ class PySparkTests extends WithKyuubiServer with HiveJDBCTestHelper {
}
}

test("catch all exception when dump the result to json") {
checkPythonRuntimeAndVersion()
withSessionConf()(Map(KyuubiConf.ENGINE_SPARK_PYTHON_MAGIC_ENABLED.key -> "true"))() {
withMultipleConnectionJdbcStatement()({ stmt =>
val statement = stmt.asInstanceOf[KyuubiStatement]
statement.executePython("l = [('Alice', 1)]")
statement.executePython("df = spark.createDataFrame(l)")
val errorMsg = intercept[KyuubiSQLException] {
statement.executePython("%json df")
}.getMessage
assert(errorMsg.contains("Object of type DataFrame is not JSON serializable"))

statement.executePython("df = spark.createDataFrame(l).collect()")
val result = statement.executePython("%json df")
assert(result.next())
assert(result.getString("output") == "{\"application/json\":[[\"Alice\",1]]}")
})
}
}

private def runPySparkTest(
pyCode: String,
output: String): Unit = {
Expand Down
Loading