Github user HyukjinKwon commented on a diff in the pull request:
https://github.com/apache/spark/pull/17435#discussion_r108437512
--- Diff: python/pyspark/sql/types.py ---
@@ -57,7 +57,25 @@ def __ne__(self, other):
@classmethod
def typeName(cls):
- return cls.__name__[:-4].lower()
+ typeTypeNameMap = {"DataType": "data",
+ "NullType": "null",
+ "StringType": "string",
+ "BinaryType": "binary",
+ "BooleanType": "boolean",
+ "DateType": "date",
+ "TimestampType": "timestamp",
+ "DecimalType": "decimal",
+ "DoubleType": "double",
+ "FloatType": "float",
+ "ByteType": "byte",
+ "IntegerType": "integer",
+ "LongType": "long",
+ "ShortType": "short",
+ "ArrayType": "array",
+ "MapType": "map",
+ "StructField": "struct",
--- End diff --
I guess it would not produce correct fields if `struct` is printed from
`StructField`.
```python
>>> from pyspark.sql import Row
>>>
>>> df = spark.createDataFrame([[Row(a=1), 2]])
>>> cols = []
>>> for i in df.schema:
... cols.append("`" + i.name + "`" + "\t" + i.typeName())
...
>>> print ",\n".join(cols)
`_1` struct,
`_2` struct
```
because actual types are as below:
```python
>>> df.schema.simpleString()
'struct<_1:struct<a:bigint>,_2:bigint>'
```
How about the one as below?
```python
from pyspark.sql import Row
df = spark.createDataFrame([[Row(a=1), 2]])
cols = []
for i in df.schema:
cols.append("`" + i.name + "`" + "\t" + i.dataType.simpleString())
print ",\n".join(cols)
```
prints
```
`_1` struct<a:bigint>,
`_2` bigint
```
---
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]