Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.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
Scala 如何使用Spark';在真实数据(文本文件或sql)上的前缀span?_Scala_Apache Spark - Fatal编程技术网

Scala 如何使用Spark';在真实数据(文本文件或sql)上的前缀span?

Scala 如何使用Spark';在真实数据(文本文件或sql)上的前缀span?,scala,apache-spark,Scala,Apache Spark,我正在尝试使用Spark的算法,但是很难将数据以正确的形状提供给算法。这感觉像是一个蒙蒂Python的短剧,API正在积极地工作,以迷惑程序员 我的数据是一个行列表,每个行包含一个文本项列表 a b c c c d b c d e a b ... 我通过两种方式提供了这些数据,一种是配置单元中的sql表(其中每行都有一个项目数组),另一种是文本文件,其中每行都包含上面的项目 官方示例创建了数组(Array)的Seq 如果使用sql,则返回以下类型: org.apache.spark.sql.

我正在尝试使用Spark的算法,但是很难将数据以正确的形状提供给算法。这感觉像是一个蒙蒂Python的短剧,API正在积极地工作,以迷惑程序员

我的数据是一个行列表,每个行包含一个文本项列表

a b c c c d 
b c d e
a b
...
我通过两种方式提供了这些数据,一种是配置单元中的sql表(其中每行都有一个项目数组),另一种是文本文件,其中每行都包含上面的项目

官方示例创建了
数组(Array)
Seq

如果使用sql,则返回以下类型:

org.apache.spark.sql.DataFrame = [seq: array<string>]
org.apache.spark.sql.DataFrame=[seq:array]
如果我阅读文本,我会得到以下类型:

org.apache.spark.sql.Dataset[Array[String]] = [value: array<string>]
org.apache.spark.sql.Dataset[Array[String]]=[value:Array]
下面是一个错误示例(如果我从sql向其提供数据):

错误:重载的方法值与可选项一起运行:
[Item,Itemset您正在尝试混合使用旧(
RDD
)和新(
Dataset
)API。对于
Dataset
,您应该使用ML API()。此外,输入应该是
Array[Array[\u]]
而不是
Array[\u]
-参见示例数据。另外解释此表示法的含义。可能重复@user10465355的“提取误解”注释是针对python的。我遇到的问题是试图使Scala类型与PrefixSpan期望的匹配
error: overloaded method value run with alternatives:
  [Item, Itemset <: Iterable[Item], Sequence <: Iterable[Itemset]](data: org.apache.spark.api.java.JavaRDD[Sequence])org.apache.spark.mllib.fpm.PrefixSpanModel[Item] <and>
  [Item](data: org.apache.spark.rdd.RDD[Array[Array[Item]]])(implicit evidence$1: scala.reflect.ClassTag[Item])org.apache.spark.mllib.fpm.PrefixSpanModel[Item]
 cannot be applied to (org.apache.spark.sql.DataFrame)
       new PrefixSpan().setMinSupport(0.5).setMaxPatternLength(5).run( sql("select seq from sequences limit 1000") )
                                                                  ^
error: overloaded method value run with alternatives:
  [Item, Itemset <: Iterable[Item], Sequence <: Iterable[Itemset]](data: org.apache.spark.api.java.JavaRDD[Sequence])org.apache.spark.mllib.fpm.PrefixSpanModel[Item] <and>
  [Item](data: org.apache.spark.rdd.RDD[Array[Array[Item]]])(implicit evidence$1: scala.reflect.ClassTag[Item])org.apache.spark.mllib.fpm.PrefixSpanModel[Item]
 cannot be applied to (org.apache.spark.sql.Dataset[Array[String]])
       new PrefixSpan().setMinSupport(0.5).setMaxPatternLength(5).run(textfiles.map( x => x.split("\u0002")).limit(3))
                                                                  ^