Github user ilganeli commented on a diff in the pull request:
https://github.com/apache/spark/pull/6686#discussion_r32656127
--- Diff: python/pyspark/sql/types.py ---
@@ -368,8 +367,49 @@ def __init__(self, fields):
>>> struct1 == struct2
False
"""
- assert all(isinstance(f, DataType) for f in fields), "fields
should be a list of DataType"
- self.fields = fields
+ if not fields:
+ self.fields = []
+ else:
+ self.fields = fields
+ assert all(isinstance(f, StructField) for f in fields),\
+ "fields should be a list of StructField"
+
+ def add(self, name_or_struct_field, data_type=NullType(),
nullable=True, metadata=None):
--- End diff --
Davies - totally agree. This was changed specifically to consolidate to a
single method as suggested by Reynold. I initially had separate add methods -
one which accepted a StructField and one which accepted the 4 parameters, the
first two of which were defined.
What would you suggest? My preference is to break this out into two methods
for clarity and to avoid the problem you mention.
Thank you,
Ilya Ganelin
-----Original Message-----
From: Davies Liu [[email protected]<mailto:[email protected]>]
Sent: Wednesday, June 17, 2015 01:18 PM Eastern Standard Time
To: apache/spark
Cc: Ganelin, Ilya
Subject: Re: [spark] [SPARK-8056][SQL] Design an easier way to construct
schema for both Scala and Python (#6686)
In
python/pyspark/sql/types.py<https://github.com/apache/spark/pull/6686#discussion_r32650869>:
> @@ -368,8 +367,49 @@ def __init__(self, fields):
> >>> struct1 == struct2
> False
> """
> - assert all(isinstance(f, DataType) for f in fields), "fields
should be a list of DataType"
> - self.fields = fields
> + if not fields:
> + self.fields = []
> + else:
> + self.fields = fields
> + assert all(isinstance(f, StructField) for f in fields),\
> + "fields should be a list of StructField"
> +
> + def add(self, name_or_struct_field, data_type=NullType(),
nullable=True, metadata=None):
What's the use cases that we should have StructType without specifying the
dataType of each column?
In createDataFrame, if a schema of StructType is provided, it will not try
to infer the data types, so it does not work with StructType with NoneType in
it.
â
Reply to this email directly or view it on
GitHub<https://github.com/apache/spark/pull/6686/files#r32650869>.
________________________________________________________
The information contained in this e-mail is confidential and/or proprietary
to Capital One and/or its affiliates and may only be used solely in performance
of work or services for Capital One. The information transmitted herewith is
intended only for use by the individual or entity to which it is addressed. If
the reader of this message is not the intended recipient, you are hereby
notified that any review, retransmission, dissemination, distribution, copying
or other use of, or taking of any action in reliance upon this information is
strictly prohibited. If you have received this communication in error, please
contact the sender and delete the material from your computer.
---
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]