[redland-dev] Query Issues

Dave Beckett Dave.Beckett at bristol.ac.uk
Sat Feb 12 23:55:38 GMT 2005


On Wed, 2005-02-09 at 00:26 -0500, Christopher Schmidt wrote:
> With the newest Redland installed, there are some issues related to, I 
> believe, confusion in what the creation of an RDF Query object is in the 
> Python bindings. Each of the following assumes that the Model is set up 
> as follows:
> 
> import RDF
> m = RDF.Model()
> p = RDF.Parser()
> p.parse_into_model(m, "http://crschmidt.net/foaf.rdf")
> 
> Unexepcted Identifier:
> 
> The following code produces a RedlandError:
> 
> q = RDF.Query("""PREFIX foaf: <http://xmlns.com/foaf/0.1/>
> SELECT ?name
> WHERE
>   (?x rdf:type foaf:Person)
>   (?x foaf:name ?name)
> """)
> i = q.execute(m)
> for j in i:
> 	print j
> RDF.RedlandError: 'syntax error, unexpected IDENTIFIER, expecting SELECT'
> 
> This is confirmed on OS X 10.3.7, Gentoo Linux 2004.0.

As I already mentioned, that's an rdql/sparql confusion.  I admit the
error message could be more helpful in telling you that.

> Repeated queries
> 
> This isn't something I'm sure is new: I think I've seen it before, but 
> I'm mentioning it anyway. If you q.execute(m) twice in a row, the 
> results are nil:
> 
> q = RDF.Query("SELECT ?n where (?p <http://xmlns.com/foaf/0.1/name> 
> ?n)")
> i = q.execute(m)
> i = q.execute(m)
> for j in i:
> 	print j
> 
> Will print nothing, although there should be some results. Also, if you 
> try:
> 
> q = RDF.Query("SELECT ?n where (?p <http://xmlns.com/foaf/0.1/name> ?n)")
> i = q.execute(m)
> i = q.execute(m)
> print i
> 
> at this point, it will cause a segfault. Under OS X, it seems to catch 
> the failure, reporting:
> *** malloc[22468]: Deallocation of a pointer not malloced: 0x319230; 
> This could be a double free(), or free() called with the middle of an 
> allocated block; Try setting environment variable MallocHelp to see 
> tools to help debug
> A segmentation fault then appears to occur during cleanup.
> 
> A complete example code snippet:
> 
> import RDF    
> m = RDF.Model()    
> p = RDF.Parser()     
> p.parse_into_model(m, "http://crschmidt.net/foaf.rdf")
> q = RDF.Query("SELECT ?p where (?p foaf:nick 'crschmidt') using foaf for 
> <http://xmlns.com/foaf/0.1/>")
> i = q.execute(m)
> i = q.execute(m)
> print i                                                                         
> 
> This causes a bus error on OS X:
> #0  rasqal_query_remove_query_result (query=0x3189d0, query_results=0x3188b0) 
> at rasqal_query.c:769
> #1  0x00282390 in rasqal_free_query_results (query_results=0x3188b0) at 
> rasqal_query.c:798
> #2  0x004aedd8 in librdf_free_query_results (query_results=0x3188b0) at 
> rdf_query_results.c:230
> #3  0x0020c360 in _wrap_librdf_free_query_results (self=0x3189d0, 
> args=0x3188b0) at Redland_wrap.c:3013
> 
> and a Segfault on Linux
> 
> #0  rasqal_query_results_is_graph (query_results=0x0) 
>     at rasqal_query.c:839
> #1  0x404e7900 in librdf_query_rasqal_results_is_graph (query_results=0x0) 
>     at rdf_query_rasqal.c:764
> #2  0x404e64ea in librdf_query_results_is_graph (query_results=0x0)
>     at rdf_query_results.c:404
> #3  0x4002965b in _wrap_librdf_query_results_is_graph (self=0x0, args=0x0)
>     at Redland_wrap.c:3064
> 
> These line numbers appear to match up with Redland 1.0 release, so 
> hopefully it's not just a version issue this time.

No that was a bug, or several bugs, now fixed.  Part 1 was the fix to
rasqal that I just emailed with a patch.  The second part was in
redland's query code failing to anticipate multiple executions with
rasqal properly.

Fixed in rasqal and redland CVS.

> Sparql XML Results
> 
> This one is more of a feature than a bug, but it's a different behavior 
> than is expected: When issuing an RDQL Query, "print" ing the 
> QueryResults prints the Sparql XML Results format. Since the original 
> query is in RDQL, I'm not sure if this is expected behavior or not: One 
> of my scripts became a lot more verbose all of a sudden. However, it is 
> a nifty feature, so I'm perfectly willing to just accept that and move 
> on.

It seemed pretty handy to overload the QueryResults __str__ to do
something sensible.  There's also the to_string() which has other
parameters that allow you to choose the output format.   It doesn't
sound like a strong "don't do that" response from you ;)


> RDFXML-Abbrev Serializer
> 
> I'm not really sure on the status on this one: it seems that it was left 
> out of RDF.py for the release, so it may be that I'm jumping the gun 
> here. However:
> 
> s = RDF.Serializer(name="rdfxml-abbrev")
> s.serialize_model_to_string(m)
> 
> shows a large number of:
> 
> rdf_uri.c:201: (librdf_new_uri_from_uri) assertion failed: object 
> pointer of type librdf_uri is NULL.
> 
> followed by a mostly empty RDF document with lots of <rdf:Description /> 
> nodes and not a lot else. I'm not sure exactly how this serializer is 
> supposed to be used, however, so as I said, this may be my mistake.

Yeah that's a couple of bugs in the rdf/xml-abbrev writer; I fixed them
in the rdf/xml one but that was before I got the code from Steve, and I
forgot to make the corresponding changes.

Fixed in raptor CVS.

> make check on both platforms claims that all tests pass.
> 
> I apologize for the length of this email. I also apologize if any of 
> these errors are errors on my end in either configuration (*cough*) or 
> use.

Thanks for helping test things.  It means a few more bugs other people
won't have.

Incidently in the redland bindings CVS for python I've made the
exception raising work better since the current python-calling C-calling
python was giving crashes regularly.  (I've already mentioned this to
Chris).

Cheers

Dave




More information about the redland-dev mailing list