我正在尝试使用SANSA-RDF将海龟RDF文件读入Spark并创建图形。我执行以下代码时收到错误。我错过了什么?
import org.apache.jena.query.QueryFactory
import org.apache.jena.riot.Lang
import org.apache.spark.sql.SparkSession
import net.sansa_stack.rdf.spark.io.rdf._
import net.sansa_stack.rdf.spark.io._
import scala.io.Source
object SparkExecutor {
private var ss:SparkSession = null
def ConfigureSpark(): Unit ={
ss = SparkSession.builder
.master("local[*]")
.config("spark.driver.cores", 1)
.appName("LAM")
.getOrCreate()
}
def createGraph(): Unit ={
val filename = "xyz.ttl"
print("Loading graph from file"+ filename)
val lang = Lang.TTL
val triples = ss.rdf(lang)(filename)
val graph = LoadGraph(triples)
}
}
我使用
从main函数调用SparkExecutor object main {
def main(args: Array[String]): Unit = {
SparkExecutor.ConfigureSpark()
val RDFGraph = SparkExecutor.createGraph()
}
}
这会导致以下错误
Error: value rdf is not a member of org.apache.spark.sql.SparkSession
val triples = ss.rdf(lang)
答案 0 :(得分:7)
如果您在
中看到SANSA-RDF源代码,则存在隐式转换sansa-rdf-spark/src/main/scala/net/sansa_stack/rdf/spark/io/package.scala:159
rdf(lang)不是spark会话的方法,而是隐式类RDFReader的方法,因此您需要导入隐式定义可用的包。请尝试添加
import net.sansa_stack.rdf.spark.io ._
让我们知道结果。