Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dataframe Spark shell中的toDF在哪里,如何与Vector、Seq或其他一起使用?_Dataframe_Apache Spark_Spark Shell - Fatal编程技术网

Dataframe Spark shell中的toDF在哪里,如何与Vector、Seq或其他一起使用?

Dataframe Spark shell中的toDF在哪里,如何与Vector、Seq或其他一起使用?,dataframe,apache-spark,spark-shell,Dataframe,Apache Spark,Spark Shell,我尝试了一些基本的数据类型 val x = Vector("John Smith", 10, "Illinois") val x = Seq("John Smith", 10, "Illinois") val x = Array("John Smith", 10, "Illinois") val x = ... val x = Seq( Vector("John Smith",10,"Illinois"), Vector("Foo",2,"Bar")) 但是没有人提供toDF(),即使是在导入

我尝试了一些基本的数据类型

val x = Vector("John Smith", 10, "Illinois")
val x = Seq("John Smith", 10, "Illinois")
val x = Array("John Smith", 10, "Illinois")
val x = ...
val x = Seq( Vector("John Smith",10,"Illinois"), Vector("Foo",2,"Bar"))
但是没有人提供
toDF()
,即使是在导入spark.implicits.\u之后

我的目标是使用
x.toDF(“姓名”、“年龄”、“城市”)。show

在上一个示例中,
toDF
存在,但出现错误“java.lang.ClassNotFoundException”


注:

  • 我在Spark v2.2中使用Spark shell

  • 需要基于在
    toDF(names)
    中参数化的colunm名称进行泛型转换,复杂解决方案作为
    案例类Person(name:String,age:Long,city:String)的创建向量

toDF后显示的预期结果为

+----------+---+--------+
|      name|age|    city|
+----------+---+--------+
|John Smith| 10|Illinois|
+----------+---+--------+

您要查找的语法是

val x = Array("John Smith", "10", "Illinois")
sc.parallelize(x).toDF()
另一种方式是,

val y = Seq("John Smith", "10", "Illinois")
Seq(y).toDF("value").show()
这也应该行得通

Seq(Vector("John Smith","10","Illinois"), Vector("Foo","2","Bar")).toDF()

您应该将值放入元组中以创建3列

scala> Seq(("John Smith", "asd", "Illinois")).toDF("name","age","city").show
+----------+---+--------+
|      name|age|    city|
+----------+---+--------+
|John Smith|asd|Illinois|
+----------+---+--------+

@PeterKrauss试试这个,这是数据类型不匹配的问题。我从来没有使用过没有限定符的
valx=(“Hello”,“world”)
。。。现在我看到它是有效的(!),你教我的是有效的,他的名字是tuple。因此,也许最好、最简单的Spark数据帧定义是“DF是元组的一个序列”(为什么没有指南这么说?)