aboutsummaryrefslogtreecommitdiff
path: root/python/pyspark/sql.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/pyspark/sql.py')
-rw-r--r--python/pyspark/sql.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/python/pyspark/sql.py b/python/pyspark/sql.py
index f0bd3cbd98..93bfc25bca 100644
--- a/python/pyspark/sql.py
+++ b/python/pyspark/sql.py
@@ -313,12 +313,15 @@ class StructField(DataType):
"""
- def __init__(self, name, dataType, nullable):
+ def __init__(self, name, dataType, nullable, metadata=None):
"""Creates a StructField
:param name: the name of this field.
:param dataType: the data type of this field.
:param nullable: indicates whether values of this field
can be null.
+ :param metadata: metadata of this field, which is a map from string
+ to simple type that can be serialized to JSON
+ automatically
>>> (StructField("f1", StringType, True)
... == StructField("f1", StringType, True))
@@ -330,6 +333,7 @@ class StructField(DataType):
self.name = name
self.dataType = dataType
self.nullable = nullable
+ self.metadata = metadata or {}
def __repr__(self):
return "StructField(%s,%s,%s)" % (self.name, self.dataType,
@@ -338,13 +342,15 @@ class StructField(DataType):
def jsonValue(self):
return {"name": self.name,
"type": self.dataType.jsonValue(),
- "nullable": self.nullable}
+ "nullable": self.nullable,
+ "metadata": self.metadata}
@classmethod
def fromJson(cls, json):
return StructField(json["name"],
_parse_datatype_json_value(json["type"]),
- json["nullable"])
+ json["nullable"],
+ json["metadata"])
class StructType(DataType):
@@ -423,7 +429,8 @@ def _parse_datatype_json_string(json_string):
... StructField("simpleArray", simple_arraytype, True),
... StructField("simpleMap", simple_maptype, True),
... StructField("simpleStruct", simple_structtype, True),
- ... StructField("boolean", BooleanType(), False)])
+ ... StructField("boolean", BooleanType(), False),
+ ... StructField("withMeta", DoubleType(), False, {"name": "age"})])
>>> check_datatype(complex_structtype)
True
>>> # Complex ArrayType.