Github user davies commented on the pull request:
https://github.com/apache/spark/pull/2901#issuecomment-60550043
@adrian-wang You can do it like this:
```
diff --git a/python/pyspark/sql.py b/python/pyspark/sql.py
index 7daf306..db256a4 100644
--- a/python/pyspark/sql.py
+++ b/python/pyspark/sql.py
@@ -782,6 +782,8 @@ def _restore_object(dataType, obj):
def _create_object(cls, v):
""" Create an customized object with class `cls`. """
+ if cls is datetime.date and isinstance(v, datetime.datetime):
+ return v.date()
return cls(v) if v is not None else v
@@ -796,9 +798,11 @@ def _create_getter(dt, i):
def _has_struct(dt):
- """Return whether `dt` is or has StructType in it"""
+ """Return whether `dt` is or has StructType/DateType in it"""
if isinstance(dt, StructType):
return True
+ if isinstance(dt, DateType):
+ return True
elif isinstance(dt, ArrayType):
return _has_struct(dt.elementType)
elif isinstance(dt, MapType):
@@ -870,6 +874,9 @@ def _create_cls(dataType):
return Dict
+ elif isinstance(dataType, DateType):
+ return datetime.date
+
elif not isinstance(dataType, StructType):
raise Exception("unexpected data type: %s" % dataType)
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]