3 Replies Latest reply on May 12, 2008 1:53 PM by alwu-Oracle

    Regarding SPARQL query...

    617912
      Hi,

      I am confused about how the SPARQL query mechanism is working in Oracle Jena Adapter Java API. In all the java examples given with Jena Patch to 10g, native Jena Query Classes are used to run the SPARQL. But as far as I know Oracle 10g uses 'sdo_rdf_match' PL/SQL procedure to query the RDF store. So I want to know how the general SPARQL(in Jena) is being converted into Oracle 'sdo_rdf_match' Pl/SQL procedure. OR is something else happening???

      I want to know this because I want to execute normal SPARQL queries from within a Java program and I dont want to execute the 'sdo_rdf_match' procedure using normal JDBC API.

      So can any one explain me what is really going behind this query mechanism, also any limitations if there are in the querying (from java program)???

      Thanks,
      Rajesh.
        • 1. Re: Regarding SPARQL query...
          alwu-Oracle
          In Oracle Jena Adaptor's implementation, a SPARQL query, when contains only conjunctive patterns, is (first parsed by Jena's ARQ logic and then) converted into a single SDO_RDF_MATCH (or SEM_MATCH for 11g) query. The query execution is done inside the database. Results are read back using JDBC.

          If the SPARQL query contains OPTIONAL, named graph, etc., then multiple SDO_RDF_MATCH queries may be issued.

          Is this detailed enough for you?
          • 2. Re: Regarding SPARQL query...
            617912
            Thanks for the reply. Your explanation cleared some doubts. But I am still not clear about, which Java Class (from the Jena Adapter patch OR Jena ARQ) is responsible for this SPARQL to sdo_rdf_matc() conversion.

            Also, When I am using one of the example programs given with the patch to run a simple SPARQL, I am getting a 'ClassCastException' most of the times especially when I am using[b] FILTER conditions. The following is the query which is throwing an exception:

            Query1 is :
                  "PREFIX owl:   <http://www.w3.org/2002/07/owl#> " + 
                  "PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
                  "PREFIX rdfs:   <http://www.w3.org/2000/01/rdf-schema#> " +
                  "PREFIX v2: <http://localhost:8989/v2> " +
                  "PREFIX v1: <http://localhost:8989/v1> " +
                  "SELECT  ?x1 " +
                  "WHERE { ?x rdf:type v1:Item." +
                  "        ?x v1:has_name ?x1 . " +
                  "        ?x v1:has_desc ?x2  ." +
                  "       FILTER regex(?x1 , \"John\" , \"i\" ) } ";
            The above query is raising the exception:
            WARN [main] (QueryIteratorCheck.java:99) - Open iterator: QueryIterBlockTriplesQH$StagePattern/6
            Exception in thread "main" java.lang.ClassCastException: com.hp.hpl.jena.graph.Node_Blank
            But when I change the pattern by making the pattern containing x1 ( which is used in FILTER) as the last one in the WHERE part, then query is working perfectly. It is given below:
            Query2 is:
                  "PREFIX owl:   <http://www.w3.org/2002/07/owl#> " + 
                  "PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
                  "PREFIX rdfs:   <http://www.w3.org/2000/01/rdf-schema#> " +
                  "PREFIX v2: <http://localhost:8989/v2> " +
                  "PREFIX v1: <http://localhost:8989/v1> " +
                  "SELECT  ?x1 " +
                  "WHERE { ?x rdf:type v1:Item." +
                  "        ?x v1:has_desc ?x2  ." +
                  "        ?x v1:has_name ?x1 . " +
                  "       FILTER regex(?x1 , \"John\" , \"i\" ) } ";
            So, making the pattern with the variable used in FILTER, close to the filter condition is the only way my query is working. I tried all other possibilities with different query patterns. In all the cases the query is working only if pattern with variable used in FILTER is the last in (close to the FILTER condition) the WHERE part. In all other cases it is giving the above stated Exception.

            Also when FILTER is not used, and a direct string match is done, all queries working fine. Why is this happenning???

            Thanks,
            Rajesh
            • 3. Re: Regarding SPARQL query...
              alwu-Oracle
              It sounds like a bug that has been fixed a while back. Could you please send me a small data set that can re-produce the problem? I have tried your query and could not reproduce.

              Please send the data set to alan dot wu at oracle dot com. Thanks.