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.functions import *
>>> df = spark.createDataFrame([ {'json': '''{ "a" : 1 }'''} ])
>>> v = df.select(parse_json(df.json).alias("var")).collect()[0].var
>>> v.toPython()
{'a': 1}

Methods

toPython()

Convert the VariantVal to a Python data structure.

Methods

toJson([zone_id])

Convert the VariantVal to a JSON string.

toPython()

Convert the VariantVal to a Python data structure.