(x)query, db lookup, and update in one step

Saturday, 8 June 2013 · 4 messages
CG
Christian Grünin reply to buzz chopra, 8 Jun 2013, 11:288 Jun 2013 11:20 #
Hi Buzz, BaseX allows you to address multiple databases in one query. Your query could e.g. look as follows:
  for $rep in collection('coll')/Report
  let $attr0 := $rep/@attr0
  let $zzz := collection('lookup')//item[@id =$attr0]/text()
  return replace value of node $rep/@attr1 with $zzz
You may speed up your query a little by using db:open() instead of collection() (the latter one will additionally look up local files if there’s no database with the given name). To ensure that your query uses the index structures of the lookup database, you can have a look at the InfoView in the GUI, or turn on the query info on command line (-V). Hope this helps, Christian
Quoted text · buzz chopra · 38 lines
> Hello All, > > I'm relatively new to basex and xquery - but am using basex as a large > report repository. > > I'd like to try and perform the following xquery - but with some > intermediate steps: > > xquery for $rep in collection('coll')/Report let $attr0 := $rep/@attr0 > return (replace value of node $rep/@attr1 with 'zzz') > > > The actual value represented by 'zzz' above must be based on a separate > (physical) database lookup for each attribute value $attr0 in the collection > ( i.e. the values of attr1 is a (non-trivial lookup) function of attr0. > > Is this a scenario in which multiple queries would have to be made based on > the number of documents in the collection ? > > Perhaps there is some slick way of including a call out to some method to > such that the 'zzz' above is replaced with something like: > JavaModule.doLookup($attr0) ? > > I'm executing xquery from a jruby application so either the ruby or the java > client can be used (perhaps that is somewhat irrelevant). > > Thanks in advance for any suggestions, > > Buzz > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
BC
buzz chopra8 Jun 2013 11:28 #
Hello All, I'm relatively new to basex and xquery - but am using basex as a large report repository. I'd like to try and perform the following xquery - but with some intermediate steps:
xquery for $rep in collection('coll')/Report let $attr0 := $rep/@attr0
return (replace value of node $rep/@attr1 with 'zzz')
The actual value represented by 'zzz' above must be based on a separate (physical) database lookup for each attribute value $attr0 in the collection ( i.e. the values of attr1 is a (non-trivial lookup) function of attr0. Is this a scenario in which multiple queries would have to be made based on the number of documents in the collection ? Perhaps there is some slick way of including a call out to some method to such that the 'zzz' above is replaced with something like: JavaModule.doLookup($attr0) ? I'm executing xquery from a jruby application so either the ruby or the java client can be used (perhaps that is somewhat irrelevant). Thanks in advance for any suggestions, Buzz
CG
Christian Grünin reply to buzz chopra, 8 Jun 2013, 17:548 Jun 2013 16:06 #
In this case, the SQL Module may come in handy [1] Best, Christian [1] http://docs.basex.org/wiki/SQL ___________________________ 2013/6/8 buzz chopra <buzz.chopra at gmail.com>:
Quoted text · buzz chopra · 81 lines
> Thanks Christian, > > There is (Java based) application logic including the possibility of an > RDBMS query associated with the $zzz lookup. I'll try to look through the > various references to see if it is possible to invoke that logic right in > the FLOWR expression. > > Thank you! > > Buzz > > > > On Sat, Jun 8, 2013 at 4:20 AM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> Hi Buzz, >> >> BaseX allows you to address multiple databases in one query. Your >> query could e.g. look as follows: >> >> for $rep in collection('coll')/Report >> let $attr0 := $rep/@attr0 >> let $zzz := collection('lookup')//item[@id =$attr0]/text() >> return replace value of node $rep/@attr1 with $zzz >> >> You may speed up your query a little by using db:open() instead of >> collection() (the latter one will additionally look up local files if >> there’s no database with the given name). To ensure that your query >> uses the index structures of the lookup database, you can have a look >> at the InfoView in the GUI, or turn on the query info on command line >> (-V). >> >> Hope this helps, >> Christian >> >> >> > Hello All, >> > >> > I'm relatively new to basex and xquery - but am using basex as a large >> > report repository. >> > >> > I'd like to try and perform the following xquery - but with some >> > intermediate steps: >> > >> > xquery for $rep in collection('coll')/Report let $attr0 := $rep/@attr0 >> > return (replace value of node $rep/@attr1 with 'zzz') >> > >> > >> > The actual value represented by 'zzz' above must be based on a separate >> > (physical) database lookup for each attribute value $attr0 in the >> > collection >> > ( i.e. the values of attr1 is a (non-trivial lookup) function of attr0. >> > >> > Is this a scenario in which multiple queries would have to be made based >> > on >> > the number of documents in the collection ? >> > >> > Perhaps there is some slick way of including a call out to some method >> > to >> > such that the 'zzz' above is replaced with something like: >> > JavaModule.doLookup($attr0) ? >> > >> > I'm executing xquery from a jruby application so either the ruby or the >> > java >> > client can be used (perhaps that is somewhat irrelevant). >> > >> > Thanks in advance for any suggestions, >> > >> > Buzz >> > >> > >> > >> > >> > _______________________________________________ >> > BaseX-Talk mailing list >> > BaseX-Talk at mailman.uni-konstanz.de >> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > > >
BC
buzz choprain reply to Christian Grün, 8 Jun 2013, 11:208 Jun 2013 17:54 #
Thanks Christian, There is (Java based) application logic including the possibility of an RDBMS query associated with the $zzz lookup. I'll try to look through the various references to see if it is possible to invoke that logic right in the FLOWR expression. Thank you! Buzz On Sat, Jun 8, 2013 at 4:20 AM, Christian Grün <christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 63 lines
> Hi Buzz, > > BaseX allows you to address multiple databases in one query. Your > query could e.g. look as follows: > > for $rep in collection('coll')/Report > let $attr0 := $rep/@attr0 > let $zzz := collection('lookup')//item[@id =$attr0]/text() > return replace value of node $rep/@attr1 with $zzz > > You may speed up your query a little by using db:open() instead of > collection() (the latter one will additionally look up local files if > there’s no database with the given name). To ensure that your query > uses the index structures of the lookup database, you can have a look > at the InfoView in the GUI, or turn on the query info on command line > (-V). > > Hope this helps, > Christian > > > > Hello All, > > > > I'm relatively new to basex and xquery - but am using basex as a large > > report repository. > > > > I'd like to try and perform the following xquery - but with some > > intermediate steps: > > > > xquery for $rep in collection('coll')/Report let $attr0 := $rep/@attr0 > > return (replace value of node $rep/@attr1 with 'zzz') > > > > > > The actual value represented by 'zzz' above must be based on a separate > > (physical) database lookup for each attribute value $attr0 in the > collection > > ( i.e. the values of attr1 is a (non-trivial lookup) function of attr0. > > > > Is this a scenario in which multiple queries would have to be made based > on > > the number of documents in the collection ? > > > > Perhaps there is some slick way of including a call out to some method to > > such that the 'zzz' above is replaced with something like: > > JavaModule.doLookup($attr0) ? > > > > I'm executing xquery from a jruby application so either the ruby or the > java > > client can be used (perhaps that is somewhat irrelevant). > > > > Thanks in advance for any suggestions, > > > > Buzz > > > > > > > > > > _______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > >

⚡Generated with XQuery