[Activerdf] RDFLite joins and reuse of table names
Paul Stadig
paul at stadig.name
Thu Dec 21 12:49:28 GMT 2006
Hi Eyal,
I think the issue comes up when there are where clauses that join at more
than one symbol. For example:
require 'rubygems'
require 'active_rdf'
adapter = ConnectionPool.add_data_source :type => :rdflite
type = Namespace.lookup(:rdf, 'type')
transProp = Namespace.lookup(:owl, 'TransitiveProperty')
Namespace.register(:test, 'http://test.com/')
ancestor = Namespace.lookup(:test, 'ancestor')
sue = Namespace.lookup(:test, 'Sue')
mary = Namespace.lookup(:test, 'Mary')
anne = Namespace.lookup(:test, 'Anne')
adapter.add ancestor, type, transProp
adapter.add sue, ancestor, mary
adapter.add mary, ancestor, anne
Query.new.select(:Sue, :ancestor, :Anne).where(:ancestor, type,
transProp).where(:Sue, :ancestor, :Mary).where(:Mary, :ancestor,
:Anne).execute.each do |row|
p row
end
This is the sql that is executed:
select t1.s, t0.s, t2.o from triple as t0 join triple as t1 on t0.s = t1.p
join triple as t2 on t0.s = t2.p join triple as t2 on t1.o = t2.s where
t0.p = ? and t0.o = ?
This code will cause the ambiguous column error. I think what is happening
is while it's working through the symbols it will join t0 and t2 by
:ancestor so it will do "join triple as t2 on t0.s = t2.p" then when it hits
the :Mary symbol in the second where clause it will add "join triple as t2
on t1.o = t2.s", but since we have already aliased the triple table as t2 it
gets an ambiguous column error. What I gather from your comment is that its
not possible to to do something like "join t2 on t1.o = t2.s" with sqlite.
What I was wondering is if you could do something like
select t1.s, t0.s, t2.o from triple as t0, triple as t1, triple as t2 where
t0.s = t1.p and t0.s = t2.p and t1.o = t2.s and t0.p = ? and t0.o = ?
I'm not sure if sqlite is able to optimize the join version better, or not,
but I think they are essentially equivalent.
BTW, I released a gem of activerdf-rules.
Paul
On 12/20/06, Eyal Oren <eyal.oren at deri.org> wrote:
>
> On 12/19/06/12/06 15:49 -0500, Paul Stadig wrote:
> >Eyal (and others),
> >I noticed the TODO in the rdflite.rb about the reuse of table names in
> >joins. I've been hacking on a forward chaining production system (
> >http://rubyforge.org/projects/activerdf-rules) that sits on top of
> >ActiveRDF. It works well enough with the RDF Schema rules, but I'm
> getting
> The rules thing sounds cool, is there any way I can try it? I didn't see
> any code yet on the project page?
>
> >an ambiguous column error for some of the rules in my OWL rule base.
> there was a bug in the join construction for rdflite, fixed it in the bzr
> version, is there any chance you can try the trunk code and see if it
> solves your problem? I can also push a gem version if you want, but I
> rather know first if the join works correctly now.
>
> >Have you considered just doing something like
> >select ... from triple as t0, triple as t1 where t0.p=t1.s;
> >instead of using joins? Maybe that would work around the sqlite problem
> >with reusing table names?
> hmm. I'm trying to understand my own (rather cryptic) comment about the
> limitations of the current join-construction-algorithm. I can't exactly
> recall the problem that I had before, so right now I'm not sure what a
> where clause (as opposed to a real join) would matter.
>
> Could you maybe pose the code (or something similar) that exhibits your
> join problem? That might help me refresh my own memory as to what's going
> on here again.
>
> -eyal
> _______________________________________________
> Activerdf mailing list
> Activerdf at lists.deri.org
> http://lists.deri.org/mailman/listinfo/activerdf
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.deri.org/pipermail/activerdf/attachments/20061221/6dc7e9c0/attachment.htm
More information about the Activerdf
mailing list