Skip to content
This repository was archived by the owner on Oct 8, 2020. It is now read-only.

Commit 4612ec1

Browse files
committed
Add missing class for DataLake example :)
1 parent 5c9dbb6 commit 4612ec1

File tree

1 file changed

+66
-0
lines changed
  • sansa-examples-spark/src/main/scala/net/sansa_stack/examples/spark/query

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package net.sansa_stack.examples.spark.query
2+
3+
import scala.collection.mutable
4+
5+
import net.sansa_stack.query.spark.query._
6+
import org.apache.jena.riot.Lang
7+
import org.apache.spark.sql.SparkSession
8+
9+
/**
10+
* Run SPARQL queries over Spark using Data Lake approach.
11+
*/
12+
object DataLake {
13+
14+
def main(args: Array[String]) {
15+
parser.parse(args, Config()) match {
16+
case Some(config) =>
17+
run(config.queryFile, config.mappingsFile, config.configFile)
18+
case None =>
19+
println(parser.usage)
20+
}
21+
}
22+
23+
def run(queryFile: String, mappingsFile: String, configFile: String): Unit = {
24+
25+
println("======================================")
26+
println("| Sparqlify example |")
27+
println("======================================")
28+
29+
val spark = SparkSession.builder
30+
.appName(s"DataLake (CSV) example")
31+
.master("local[*]")
32+
.getOrCreate()
33+
34+
val result = spark.sparqlDL(queryFile, mappingsFile, configFile)
35+
result.show()
36+
37+
spark.stop
38+
39+
}
40+
41+
case class Config(
42+
queryFile: String = getClass.getResource("/datalake/queries/Q1.sparql").getPath,
43+
mappingsFile: String = getClass.getResource("/datalake/config_csv-only").getPath,
44+
configFile: String = getClass.getResource("/datalake/mappings_csv-only.ttl").getPath)
45+
46+
val parser = new scopt.OptionParser[Config]("Sparqlify example") {
47+
48+
head(" DataLake (CSV) example")
49+
50+
opt[String]('f', "queryFile").valueName("<queryFile>").
51+
action((x, c) => c.copy(queryFile = x)).
52+
text("a file containing SPARQL queries or a single query, default: /queries/Q1.sparql")
53+
54+
opt[String]('m', "mappingsFile").valueName("<mappingsFile>").
55+
action((x, c) => c.copy(mappingsFile = x)).
56+
text("the mappings to the target sources, default: /config_csv-only")
57+
58+
opt[String]('c', "configFile").optional().valueName("<configFile>").
59+
action((x, c) => c.copy(configFile = x)).
60+
text("configuration file for different data sources, default: /mappings_csv-only.ttl")
61+
62+
help("help").text("prints this usage text")
63+
}
64+
65+
}
66+

0 commit comments

Comments
 (0)