Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.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/6.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中过滤RDD后获得密钥的第一个值?_Scala_Apache Spark_Spark Graphx - Fatal编程技术网

Scala 如何在Spark中过滤RDD后获得密钥的第一个值?

Scala 如何在Spark中过滤RDD后获得密钥的第一个值?,scala,apache-spark,spark-graphx,Scala,Apache Spark,Spark Graphx,我是新手。我使用GraphLoader创建了我的图形,并使用mapVertices和下面的代码更改节点属性: case class nodes_property(label:Int,get_label:Boolean) 经过一些转换后,RDD中的每个节点都具有以下结构: (1,nodes_property(12,true)) (2,nodes_property(9,false)) (3,nodes_property(12,true)) ... 我使用graph.vertices.filte

我是新手。我使用GraphLoader创建了我的图形,并使用
mapVertices
和下面的代码更改节点属性:

case class nodes_property(label:Int,get_label:Boolean)
经过一些转换后,RDD中的每个节点都具有以下结构:

(1,nodes_property(12,true))
(2,nodes_property(9,false))
(3,nodes_property(12,true))
...

我使用
graph.vertices.filter(x=>x.\u 1==1)
为ID=1的节点过滤值。如何选择值中的第一个元素?我的意思是如何选择12(它是节点1的第一个值)?

您应该使用take(1)来获取值,然后,为了仅提取12,您应该执行以下操作:

val x=graph.vertices.filter(x=>x._1==1).values.take(1)
println(x(0).label)

这只会给你12英镑。

take(1)
可能是你需要的。在这里阅读更多。谢谢你的帮助。但它没有起作用。我做了以下代码:``valx=graph.vertices.filter(x=>x.`u1==1.values.take(1)``。当我想做这段代码时,它不起作用:``if(x>10)do something``我使用了
x.foreach(println)
并给出
nodes\u属性(12,true)
。我只想要12,以便在
if
语句中使用它