I want to create a DataFrame from a list of string that could match existing schema. Here is my code.
val rowValues = List("ann", "f", "90", "world", "23456") // fails
val rowValueTuple = ("ann", "f", "90", "world", "23456") //works
val newRow = sqlContext.sparkContext.parallelize(Seq(rowValueTuple)).toDF(df.columns: _*)
val newdf = df.unionAll(newRow).show()
The same code fails if i use the List of String. I see the difference is with rowValueTuple
a Tuple
is created.
Since the size of rowValues
list dynamically changes, i cannot manually create Tuple*
object.
How can i do this? What am i missing? How can i flatten this list to meet the requirement?
Appreciate your help, Please.