timsaucer commented on code in PR #1720:
URL:
https://github.com/apache/datafusion-python/pull/1720#discussion_r3980248740
##########
python/datafusion/plan.py:
##########
@@ -178,17 +179,55 @@ def __repr__(self) -> str:
@property
def partition_count(self) -> int:
- """Returns the number of partitions in the physical plan."""
+ """Returns the number of partitions in the physical plan.
+
+ Examples:
+ >>> from datafusion import SessionContext
+ >>> ctx = SessionContext()
+ >>> df = ctx.from_pydict({"a": [1, 2, 3]})
+ >>> df.execution_plan().partition_count
+ 1
+ """
return self._raw_plan.partition_count
+ @property
+ def output_partitioning(self) -> PhysicalPartitioning:
+ """Returns how this plan's output rows are spread across its
partitions.
+
+ Where :py:attr:`partition_count` gives only the number of partitions,
+ this also reports the scheme, so a caller executing partitions
+ separately can tell whether they are hash-distributed on known keys or
+ merely counted. A plan does not necessarily partition the way it was
+ asked to; see :ref:`checking_partitioning`.
+
+ Examples:
+ >>> import pyarrow as pa
+ >>> from datafusion import SessionConfig, SessionContext
+ >>> ctx = SessionContext(SessionConfig().with_target_partitions(4))
+ >>> ctx.register_record_batches("t", [
+ ... [pa.record_batch({"a": [1, 2, 3]})],
+ ... [pa.record_batch({"a": [4, 5, 6]})],
+ ... ])
+ >>> ctx.sql("select a from t").execution_plan().output_partitioning
+ UnknownPartitioning(2)
+
+ A group-by redistributes rows, so the plan reports the keys:
+
+ >>> grouped = ctx.sql("select a, count(*) from t group by a")
+ >>> partitioning = grouped.execution_plan().output_partitioning
+ >>> partitioning.scheme
+ 'Hash'
+ >>> partitioning.partition_count
+ 4
+ """
+ return PhysicalPartitioning(self._raw_plan.output_partitioning)
+
@staticmethod
def from_bytes(ctx: SessionContext, data: bytes) -> ExecutionPlan:
"""Create an ExecutionPlan from serialized protobuf bytes.
Decoding routes through the codecs installed on ``ctx`` with
:py:meth:`~datafusion.SessionContext.with_physical_extension_codec`.
- Tables created in memory from record batches are currently not
- supported.
Review Comment:
This was true for the logical side, but not the physical side so removed.
--
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]