VariantVal class
A class to represent a Variant value in Python.
Syntax
Python
from pyspark.sql.types import VariantVal
VariantVal(value, metadata)
Parameters
Parameter | Type | Description |
|---|---|---|
| bytes | The bytes representing the value component of the Variant. |
| bytes | The bytes representing the metadata component of the Variant. |
Methods
Method | Description |
|---|---|
Convert the VariantVal to a Python data structure. | |
Convert the VariantVal to a JSON string. The zone ID represents the time zone that the timestamp should be printed in. It is defaulted to UTC. The list of valid zone IDs can be found by importing the zoneinfo module and running | |
Convert the VariantVal to a nested Python object of Python data types. |
Examples
Python
from pyspark.sql import functions as sf
df = spark.createDataFrame([ {'json': '''{ "a" : 1 }'''} ])
v = df.select(sf.parse_json(df.json).alias("var")).head().var
v.toPython()
# {'a': 1}
v.toJson()
# '{"a":1}'