I have a task of combining multiple Spark DataFrames generated from a for loop together. So I thought to create an empty DataFrame before running the for loop and then combine them by UnionAll. result is the name of data frames generated from for loop.
Below is the code:
empty = sqlContext.createDataFrame(sc.emptyRDD(), StructType([]))
empty = empty.unionAll(result)
Below is the error:
first table has 0 columns and the second table has 25 columns
Looks like I have to specify specific schema when creating the empty Spark DataFrame. I am wondering if there is a way to make it work without doing so or simply combine Spark DataFrames. I do have many columns to specify otherwise.
Thanks in advance!