pyspark.sql.VariantVal#
- class pyspark.sql.VariantVal(value, metadata)[source]#
A class to represent a Variant value in Python.
New in version 4.0.0.
- Parameters
- valuebytes
The bytes representing the value component of the Variant.
- metadatabytes
The bytes representing the metadata component of the Variant.
Examples
>>> 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}'
Methods
toPython()
Convert the VariantVal to a Python data structure.
Methods
parseJson
(json_str)Convert the VariantVal to a nested Python object of Python data types.
toJson
([zone_id])Convert the VariantVal to a JSON string.
toPython
()Convert the VariantVal to a Python data structure.