How to use the py4j.protocol.get_return_value function in py4j

To help you get started, we’ve selected a few py4j examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bartdag / py4j / py4j-python / src / py4j / java_gateway.py View on Github external
def _get_params(self, input):
        params = []
        temp = smart_decode(input.readline())[:-1]
        while temp != proto.END:
            param = get_return_value("y" + temp, self.gateway_client)
            params.append(param)
            temp = smart_decode(input.readline())[:-1]
        return params
github bartdag / py4j / py4j-python / src / py4j / java_gateway.py View on Github external
value,
        java_object._gateway_client.gateway_property.pool)

    command = proto.FIELD_COMMAND_NAME + proto.FIELD_SET_SUBCOMMAND_NAME +\
        java_object._target_id + "\n" + field_name + "\n" +\
        command_part + proto.END_COMMAND_PART

    answer = java_object._gateway_client.send_command(command)
    has_error, error_message = get_error_message(answer)

    if answer == proto.NO_MEMBER_COMMAND or has_error:
        message = compute_exception_message(
            "no field {0} in object {1}".format(
                field_name, java_object._target_id), error_message)
        raise Py4JError(message)
    return get_return_value(
        answer, java_object._gateway_client, java_object._target_id,
        field_name)
github bartdag / py4j / py4j-python / src / py4j / java_gateway.py View on Github external
def java_import(jvm_view, import_str):
    """Imports the package or class specified by `import_str` in the
    jvm view namespace.

    :param jvm_view: The jvm_view in which to import a class/package.
    :import_str: The class (e.g., java.util.List) or the package
                 (e.g., java.io.*) to import
    """
    gateway_client = jvm_view._gateway_client
    command = proto.JVMVIEW_COMMAND_NAME + proto.JVM_IMPORT_SUB_COMMAND_NAME +\
        jvm_view._id + "\n" + escape_new_line(import_str) + "\n" +\
        proto.END_COMMAND_PART
    answer = gateway_client.send_command(command)
    return_value = get_return_value(answer, gateway_client, None, None)
    return return_value
github bartdag / py4j / py4j-python / src / py4j / java_collections.py View on Github external
def __mul__(self, other):
        command = proto.LIST_COMMAND_NAME + proto.LIST_MULT_SUBCOMMAND_NAME +\
            self._get_object_id() + "\n" + get_command_part(other) +\
            proto.END_COMMAND_PART
        answer = self._gateway_client.send_command(command)
        return get_return_value(answer, self._gateway_client)
github UCLA-VAST / blaze / spark-1.5.1 / python / pyspark / sql / utils.py View on Github external
def install_exception_handler():
    """
    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.
    """
    original = py4j.protocol.get_return_value
    # The original `get_return_value` is not patched, it's idempotent.
    patched = capture_sql_exception(original)
    # only patch the one used in in py4j.java_gateway (call Java API)
    py4j.java_gateway.get_return_value = patched
github bartdag / py4j / py4j-python / src / py4j / clientserver.py View on Github external
def _get_params(self, input):
        params = []
        temp = smart_decode(input.readline())[:-1]
        while temp != proto.END:
            param = get_return_value("y" + temp, self.java_client)
            params.append(param)
            temp = smart_decode(input.readline())[:-1]
        return params
github bartdag / py4j / py4j-python / src / py4j / java_gateway.py View on Github external
def _get_field(self, name):
        command = proto.FIELD_COMMAND_NAME +\
            proto.FIELD_GET_SUBCOMMAND_NAME +\
            self._target_id + "\n" +\
            name + "\n" +\
            proto.END_COMMAND_PART

        answer = self._gateway_client.send_command(command)
        if answer == proto.NO_MEMBER_COMMAND or is_error(answer)[0]:
            return (False, None)
        else:
            return_value = get_return_value(
                answer, self._gateway_client, self._target_id, name)
            return (True, return_value)
github bartdag / py4j / py4j-python / src / py4j / java_collections.py View on Github external
def __get_slice(self, indices):
        command = proto.LIST_COMMAND_NAME +\
            proto.LIST_SLICE_SUBCOMMAND_NAME +\
            self._get_object_id() + "\n"
        for index in indices:
            command += get_command_part(index)
        command += proto.END_COMMAND_PART
        answer = self._gateway_client.send_command(command)
        return get_return_value(answer, self._gateway_client)