Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #
desc = desc + "\n\nJVM stacktrace:\n%s" % self.stackTrace
""" Failed to analyze a SQL query plan. """
""" Failed to parse a SQL command. """
""" Passed an illegal or inappropriate argument. """
""" Exception that stopped a :class:`StreamingQuery`. """
""" Failed to execute a query. """
""" Exceptions thrown from Python workers. """
""" None of the above exceptions. """
return QueryExecutionException(s.split(': ', 1)[1], stacktrace, c) c.toString().startswith('org.apache.spark.api.python.PythonException: ') # To make sure this only catches Python UDFs. and any(map(lambda v: "org.apache.spark.sql.execution.python" in v.toString(), c.getStackTrace()))): "Please see the stack trace below.\n%s" % c.getMessage())
# Hide where the exception came from that shows a non-Pythonic # JVM exception message. else:
""" Hook an exception handler into Py4j, which could capture some SQL exceptions in Java.
When calling Java API, it will call `get_return_value` to parse the returned object. If any exception happened in JVM, the result will be Java exception object, it raise py4j.protocol.Py4JJavaError. We replace the original `get_return_value` with one that could capture the Java exception and throw a Python one (with the same error message).
It's idempotent, could be called multiple times. """ # The original `get_return_value` is not patched, it's idempotent. # only patch the one used in py4j.java_gateway (call Java API)
""" Convert python list to java type array
Parameters ---------- gateway : Py4j Gateway jtype : java type of element in array arr : python type list """ jarray = gateway.new_array(jtype, len(arr)) for i in range(0, len(arr)): jarray[i] = arr[i] return jarray
""" Raise Exception if test classes are not compiled """ except KeyError: raise RuntimeError('SPARK_HOME is not defined in environment')
spark_home, 'sql', 'core', 'target', '*', 'test-classes')
raise RuntimeError( "%s doesn't exist. Spark sql test classes are not compiled." % test_class_path)
""" This is the Python implementation of Java interface 'ForeachBatchFunction'. This wraps the user-defined 'foreachBatch' function such that it can be called from the JVM when the query is active. """
""" A wrapper over str(), but converts bool values to lower case strings. If None is given, just returns None, instead of converting it to string "None". """ else: |