This adapter can be used to execute SQL queries over a SPARQL endpoint via Apache Calcite and Apache Jena. The project is a work in progress and it is not meant to be run in production.
The adapter can be used in several modes to expose the RDF data in a SPARQL endpoint as data:
- the
propertymode, which exposes every RDF property (the?pof a?s ?p ?opattern) as a table with two columnss(subject) ando(object); - the
classmode, which exposes every RDF class (the?clof a?s rdf:type ?clpattern) as a table whose columns are all the properties that link items of such class (the?sof the same pattern) to objects; - the
mappingmode, where selected properties are directly mapped to columns of a specified table.
The SPARQL endpoint in the following examples is a Jena in-memory endpoint created from a local file. Replace with e.g. "jdbc:jena:remote:query=https://dbpedia.org/sparql" to use a remote endpoint.
- Using the
propertymode:
{
"version": "1.0",
"defaultSchema": "sparql",
"schemas": [
{
"name": "sparql",
"type": "custom",
"factory": "com.datagrafting.sql2sparql.calcite.SparqlSchemaFactory",
"operand": {
"endpoint": "jdbc:jena:mem:dataset=data.nq",
"tableMode": "property"
}
}
]
}- Using the
classmode:
{
"version": "1.0",
"defaultSchema": "sparql",
"schemas": [
{
"name": "sparql",
"type": "custom",
"factory": "com.datagrafting.sql2sparql.calcite.SparqlSchemaFactory",
"operand": {
"endpoint": "jdbc:jena:mem:dataset=data.nq",
"tableMode": "class"
}
}
]
}- Using the
mappingmode:
{
"version": "1.0",
"defaultSchema": "sparql",
"schemas": [
{
"name": "sparql",
"type": "custom",
"factory": "com.datagrafting.sql2sparql.calcite.SparqlSchemaFactory",
"operand": {
"endpoint": "jdbc:jena:mem:dataset=data.nq",
"tableMode": "mapping",
"tableMappings": [
{
"name": "Person",
"columns": [
{
"name": "name",
"property": "http://xmlns.com/foaf/0.1/name"
},
{
"name": "age",
"property": "http://xmlns.com/foaf/0.1/age"
}
]
}
]
}
}
]
}- Java example
- Python (Jupyter notebook) examples using jaydebeapi and Apache Arrow
Compile the main library using Java 11:
cd core
mvn clean package -DskipTests
cd ..or using Java 8:
cd core
mvn clean package -P java1.8 -DskipTests
cd ..Please note that compiling with Java 8 forces Jena version to 3.17.0 (last version before switching to Java 11).
For the Java examples:
cd example
mv clean package
/path/to/java -cp target/classes:../../core/target/calcite-sparql-core-0.0.1-SNAPSHOT.jar com.datagrafting.sql2sparql.examples.SparqlClassTableRemoteFor the Python examples, Python 3 and Jupyter Notebook need to be installed first. Then, the notebooks can be run from the examples/python directory.
SELECT *andSELECTwith any number of columnsWHERE(with=,<>,<,>,<=,>=)ORDER BYLIMIT
When releasing, please make sure to update both the changelog and the citation file.
If you use this project in an article, please cite it as specified in the CITATION.cff file.
Many thanks to:
- Paul Jackson for interesting discussions on the mapping from RDF to SQL schema.