3 Replies Latest reply on Feb 3, 2014 4:45 PM by alwu-Oracle

    BIND in the SPARQL Where

    kingc

      I am new to SPARQL and RDF, so I hope that there is an easy answer to this question.

       

      I am using the Oracle Jena bindings to do some testing.  My tests are based on the Jena examples which all work.  This specific test is based on Test8.java in the Jena examples. I added the Spatial index and was able to do some spatial queries in RDF.  But now I would like to call a spatial function and return the value, rather than just use it in a FILTER.

       

      My query looks like this (Retrieve the parents and their children, and tell me how far apart they live):

       

            PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>

            SELECT ?s ?o ?geom1 ?geom2 ?dist2

            WHERE {

             ?s <u:parentOf> ?o .

             ?s <u:livesAt> ?geom1 .

             ?o <u:livesAt> ?geom2 .

             BIND(orageo:distance (geom1, geom2, "KM") as ?dist2)

            }


      I tried using the form LET instead of bind, but Jena rejected that form.  I also tried using a function in the SELECT, but from what I read it looks like that might be limited to a certain set of Aggregate functions.


      Using LET generates syntax errors, BIND brings back empty results.


      Just as a reference, this type of query works:


      PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>

      SELECT ?s ?geom

      WHERE {?s <u:livesAt> ?geom

        FILTER(orageo:withinDistance(?geom,"POINT(-122.4192 37.7793)"^^<http://xmlns.oracle.com/rdf/geo/WKTLiteral>,10000,"KM"))

      }


      Does the Oracle Jena version implement the BIND clause?


      Thanks in advance,


      Craig

        • 1. Re: BIND in the SPARQL Where
          alwu-Oracle

          Craig,

           

          The Jena Adapter supports the BIND clause. Oracle 11g Database, however, does not support BIND directly so Jena Adapter ends up using ARQ to handle the BIND. Unfortunately, the orageo functions are not recognized. (String operations, calculations, etc. are supported though.)

           

          The FILTER case works because the database supports it and we push the expression down to the database.

           

          BTW, syntax wise, you may want to use something like:

           

          BIND(orageo:distance (?geom1, ?geom2, "KM") as ?dist2)

           

          Hope it clarifies,

           

          Zhe Wu

          • 2. Re: BIND in the SPARQL Where
            kingc

            Zhe, Thanks for the update.

             

            You are correct on the updated syntax... it was a cut/paste issue on my part, in my running example, I had the "?" on the variables... :-/

             

            What I want to do is to use some of the geospatial commands in the bind clause... You say that it does not support the orageo functions, but does it support any of the standard geosparql functions?

             

            Back to your response...

             

            If you push the FILTER to the database, is that applied before the graph is created?

             

            In normal Jena execution, the FILTER is applied to the graph results after the query(s) run.  Does Oracle change the query plan to execute the FILTER before the rest of the graph is queried/analyzed?

             

            Craig

            • 3. Re: BIND in the SPARQL Where
              alwu-Oracle

              Hi Craig,

               

              I don't think Jena 2.7.2 has support of geosparql functions.

               

              Regarding the execution order (with respect to FILTER clause vs other query patterns), Oracle converts SPARQL queries into

              SQL queries and the execution plan (order, join methods, etc.) is decided transparently by the optimizer. It is possible, however, to

              influence the execution plan through query hints.

               

              Hope it helps,


              Zhe Wu