pyspark.sql.VariantVal#
- class pyspark.sql.VariantVal(value, metadata)[source]#
A class to represent a Variant value in Python.
Added 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.
Methods
toPython()
Convert the VariantVal to a Python data structure.
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