如何解决使用Java获取GraphFrames中的最短路径
我是Spark和GraphFrames的新手。
当我想了解GraphFrame中的shortestPaths方法时,GraphFrames documentation在Scala中为我提供了示例代码,但在Java中却没有。
在他们的文档中,他们提供了以下(Scala代码):
import org.graphframes.{examples,GraphFrame}
val g: GraphFrame = examples.Graphs.friends // get example graph
val results = g.shortestPaths.landmarks(Seq("a","d")).run()
results.select("id","distances").show()
在Java中,我尝试过:
import org.graphframes.GraphFrames;
import scala.collection.Seq;
import scala.collection.JavaConverters;
GraphFrame g = new GraphFrame(...,...);
Seq landmarkSeq = JavaConverters.collectionAsScalaIterableConverter(Arrays.asList((Object)"a",(Object)"d")).asScala().toSeq();
g.shortestPaths().landmarks(landmarkSeq).run().show();
或
g.shortestPaths().landmarks(new ArrayList<Object>(List.of((Object)"a",(Object)"d"))).run().show();
由于API需要Seq
运行代码后,我看到了消息:
Exception in thread "main" org.apache.spark.sql.AnalysisException: You're using untyped Scala UDF,which does not have the input type information. Spark may blindly pass null to the Scala closure with primitive-type argument,and the closure will see the default value of the Java type for the null argument,e.g. `udf((x: Int) => x,IntegerType)`,the result is 0 for null input. To get rid of this error,you Could:
1. use typed Scala UDF APIs(without return type parameter),e.g. `udf((x: Int) => x)`
2. use Java UDF APIs,e.g. `udf(new UDF1[String,Integer] { override def call(s: String): Integer = s.length() },if input types are all non primitive
3. set spark.sql.legacy.allowUntypedScalaUDF to true and use this API with caution;
System.setProperty("spark.sql.legacy.allowUntypedScalaUDF","true");
但情况没有改变。
由于Java中关于GraphFrames的示例代码或stackoverflow问题数量有限,因此四处寻找时找不到任何有用的信息。
解决方法
这似乎是GraphFrames 0.8.0中的错误。
请参见github.com中的Issue #367
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。