pythonsparqlblazegraph

Trying to run a sparql query on quads+triples files, getting error: com.bigdata.rdf.sparql.ast.QuadsOperationInTriplesModeException


I am using the Blazegraph Database to run a very simple query. For my dataset, I have .ttl and .nq files. I am loading the files using Blazegraph's Bulk Data Loader. Here is my query:

SELECT DISTINCT ?g 
WHERE {
 GRAPH ?g { ?s ?p ?o }
}

I expect an output of the distinct graph names. However, here is the error I am getting:

java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.bigdata.rdf.sparql.ast.QuadsOperationInTriplesModeException: Use of WITH and GRAPH constructs in query body is not supported in triples mode.

In my RWStore.properties, here are the two main flags for setup (there are more but these are the related ones):

com.bigdata.rdf.sail.truthMaintenance=false
com.bigdata.rdf.store.AbstractTripleStore.quads=true

This is how I am loading the files and running the jar:

java -Xmx4g -cp /pathto/blazegraph.jar com.bigdata.rdf.store.DataLoader -verbose -namespace kb /pathto/RWStore.properties /pathto/data

java -server -Xmx4g -jar -Djetty.host=0.0.0.0 /pathto/blazegraph.jar

Also, here is something to note: I am able to run the same queries when I manually load the files via python (sparql.SPARQLServer.update(file)). I don't get this error then.

Can someone help me with this error? I can't find any solution anywhere!


Solution

  • I found a solution! The problem was because of the different format of the files being loaded by BulkDataLoader. Triples don't have a named graph while quads do, and so while querying, there was a mismatch which is the error in my question. This isn't the case when you manually upload the files (via workbench or python).

    These are the changes I made:

    1. Two properties files, one for quads and one for triples.

    quads.properties:

    com.bigdata.rdf.store.AbstractTripleStore.quads=true
    com.bigdata.rdf.store.AbstractTripleStore.statementIdentifiers=false
    

    triples.properties:

    com.bigdata.rdf.store.AbstractTripleStore.quads=false
    com.bigdata.rdf.store.AbstractTripleStore.statementIdentifiers=false
    
    1. While using BulkDataLoader:

    For .nq files:

    java -Xmx4g -cp /pathto/blazegraph.jar com.bigdata.rdf.store.DataLoader -verbose -namespace kb /pathto/quads.properties /pathto/data
    

    For .ttl files:

    java -Xmx4g -cp /pathto/blazegraph.jar com.bigdata.rdf.store.DataLoader -verbose -defaultGraph http://ex.org -namespace kb /pathto/triples.properties /pathto/data
    

    To start Blazegraph after loading files:

    java -server -Xmx4g -jar -Djetty.host=0.0.0.0 /pathto/blazegraph.jar
    

    Hope this helps others facing a similar issue!