Closed muratseyhan closed 9 years ago
Hello! Can you try something like this?
person2 = Person.first
person2.hydrate!
person2.age
Hi @muratseyhan. Thanks for this. I'll take a look when I get a moment.
Hello! Can you try something like this?
Hi @fonji! Here is the output:
>> person2 = Person.first
#<Person:0x000000024bf3c8 @uri=#<RDF::URI:0x125f8e0 URI:http://example.com/ric>, @repository=#<RDF::Repository:0x1266730()>, @new_record=false, @graph_uri=# <RDF::URI:0x125e06c URI:http://example.com/people>, @changed_attributes={:rdf_type=>[]}>
>> person2.hydrate!
#<RDF::NTriples::Reader:0x000000029d2860 @options={:validate=>false, :canonicalize=>false, :intern=>true, :prefixes=>{}, :encoding=>#<Encoding:UTF-8>}, @input=#<StringIO:0x000000029d1d98>, @line=".", @line_rest=nil>
>> person2.age
31
So here's your temporary fix: call hydrate! before trying to get any data from an object. That's what I do. @RicSwirrl is there a reason to return dry objects using .first and .resources? Or should this be considered a bug? I guess it can be difficult to do it with a single query and without a loop to call hydrate! on every object, no worries, I'm just curious.
Thanks @fonji! I know that I can retrieve the data in other ways, but I would rather monkey patch these methods. I think this is definitely a bug (or a consequence of several bugs), since find
and resources
both hit the database with a CONSTRUCT
query that seems to be meant for retrieving data, but is guaranteed to return empty graphs. I suspect the problem is in the generation of these queries. Consider the following query performed by resources
:
CONSTRUCT {
?tripod_construct_s ?tripod_construct_p ?tripod_construct_o .
}
WHERE {
{
SELECT (?uri as ?tripod_construct_s)
{
SELECT DISTINCT ?uri (<http://example.com/people> as ?graph)
WHERE {
GRAPH <http://example.com/people>
{
?uri a <http://example.com/person> .
?uri ?p ?o
}
}
}
}
?tripod_construct_s ?tripod_construct_p ?tripod_construct_o .
}
The query does not even select the predicates and objects and have an unnecessary nested SELECT
clause. It is rather easy to retrieve the desired data with a single query such as the following:
CONSTRUCT {
?uri ?tripod_construct_p ?tripod_construct_o .
}
WHERE {
SELECT DISTINCT ?uri (<http://example.com/people> as ?graph) ?tripod_construct_p ?tripod_construct_o
WHERE {
GRAPH <http://example.com/people>
{
?uri a <http://example.com/person> .
?uri ?tripod_construct_p ?tripod_construct_o
}
}
}
I think you're right, but I'm still waiting for @RicSwirrl's opinion about this. My guess will be that it's because it used to be a describe statement instead of a construct. You only need the uri for the describe, hence the subquery returning it. Construct is way faster when you have lots of relations (which is my case and why I'm happy they changed), so I think it's a good thing but it needs a patch. If you have time to create a fork and then a pull request (I sadly don't), I guess it will be appreciated. The linked commit given above should help you find the code to patch.
Thanks @fonji! That makes sense. I haven't had enough time to examine the source code to propose a fix myself, yet I will probably have the time for it this weekend. I will create a pull request if it would still be open.
Maybe I should open another issue for this, but it also seems unnecessary to hit the database twice for first
and resources
methods. Both yield a SELECT
to retrieve the target URIs first, then a CONSTRUCT
to retrieve other relevant data. I suspect this is another thing that made sense when using DESCRIBE
queries.
@RicSwirrl, many thanks for this much needed project. It's also nice to see that it has started to form an active community.
Thanks @muratseyhan @fonji for your comments. Yeah - there's some legacy reasoning behind this. Some of the internals of Tripod are due a revisit, for performance and sense! I'll take a look this week.
Thanks @RicSwirrl, that's awesome!
Execution methods for criteria objects do not retrieve any information but the URIs of the resources.
resources
andfirst
methods seem to have this problem. I used the example code in the documentation ontripod (0.10.9)
. I had the same issue on0.10.8
.Adding data using the example in the documentation:
find
method seems to work fine:resources
method does not retrieve the fields for the target instances.Here is the Fuseki logs for the
resources
call.first
yields the same issue.The logs for
find
call.CONSTRUCT
queries that hit the database do not seem to make sense, and they return empty graphs as one would expect.