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

[SPARK-50511][PYTHON][FOLLOWUP] Avoid wrapping streaming Python data source error messages #49532

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 @@ -21,7 +21,7 @@
from typing import IO, Iterator, Tuple

from pyspark.accumulators import _accumulatorRegistry
from pyspark.errors import IllegalArgumentException, PySparkAssertionError, PySparkRuntimeError
from pyspark.errors import IllegalArgumentException, PySparkAssertionError
from pyspark.serializers import (
read_int,
write_int,
Expand Down Expand Up @@ -78,6 +78,7 @@ def partitions_func(
start_offset = json.loads(utf8_deserializer.loads(infile))
end_offset = json.loads(utf8_deserializer.loads(infile))
partitions = reader.partitions(start_offset, end_offset)

# Return the serialized partition values.
write_int(len(partitions), outfile)
for partition in partitions:
Expand Down Expand Up @@ -183,12 +184,6 @@ def main(infile: IO, outfile: IO) -> None:
},
)
outfile.flush()
except Exception as e:
error_msg = "data source {} throw exception: {}".format(data_source.name, e)
raise PySparkRuntimeError(
errorClass="PYTHON_STREAMING_DATA_SOURCE_RUNTIME_ERROR",
messageParameters={"msg": error_msg},
)
finally:
reader.stop()
except BaseException as e:
Expand Down
70 changes: 31 additions & 39 deletions python/pyspark/sql/worker/python_streaming_sink_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from typing import IO

from pyspark.accumulators import _accumulatorRegistry
from pyspark.errors import PySparkAssertionError, PySparkRuntimeError
from pyspark.errors import PySparkAssertionError
from pyspark.serializers import (
read_bool,
read_int,
Expand Down Expand Up @@ -96,44 +96,36 @@ def main(infile: IO, outfile: IO) -> None:
)
# Receive the `overwrite` flag.
overwrite = read_bool(infile)
# Instantiate data source reader.
try:
# Create the data source writer instance.
writer = data_source.streamWriter(schema=schema, overwrite=overwrite)

# Receive the commit messages.
num_messages = read_int(infile)
commit_messages = []
for _ in range(num_messages):
message = pickleSer._read_with_length(infile)
if message is not None and not isinstance(message, WriterCommitMessage):
raise PySparkAssertionError(
errorClass="DATA_SOURCE_TYPE_MISMATCH",
messageParameters={
"expected": "an instance of WriterCommitMessage",
"actual": f"'{type(message).__name__}'",
},
)
commit_messages.append(message)

batch_id = read_long(infile)
abort = read_bool(infile)

# Commit or abort the Python data source write.
# Note the commit messages can be None if there are failed tasks.
if abort:
writer.abort(commit_messages, batch_id)
else:
writer.commit(commit_messages, batch_id)
# Send a status code back to JVM.
write_int(0, outfile)
outfile.flush()
except Exception as e:
error_msg = "data source {} throw exception: {}".format(data_source.name, e)
raise PySparkRuntimeError(
errorClass="PYTHON_STREAMING_DATA_SOURCE_RUNTIME_ERROR",
messageParameters={"action": "commitOrAbort", "error": error_msg},
)
# Create the data source writer instance.
writer = data_source.streamWriter(schema=schema, overwrite=overwrite)
# Receive the commit messages.
num_messages = read_int(infile)

commit_messages = []
for _ in range(num_messages):
message = pickleSer._read_with_length(infile)
if message is not None and not isinstance(message, WriterCommitMessage):
raise PySparkAssertionError(
errorClass="DATA_SOURCE_TYPE_MISMATCH",
messageParameters={
"expected": "an instance of WriterCommitMessage",
"actual": f"'{type(message).__name__}'",
},
)
commit_messages.append(message)

batch_id = read_long(infile)
abort = read_bool(infile)

# Commit or abort the Python data source write.
# Note the commit messages can be None if there are failed tasks.
if abort:
writer.abort(commit_messages, batch_id)
else:
writer.commit(commit_messages, batch_id)
# Send a status code back to JVM.
write_int(0, outfile)
outfile.flush()
except BaseException as e:
handle_worker_exception(e, outfile)
sys.exit(-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ class PythonStreamingDataSourceSimpleSuite extends PythonDataSourceSuiteBase {
)
)
assert(err.getMessage.contains(msg))
assert(err.getMessage.contains("ErrorDataSource"))
stream.stop()
}

Expand Down Expand Up @@ -332,7 +331,6 @@ class PythonStreamingDataSourceSimpleSuite extends PythonDataSourceSuiteBase {
)
)
assert(err.getMessage.contains(msg))
assert(err.getMessage.contains("ErrorDataSource"))
stream.stop()
}

Expand Down Expand Up @@ -669,7 +667,6 @@ class PythonStreamingDataSourceSuite extends PythonDataSourceSuiteBase {
)
)
assert(err.getMessage.contains(msg))
assert(err.getMessage.contains("ErrorDataSource"))
stream.stop()
}

Expand Down Expand Up @@ -731,7 +728,6 @@ class PythonStreamingDataSourceSuite extends PythonDataSourceSuiteBase {
)
)
assert(err.getMessage.contains(msg))
assert(err.getMessage.contains("ErrorDataSource"))
stream.stop()
}

Expand Down