[英]Scala: compilation error: not found type
I've started to learn some Spark\\Scala\\GraphX to use it with Pregel, I've found some simple code here: http://www.cakesolutions.net/teamblogs/graphx-pregel-api-an-example and wanted to try it. 我已经开始学习一些Spark \\ Scala \\ GraphX以便与Pregel一起使用,我在这里找到了一些简单的代码: http : //www.cakesolutions.net/teamblogs/graphx-pregel-api-an-example并且想要尝试一下。 So I tried to compile this code as I thought it should be(It's my first time with Scala): 因此,我尝试按照我认为的那样编译此代码(这是我第一次使用Scala):
/* SimpleApp.scala */
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
import org.apache.spark._
import org.apache.spark.graphx._
import org.apache.spark.rdd.RDD
class Graph[VD, ED] (
val vertices: VertexRDD[VD],
val edges: EdgeRDD[ED]) {
}
object SimpleApp {
val initialMsg = 9999
def vprog(vertexId: VertexId, value: (Int, Int), message: Int): (Int, Int) = {
if (message == initialMsg)
value
else
(message min value._1, value._1)
}
def sendMsg(triplet: EdgeTriplet[(Int, Int), Boolean]): Iterator[(VertexId, Int)] = {
val sourceVertex = triplet.srcAttr
if (sourceVertex._1 == sourceVertex._2)
Iterator.empty
else
Iterator((triplet.dstId, sourceVertex._1))
}
def mergeMsg(msg1: Int, msg2: Int): Int = msg1 min msg2
def pregel[A]
(initialMsg: A,
maxIter: Int = Int.MaxValue,
activeDir: EdgeDirection = EdgeDirection.Out)
(vprog: (VertexId, VD, A) => VD,
sendMsg: EdgeTriplet[VD, ED] => Iterator[(VertexId, A)],
mergeMsg: (A, A) => A)
: Graph[VD, ED]
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Simple Application")
val sc = new SparkContext(conf)
val minGraph = graph.pregel(initialMsg,
Int.MaxValue,
EdgeDirection.Out)(
vprog,
sendMsg,
mergeMsg)
minGraph.vertices.collect.foreach{
case (vertexId, (value, original_value)) => println(value)
}
sc.stop()
}
}
But I get this error: 但是我得到这个错误:
$ C:\"Program Files (x86)"\sbt\bin\sbt package
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Set current project to Simple Project (in build file:/C:/spark/simple/)
[info] Compiling 1 Scala source to C:\spark\simple\target\scala-2.10\classes...
[error] C:\spark\simple\src\main\scala\SimpleApp.scala:42: not found: type VD
[error] : Graph[VD, ED]
[error] ^
[error] C:\spark\simple\src\main\scala\SimpleApp.scala:42: not found: type ED
[error] : Graph[VD, ED]
[error] ^
[error] C:\spark\simple\src\main\scala\SimpleApp.scala:39: not found: type VD
[error] (vprog: (VertexId, VD, A) => VD,
[error] ^
[error] C:\spark\simple\src\main\scala\SimpleApp.scala:39: not found: type VD
[error] (vprog: (VertexId, VD, A) => VD,
[error] ^
[error] C:\spark\simple\src\main\scala\SimpleApp.scala:40: not found: type VD
[error] sendMsg: EdgeTriplet[VD, ED] => Iterator[(VertexId, A)],
[error] ^
[error] C:\spark\simple\src\main\scala\SimpleApp.scala:40: not found: type ED
[error] sendMsg: EdgeTriplet[VD, ED] => Iterator[(VertexId, A)],
[error] ^
[error] C:\spark\simple\src\main\scala\SimpleApp.scala:35: only classes can have declared but undefined members
[error] def pregel[A]
[error] ^
[error] C:\spark\simple\src\main\scala\SimpleApp.scala:48: not found: value graph
[error] val minGraph = graph.pregel(initialMsg,
[error] ^
[error] 8 errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 5 s, completed Jan 17, 2017 12:35:00 AM
I'm fairly new to Scala so I don't exactly understand VD\\ED role in these defines. 我对Scala还是很陌生,所以我不完全了解这些定义中的VD \\ ED角色。
The problem is that you cannot use a type for your method definition that hasn't been declared as a type parameter somewhere in scope (eg that method, or containing class etc.). 问题是您不能在方法定义中使用尚未在作用域中某个地方声明为类型参数的类型(例如,该方法或包含类等)。
Look at your method def pregel[A]
. 看看你的方法def pregel[A]
。 It returns a value of type Graph[VD, ED]
. 它返回Graph[VD, ED]
类型的值。 But how can compiler know what VD
refers to? 但是编译器如何知道VD
指的是什么? Without getting into what your code does, fixing this problem is easy if you just add VD
as a method type parameter: 如果不添加代码功能,则只需将VD
添加为方法类型参数即可轻松解决此问题:
def pregel[A, VD]
Note that if pregel
were a method within the class Graph
, it would be OK because Graph
defines that type: class Graph[VD, ED]
. 请注意,如果pregel
是Graph
类中的方法,则可以,因为Graph
定义了该类型: class Graph[VD, ED]
。 By the code you posted, it would seem that your methods are lingering in the middle of nowhere, which is not allowed - perhaps you may want to consider moving them inside the Graph
class? 通过您发布的代码,您的方法似乎徘徊在无处可寻的地方,这是不允许的-也许您可能要考虑将它们移至Graph
类中?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.