allisonwang-db commented on code in PR #45485:
URL: https://github.com/apache/spark/pull/45485#discussion_r1534755416
##########
python/pyspark/sql/worker/plan_data_source_read.py:
##########
@@ -264,11 +246,40 @@ def batched(iterator: Iterator, n: int) -> Iterator:
command = (data_source_read_func, return_type)
pickleSer._write_with_length(command, outfile)
- # Return the serialized partition values.
- write_int(len(partitions), outfile)
- for partition in partitions:
- pickleSer._write_with_length(partition, outfile)
-
+ if not is_streaming:
+ # The partitioning of python batch source read is determined
before query execution.
+ try:
+ partitions = reader.partitions() # type: ignore[attr-defined]
+ if not isinstance(partitions, list):
+ raise PySparkRuntimeError(
+ error_class="DATA_SOURCE_TYPE_MISMATCH",
+ message_parameters={
+ "expected": "'partitions' to return a list",
+ "actual": f"'{type(partitions).__name__}'",
+ },
+ )
+ if not all(isinstance(p, InputPartition) for p in partitions):
+ partition_types = ", ".join([f"'{type(p).__name__}'" for p
in partitions])
+ raise PySparkRuntimeError(
+ error_class="DATA_SOURCE_TYPE_MISMATCH",
+ message_parameters={
+ "expected": "elements in 'partitions' to be of
type 'InputPartition'",
+ "actual": partition_types,
+ },
+ )
+ if len(partitions) == 0:
+ partitions = [None]
+ except NotImplementedError:
+ partitions = [None]
+
+ # Return the serialized partition values.
+ write_int(len(partitions), outfile)
+ for partition in partitions:
+ pickleSer._write_with_length(partition, outfile)
+ else:
+ # Send an empty list of partition for stream reader because
partitions are planned
+ # in each microbatch during query execution.
+ write_int(0, outfile)
Review Comment:
Could you give me some code pointers on where the planning of partitions
takes place in streaming?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]