我尝试在Python中的两个Spark数据帧之间进行联合,其中一个有时是空的,我做了一个测试,如果,返回完整的。 例如下面的一个小代码,它返回一个错误:
>>> from pyspark.sql.types import *
>>> fulldataframe = [StructField("FIELDNAME_1",StringType(), True),StructField("FIELDNAME_2", StringType(), True),StructField("FIELDNAME_3", StringType(), True)]
>>> schema = StructType([])
>>>
>>> dataframeempty = sqlContext.createDataFrame(sc.emptyRDD(), schema)
>>> resultunion = sqlContext.createDataFrame(sc.emptyRDD(), schema)
>>> if (fulldataframe.isEmpty()):
... resultunion = dataframeempty
... elif (dataframeempty.isEmpty()):
... resultunion = fulldataframe
... else:
... resultunion=fulldataframe.union(dataframeempty)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'isEmpty'
>>>
有人能告诉我哪里出了问题?在
计数可能需要很长时间。在Scala中:
相关问题 更多 >
编程相关推荐