yggdrasil.pickle.ser.pyspark¶
pyspark ¶
PySpark serialization support.
Wire-tag range: 700–799 (PYSPARK_BASE = 700)
Objects covered¶
pyspark.sql.DataFrame -> PYSPARK_DATAFRAME (700) via PyArrow IPC file pyspark.sql.Row -> PYSPARK_ROW (701) via Arrow record-batch pyspark.sql.types.StructType -> PYSPARK_SCHEMA (702) via Arrow IPC schema pyspark.sql.types.DataType -> PYSPARK_DATATYPE (703) via JSON repr pyspark.sql.Column -> PYSPARK_COLUMN (704) via pickle/cloudpickle pyspark.RDD -> PYSPARK_RDD (705) collect() → Arrow IPC pyspark.sql.SparkSession -> PYSPARK_SESSION (706) not reconstructed; serialised as a metadata-only stub
DataFrame / RDD payloads delegate to pyarrow. All other PySpark objects that cannot be naturally expressed with Arrow fall back to cloudpickle (if available) or standard pickle.
Decoding note¶
SparkSession references are not reconstructed on load. value returns
None for PYSPARK_SESSION because a live Spark context cannot be round-
tripped through bytes. The serialized form serves as documentation / provenance
only.
PySparkSerialized
dataclass
¶
Bases: Serialized[TPySpark], Generic[TPySpark]
Abstract base for all PySpark-flavoured Serialized subclasses.
PySparkDataFrameSerialized
dataclass
¶
Bases: PySparkSerialized[Any]
Serialize a pyspark.sql.DataFrame by collecting it to the driver and
storing the result as an Arrow IPC file.
On deserialization a pyarrow.Table is returned (not a DataFrame) because
there is no live SparkSession available at load time. Call
.to_pyspark(spark) to re-wrap if a session is available.
to_pyspark ¶
Re-create a pyspark.sql.DataFrame from the stored Arrow data.
Uses :func:~yggdrasil.spark.cast.arrow_table_to_spark_dataframe which
requires an active SparkSession (obtained via
SparkSession.getActiveSession() when spark is None).
Parameters¶
spark:
An active pyspark.sql.SparkSession, or None to use the
currently-active session.
module_and_name
staticmethod
¶
Return (module, qualname) for obj.
Robust across Python objects, including many C-extension / PyArrow objects where module may be missing or misleading.
decode_arrow_buffer ¶
Return payload as a pyarrow.Buffer for IPC reads.
PySparkRowSerialized
dataclass
¶
Bases: PySparkSerialized[Any]
Serialize a pyspark.sql.Row as a one-row Arrow RecordBatch.
PySparkSchemaSerialized
dataclass
¶
Bases: PySparkSerialized[Any]
Serialize a pyspark.sql.types.StructType as an Arrow IPC schema.
On load, if PySpark is available the Arrow schema is converted back to a
StructType; otherwise a pyarrow.Schema is returned.
PySparkDataTypeSerialized
dataclass
¶
Bases: PySparkSerialized[Any]
Serialize a pyspark.sql.types.DataType via its JSON representation.
PySparkColumnSerialized
dataclass
¶
Bases: PySparkSerialized[Any]
Serialize a pyspark.sql.Column expression.
Column objects are opaque JVM-backed objects. We use cloudpickle (preferred) or standard pickle as the storage strategy. Note that the deserialized Column requires the same PySpark / JVM version to be available.
PySparkRDDSerialized
dataclass
¶
Bases: PySparkSerialized[Any]
Serialize a pyspark.RDD by collecting all elements to the driver.
Elements must be homogeneous and Arrow-convertible (e.g. Rows, dicts, tuples, or primitives). The collected data is stored as an Arrow IPC file.
On deserialization, a pyarrow.Table is returned.
PySparkSessionSerialized
dataclass
¶
Bases: PySparkSerialized[None]
Provenance stub for a pyspark.sql.SparkSession.
A live SparkSession cannot be serialized in a meaningful way – it is a
client handle to a running JVM. We store app-name, master URL, and Spark
version as metadata, and return None on deserialization.