Dynamic Evaluation of XQUERY

Wednesday, 29 October 2014 · 10 messages · last reply 10 Nov 2014
MS
Mansi Sheth29 Oct 2014 20:07 #
Hello, I want to devise a generic xquery script, which accepts actual XPATH to be run across all documents in all databases, from command line. Something like: curl -i " http://localhost:8984/rest?run=get_query_result.xq&n=/root/*//calls/@name/string() " Basically, parameter "n" would hold the query. I am trying this using xquery module eval method. But, am not succeeding in it. I have my script something as under:
declare variable $n as xs:string external;
declare option output:item-separator "
";

let $aList :=
for $db in db:list()
let $vars := map {'db_name':$db , 'query' : $n}
let $query_to_execute := "db:open($db_name)$query"
return xquery:eval($query_to_execute,$vars)
return distinct-values($aList) My questions are: 1. Can we assign dynamic values as a value to a map's key ? 2. Can I map have more than one key, in query:eval ? Please point me in right direction, or explain what am I doing wrong in above code .. - Mansi
CG
Christian Grün30 Oct 2014 10:54 #
Hi Mansi, you have been close! It could work with the following query (I haven't tried it out, though): _ get_query_result.xq ____________________
declare variable $n external;
declare option output:item-separator "
";

let $aList :=
  for $name in db:list()
  let $db := db:open($name)
  return xquery:eval($n, map { '': $db })
return distinct-values($aList) ______________________________________ In this code, I'm opening the database in the main loop, and I then bind it to the empty string. This way, the database will be the context of the query to be evaluated query, and you won't have to deal with bugs that arise from the concatenation of "db:open" and the query string.
Quoted text · Mansi Sheth · 2 lines
> 1. Can we assign dynamic values as a value to a map's key ? > 2. Can I map have more than one key, in query:eval ?
This is both possible. As you see in the following query, you'll again have to declare the variables that you want to bind. I agree this causes a lot of code, so we may simplify it again in a future version of BaseX: ______________________________________
let $n := "/a/b/c"
for $db in db:list()
let $query :=
  "declare variable $db external; " ||
  "db:open($db)" || $n
return xquery:eval($query,
  map { 'db': $db, 'query': $n })
______________________________________
Best, Christian
MS
Mansi Sheth3 Nov 2014 21:37 #
Thanks Christian, The second query below worked beautifully. I am trying to get db:path of the dynamic query. Code:
declare variable $n as xs:string external;
declare option output:item-separator "
";

let $aPath :=
for $db in db:list()
let $query :=
  "declare variable $db external; " ||
  "db:open($db)" || $n
return xquery:eval($query,
  map { 'db': $db, 'query': $n })

for $elem in $aPath
return db:path($elem)
and am getting below exception, when called:
mansi@work:BigData mansiadmin$ basex -b\$n='<query>' get_paths.xq
Improper use? Potential bug? Your feedback is welcome:
Contact: basex-talk at mailman.uni-konstanz.de
Version: BaseX 7.9
Java: Oracle Corporation, 1.7.0_45
OS: Mac OS X, x86_64
Stack Trace:
java.lang.NullPointerException
at org.basex.query.value.item.Str.get(Str.java:49)
at org.basex.query.func.FNDb.path(FNDb.java:489)
at org.basex.query.func.FNDb.item(FNDb.java:128)
at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:45)
at org.basex.query.func.FNDb.iter(FNDb.java:92)
at org.basex.query.gflwor.GFLWOR$2.next(GFLWOR.java:78)
at org.basex.query.MainModule$1.next(MainModule.java:98)
at org.basex.core.cmd.AQuery.query(AQuery.java:91)
at org.basex.core.cmd.XQuery.run(XQuery.java:22)
at org.basex.core.Command.run(Command.java:329)
at org.basex.core.Command.execute(Command.java:94)
at org.basex.server.LocalSession.execute(LocalSession.java:121)
at org.basex.server.Session.execute(Session.java:37)
at org.basex.core.CLI.execute(CLI.java:106)
at org.basex.BaseX.<init>(BaseX.java:123)
at org.basex.BaseX.main(BaseX.java:42)
Quoted text · Christian Grün · 47 lines
On Thu, Oct 30, 2014 at 5:54 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Mansi, > > you have been close! It could work with the following query (I haven't > tried it out, though): > > _ get_query_result.xq ____________________ > > declare variable $n external; > declare option output:item-separator "&#xa;"; > > let $aList := > for $name in db:list() > let $db := db:open($name) > return xquery:eval($n, map { '': $db }) > > return distinct-values($aList) > ______________________________________ > > In this code, I'm opening the database in the main loop, and I then > bind it to the empty string. This way, the database will be the > context of the query to be evaluated query, and you won't have to deal > with bugs that arise from the concatenation of "db:open" and the query > string. > > > 1. Can we assign dynamic values as a value to a map's key ? > > 2. Can I map have more than one key, in query:eval ? > > This is both possible. As you see in the following query, you'll again > have to declare the variables that you want to bind. I agree this > causes a lot of code, so we may simplify it again in a future version > of BaseX: > ______________________________________ > > let $n := "/a/b/c" > for $db in db:list() > let $query := > "declare variable $db external; " || > "db:open($db)" || $n > return xquery:eval($query, > map { 'db': $db, 'query': $n }) > ______________________________________ > > Best, > Christian >
-- - Mansi
CG
Christian Grün4 Nov 2014 00:46 #
Quoted text · Mansi Sheth · 1 line
> Improper use? Potential bug? Your feedback is welcome:
Sounds like a little bug indeed; I will check it tomorrow!
Quoted text · Mansi Sheth · 77 lines
> Contact: basex-talk at mailman.uni-konstanz.de > Version: BaseX 7.9 > Java: Oracle Corporation, 1.7.0_45 > OS: Mac OS X, x86_64 > Stack Trace: > java.lang.NullPointerException > at org.basex.query.value.item.Str.get(Str.java:49) > at org.basex.query.func.FNDb.path(FNDb.java:489) > at org.basex.query.func.FNDb.item(FNDb.java:128) > at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:45) > at org.basex.query.func.FNDb.iter(FNDb.java:92) > at org.basex.query.gflwor.GFLWOR$2.next(GFLWOR.java:78) > at org.basex.query.MainModule$1.next(MainModule.java:98) > at org.basex.core.cmd.AQuery.query(AQuery.java:91) > at org.basex.core.cmd.XQuery.run(XQuery.java:22) > at org.basex.core.Command.run(Command.java:329) > at org.basex.core.Command.execute(Command.java:94) > at org.basex.server.LocalSession.execute(LocalSession.java:121) > at org.basex.server.Session.execute(Session.java:37) > at org.basex.core.CLI.execute(CLI.java:106) > at org.basex.BaseX.<init>(BaseX.java:123) > at org.basex.BaseX.main(BaseX.java:42) > > > On Thu, Oct 30, 2014 at 5:54 AM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> Hi Mansi, >> >> you have been close! It could work with the following query (I haven't >> tried it out, though): >> >> _ get_query_result.xq ____________________ >> >> declare variable $n external; >> declare option output:item-separator "&#xa;"; >> >> let $aList := >> for $name in db:list() >> let $db := db:open($name) >> return xquery:eval($n, map { '': $db }) >> >> return distinct-values($aList) >> ______________________________________ >> >> In this code, I'm opening the database in the main loop, and I then >> bind it to the empty string. This way, the database will be the >> context of the query to be evaluated query, and you won't have to deal >> with bugs that arise from the concatenation of "db:open" and the query >> string. >> >> > 1. Can we assign dynamic values as a value to a map's key ? >> > 2. Can I map have more than one key, in query:eval ? >> >> This is both possible. As you see in the following query, you'll again >> have to declare the variables that you want to bind. I agree this >> causes a lot of code, so we may simplify it again in a future version >> of BaseX: >> ______________________________________ >> >> let $n := "/a/b/c" >> for $db in db:list() >> let $query := >> "declare variable $db external; " || >> "db:open($db)" || $n >> return xquery:eval($query, >> map { 'db': $db, 'query': $n }) >> ______________________________________ >> >> Best, >> Christian > > > > > -- > - Mansi
CG
Christian Grün4 Nov 2014 00:48 #
…in the meanwhile, could you please check if the bug has possibly been fixed in the latest 8.0 snapshot [1]? [1] http://files.basex.org/releases/latest
Quoted text · Christian Grün · 84 lines
On Tue, Nov 4, 2014 at 12:46 AM, Christian Grün <christian.gruen at gmail.com> wrote: >> Improper use? Potential bug? Your feedback is welcome: > > Sounds like a little bug indeed; I will check it tomorrow! > > >> Contact: basex-talk at mailman.uni-konstanz.de >> Version: BaseX 7.9 >> Java: Oracle Corporation, 1.7.0_45 >> OS: Mac OS X, x86_64 >> Stack Trace: >> java.lang.NullPointerException >> at org.basex.query.value.item.Str.get(Str.java:49) >> at org.basex.query.func.FNDb.path(FNDb.java:489) >> at org.basex.query.func.FNDb.item(FNDb.java:128) >> at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:45) >> at org.basex.query.func.FNDb.iter(FNDb.java:92) >> at org.basex.query.gflwor.GFLWOR$2.next(GFLWOR.java:78) >> at org.basex.query.MainModule$1.next(MainModule.java:98) >> at org.basex.core.cmd.AQuery.query(AQuery.java:91) >> at org.basex.core.cmd.XQuery.run(XQuery.java:22) >> at org.basex.core.Command.run(Command.java:329) >> at org.basex.core.Command.execute(Command.java:94) >> at org.basex.server.LocalSession.execute(LocalSession.java:121) >> at org.basex.server.Session.execute(Session.java:37) >> at org.basex.core.CLI.execute(CLI.java:106) >> at org.basex.BaseX.<init>(BaseX.java:123) >> at org.basex.BaseX.main(BaseX.java:42) >> >> >> On Thu, Oct 30, 2014 at 5:54 AM, Christian Grün <christian.gruen at gmail.com> >> wrote: >>> >>> Hi Mansi, >>> >>> you have been close! It could work with the following query (I haven't >>> tried it out, though): >>> >>> _ get_query_result.xq ____________________ >>> >>> declare variable $n external; >>> declare option output:item-separator "&#xa;"; >>> >>> let $aList := >>> for $name in db:list() >>> let $db := db:open($name) >>> return xquery:eval($n, map { '': $db }) >>> >>> return distinct-values($aList) >>> ______________________________________ >>> >>> In this code, I'm opening the database in the main loop, and I then >>> bind it to the empty string. This way, the database will be the >>> context of the query to be evaluated query, and you won't have to deal >>> with bugs that arise from the concatenation of "db:open" and the query >>> string. >>> >>> > 1. Can we assign dynamic values as a value to a map's key ? >>> > 2. Can I map have more than one key, in query:eval ? >>> >>> This is both possible. As you see in the following query, you'll again >>> have to declare the variables that you want to bind. I agree this >>> causes a lot of code, so we may simplify it again in a future version >>> of BaseX: >>> ______________________________________ >>> >>> let $n := "/a/b/c" >>> for $db in db:list() >>> let $query := >>> "declare variable $db external; " || >>> "db:open($db)" || $n >>> return xquery:eval($query, >>> map { 'db': $db, 'query': $n }) >>> ______________________________________ >>> >>> Best, >>> Christian >> >> >> >> >> -- >> - Mansi
MS
Mansi Sheth5 Nov 2014 20:52 #
Christian, Thanks for all your support. I picked the latest snapshot as advised. For simple queries it worked ! However, below query didn't work: ~/Downloads/basex/bin/basex -bn='/Archives/*//class[contains(@name,"abc") and contains(@name,"pqr")]' get_paths.xq Stopped at /Users/mansiadmin/Documents/Research-Projects/BigData, 1/4: [XPDY0002] and: no context value bound. However, below query works as a charm: ~/Downloads/basex/bin/basex -bn='/Archives/*//class[contains(@name,"abc")]' get_paths.xq I am hoping, for first query above, its some syntactic issue at my end. But, couldn't fix it, so thought should point out. Please advise. Code:
declare variable $n as xs:string external;
declare option output:item-separator "&#xa;";

let $aPath :=
for $db in db:list()
let $query :=
  "declare variable $db external; " ||
  "db:open($db)" || $n
return xquery:eval($query,
  map { 'db': $db, 'query': $n })

let $paths :=
for $elem in $aPath
return db:path($elem)
return distinct-values($paths)
Quoted text · Christian Grün · 94 lines
On Mon, Nov 3, 2014 at 6:48 PM, Christian Grün <christian.gruen at gmail.com> wrote: > …in the meanwhile, could you please check if the bug has possibly been > fixed in the latest 8.0 snapshot [1]? > > [1] http://files.basex.org/releases/latest > > > On Tue, Nov 4, 2014 at 12:46 AM, Christian Grün > <christian.gruen at gmail.com> wrote: > >> Improper use? Potential bug? Your feedback is welcome: > > > > Sounds like a little bug indeed; I will check it tomorrow! > > > > > >> Contact: basex-talk at mailman.uni-konstanz.de > >> Version: BaseX 7.9 > >> Java: Oracle Corporation, 1.7.0_45 > >> OS: Mac OS X, x86_64 > >> Stack Trace: > >> java.lang.NullPointerException > >> at org.basex.query.value.item.Str.get(Str.java:49) > >> at org.basex.query.func.FNDb.path(FNDb.java:489) > >> at org.basex.query.func.FNDb.item(FNDb.java:128) > >> at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:45) > >> at org.basex.query.func.FNDb.iter(FNDb.java:92) > >> at org.basex.query.gflwor.GFLWOR$2.next(GFLWOR.java:78) > >> at org.basex.query.MainModule$1.next(MainModule.java:98) > >> at org.basex.core.cmd.AQuery.query(AQuery.java:91) > >> at org.basex.core.cmd.XQuery.run(XQuery.java:22) > >> at org.basex.core.Command.run(Command.java:329) > >> at org.basex.core.Command.execute(Command.java:94) > >> at org.basex.server.LocalSession.execute(LocalSession.java:121) > >> at org.basex.server.Session.execute(Session.java:37) > >> at org.basex.core.CLI.execute(CLI.java:106) > >> at org.basex.BaseX.<init>(BaseX.java:123) > >> at org.basex.BaseX.main(BaseX.java:42) > >> > >> > >> On Thu, Oct 30, 2014 at 5:54 AM, Christian Grün < > christian.gruen at gmail.com> > >> wrote: > >>> > >>> Hi Mansi, > >>> > >>> you have been close! It could work with the following query (I haven't > >>> tried it out, though): > >>> > >>> _ get_query_result.xq ____________________ > >>> > >>> declare variable $n external; > >>> declare option output:item-separator "&#xa;"; > >>> > >>> let $aList := > >>> for $name in db:list() > >>> let $db := db:open($name) > >>> return xquery:eval($n, map { '': $db }) > >>> > >>> return distinct-values($aList) > >>> ______________________________________ > >>> > >>> In this code, I'm opening the database in the main loop, and I then > >>> bind it to the empty string. This way, the database will be the > >>> context of the query to be evaluated query, and you won't have to deal > >>> with bugs that arise from the concatenation of "db:open" and the query > >>> string. > >>> > >>> > 1. Can we assign dynamic values as a value to a map's key ? > >>> > 2. Can I map have more than one key, in query:eval ? > >>> > >>> This is both possible. As you see in the following query, you'll again > >>> have to declare the variables that you want to bind. I agree this > >>> causes a lot of code, so we may simplify it again in a future version > >>> of BaseX: > >>> ______________________________________ > >>> > >>> let $n := "/a/b/c" > >>> for $db in db:list() > >>> let $query := > >>> "declare variable $db external; " || > >>> "db:open($db)" || $n > >>> return xquery:eval($query, > >>> map { 'db': $db, 'query': $n }) > >>> ______________________________________ > >>> > >>> Best, > >>> Christian > >> > >> > >> > >> > >> -- > >> - Mansi >
-- - Mansi
CG
Christian Grün6 Nov 2014 14:45 #
Hi Mansi,
Quoted text · Mansi Sheth · 4 lines
> ~/Downloads/basex/bin/basex -bn='/Archives/*//class[contains(@name,"abc") > and contains(@name,"pqr")]' get_paths.xq > Stopped at /Users/mansiadmin/Documents/Research-Projects/BigData, 1/4: > [XPDY0002] and: no context value bound.
It seems that "and" was interpreted as XPath step, so it seems as if something went wrong when parsing your query on command line (I doubt that it's something specific to BaseX). Maybe you can simply try to output the query that causes the error, instead of trying to evaluate it? Christian
Quoted text · Mansi Sheth · 128 lines
> > However, below query works as a charm: > > ~/Downloads/basex/bin/basex -bn='/Archives/*//class[contains(@name,"abc")]' > get_paths.xq > > I am hoping, for first query above, its some syntactic issue at my end. But, > couldn't fix it, so thought should point out. Please advise. > > Code: > > declare variable $n as xs:string external; > declare option output:item-separator "&#xa;"; > > let $aPath := > for $db in db:list() > let $query := > "declare variable $db external; " || > "db:open($db)" || $n > return xquery:eval($query, > map { 'db': $db, 'query': $n }) > > let $paths := > for $elem in $aPath > return db:path($elem) > > return distinct-values($paths) > > On Mon, Nov 3, 2014 at 6:48 PM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> …in the meanwhile, could you please check if the bug has possibly been >> fixed in the latest 8.0 snapshot [1]? >> >> [1] http://files.basex.org/releases/latest >> >> >> On Tue, Nov 4, 2014 at 12:46 AM, Christian Grün >> <christian.gruen at gmail.com> wrote: >> >> Improper use? Potential bug? Your feedback is welcome: >> > >> > Sounds like a little bug indeed; I will check it tomorrow! >> > >> > >> >> Contact: basex-talk at mailman.uni-konstanz.de >> >> Version: BaseX 7.9 >> >> Java: Oracle Corporation, 1.7.0_45 >> >> OS: Mac OS X, x86_64 >> >> Stack Trace: >> >> java.lang.NullPointerException >> >> at org.basex.query.value.item.Str.get(Str.java:49) >> >> at org.basex.query.func.FNDb.path(FNDb.java:489) >> >> at org.basex.query.func.FNDb.item(FNDb.java:128) >> >> at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:45) >> >> at org.basex.query.func.FNDb.iter(FNDb.java:92) >> >> at org.basex.query.gflwor.GFLWOR$2.next(GFLWOR.java:78) >> >> at org.basex.query.MainModule$1.next(MainModule.java:98) >> >> at org.basex.core.cmd.AQuery.query(AQuery.java:91) >> >> at org.basex.core.cmd.XQuery.run(XQuery.java:22) >> >> at org.basex.core.Command.run(Command.java:329) >> >> at org.basex.core.Command.execute(Command.java:94) >> >> at org.basex.server.LocalSession.execute(LocalSession.java:121) >> >> at org.basex.server.Session.execute(Session.java:37) >> >> at org.basex.core.CLI.execute(CLI.java:106) >> >> at org.basex.BaseX.<init>(BaseX.java:123) >> >> at org.basex.BaseX.main(BaseX.java:42) >> >> >> >> >> >> On Thu, Oct 30, 2014 at 5:54 AM, Christian Grün >> >> <christian.gruen at gmail.com> >> >> wrote: >> >>> >> >>> Hi Mansi, >> >>> >> >>> you have been close! It could work with the following query (I haven't >> >>> tried it out, though): >> >>> >> >>> _ get_query_result.xq ____________________ >> >>> >> >>> declare variable $n external; >> >>> declare option output:item-separator "&#xa;"; >> >>> >> >>> let $aList := >> >>> for $name in db:list() >> >>> let $db := db:open($name) >> >>> return xquery:eval($n, map { '': $db }) >> >>> >> >>> return distinct-values($aList) >> >>> ______________________________________ >> >>> >> >>> In this code, I'm opening the database in the main loop, and I then >> >>> bind it to the empty string. This way, the database will be the >> >>> context of the query to be evaluated query, and you won't have to deal >> >>> with bugs that arise from the concatenation of "db:open" and the query >> >>> string. >> >>> >> >>> > 1. Can we assign dynamic values as a value to a map's key ? >> >>> > 2. Can I map have more than one key, in query:eval ? >> >>> >> >>> This is both possible. As you see in the following query, you'll again >> >>> have to declare the variables that you want to bind. I agree this >> >>> causes a lot of code, so we may simplify it again in a future version >> >>> of BaseX: >> >>> ______________________________________ >> >>> >> >>> let $n := "/a/b/c" >> >>> for $db in db:list() >> >>> let $query := >> >>> "declare variable $db external; " || >> >>> "db:open($db)" || $n >> >>> return xquery:eval($query, >> >>> map { 'db': $db, 'query': $n }) >> >>> ______________________________________ >> >>> >> >>> Best, >> >>> Christian >> >> >> >> >> >> >> >> >> >> -- >> >> - Mansi > > > > > -- > - Mansi
MS
Mansi Sheth7 Nov 2014 20:34 #
Christian, I am running out of ideas in debugging this. When I directly execute this query within XQUERY file, its working perfectly. Just when I pass it thru command line, its breaking. Infact the actual .xq file also doesn't matter, as you pointed out, parsing from command line is broken. I tried "-d" switch and escaping spaces, but didn't help. Also, I tested, this is a valid XPATH query. Please pardon my XQUERY knowledge, its really not my background. - Mansi
Quoted text · Christian Grün · 156 lines
On Thu, Nov 6, 2014 at 8:45 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Mansi, > > > ~/Downloads/basex/bin/basex -bn='/Archives/*//class[contains(@name,"abc") > > and contains(@name,"pqr")]' get_paths.xq > > Stopped at /Users/mansiadmin/Documents/Research-Projects/BigData, 1/4: > > [XPDY0002] and: no context value bound. > > It seems that "and" was interpreted as XPath step, so it seems as if > something went wrong when parsing your query on command line (I doubt > that it's something specific to BaseX). > > Maybe you can simply try to output the query that causes the error, > instead of trying to evaluate it? > > Christian > > > > > > However, below query works as a charm: > > > > ~/Downloads/basex/bin/basex > -bn='/Archives/*//class[contains(@name,"abc")]' > > get_paths.xq > > > > I am hoping, for first query above, its some syntactic issue at my end. > But, > > couldn't fix it, so thought should point out. Please advise. > > > > Code: > > > > declare variable $n as xs:string external; > > declare option output:item-separator "&#xa;"; > > > > let $aPath := > > for $db in db:list() > > let $query := > > "declare variable $db external; " || > > "db:open($db)" || $n > > return xquery:eval($query, > > map { 'db': $db, 'query': $n }) > > > > let $paths := > > for $elem in $aPath > > return db:path($elem) > > > > return distinct-values($paths) > > > > On Mon, Nov 3, 2014 at 6:48 PM, Christian Grün < > christian.gruen at gmail.com> > > wrote: > >> > >> …in the meanwhile, could you please check if the bug has possibly been > >> fixed in the latest 8.0 snapshot [1]? > >> > >> [1] http://files.basex.org/releases/latest > >> > >> > >> On Tue, Nov 4, 2014 at 12:46 AM, Christian Grün > >> <christian.gruen at gmail.com> wrote: > >> >> Improper use? Potential bug? Your feedback is welcome: > >> > > >> > Sounds like a little bug indeed; I will check it tomorrow! > >> > > >> > > >> >> Contact: basex-talk at mailman.uni-konstanz.de > >> >> Version: BaseX 7.9 > >> >> Java: Oracle Corporation, 1.7.0_45 > >> >> OS: Mac OS X, x86_64 > >> >> Stack Trace: > >> >> java.lang.NullPointerException > >> >> at org.basex.query.value.item.Str.get(Str.java:49) > >> >> at org.basex.query.func.FNDb.path(FNDb.java:489) > >> >> at org.basex.query.func.FNDb.item(FNDb.java:128) > >> >> at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:45) > >> >> at org.basex.query.func.FNDb.iter(FNDb.java:92) > >> >> at org.basex.query.gflwor.GFLWOR$2.next(GFLWOR.java:78) > >> >> at org.basex.query.MainModule$1.next(MainModule.java:98) > >> >> at org.basex.core.cmd.AQuery.query(AQuery.java:91) > >> >> at org.basex.core.cmd.XQuery.run(XQuery.java:22) > >> >> at org.basex.core.Command.run(Command.java:329) > >> >> at org.basex.core.Command.execute(Command.java:94) > >> >> at org.basex.server.LocalSession.execute(LocalSession.java:121) > >> >> at org.basex.server.Session.execute(Session.java:37) > >> >> at org.basex.core.CLI.execute(CLI.java:106) > >> >> at org.basex.BaseX.<init>(BaseX.java:123) > >> >> at org.basex.BaseX.main(BaseX.java:42) > >> >> > >> >> > >> >> On Thu, Oct 30, 2014 at 5:54 AM, Christian Grün > >> >> <christian.gruen at gmail.com> > >> >> wrote: > >> >>> > >> >>> Hi Mansi, > >> >>> > >> >>> you have been close! It could work with the following query (I > haven't > >> >>> tried it out, though): > >> >>> > >> >>> _ get_query_result.xq ____________________ > >> >>> > >> >>> declare variable $n external; > >> >>> declare option output:item-separator "&#xa;"; > >> >>> > >> >>> let $aList := > >> >>> for $name in db:list() > >> >>> let $db := db:open($name) > >> >>> return xquery:eval($n, map { '': $db }) > >> >>> > >> >>> return distinct-values($aList) > >> >>> ______________________________________ > >> >>> > >> >>> In this code, I'm opening the database in the main loop, and I then > >> >>> bind it to the empty string. This way, the database will be the > >> >>> context of the query to be evaluated query, and you won't have to > deal > >> >>> with bugs that arise from the concatenation of "db:open" and the > query > >> >>> string. > >> >>> > >> >>> > 1. Can we assign dynamic values as a value to a map's key ? > >> >>> > 2. Can I map have more than one key, in query:eval ? > >> >>> > >> >>> This is both possible. As you see in the following query, you'll > again > >> >>> have to declare the variables that you want to bind. I agree this > >> >>> causes a lot of code, so we may simplify it again in a future > version > >> >>> of BaseX: > >> >>> ______________________________________ > >> >>> > >> >>> let $n := "/a/b/c" > >> >>> for $db in db:list() > >> >>> let $query := > >> >>> "declare variable $db external; " || > >> >>> "db:open($db)" || $n > >> >>> return xquery:eval($query, > >> >>> map { 'db': $db, 'query': $n }) > >> >>> ______________________________________ > >> >>> > >> >>> Best, > >> >>> Christian > >> >> > >> >> > >> >> > >> >> > >> >> -- > >> >> - Mansi > > > > > > > > > > -- > > - Mansi >
-- - Mansi
DK
Dirk Kirsten10 Nov 2014 10:35 #
Hi Mansi, the same as in my other mail on the list a few minutes ago. I do think this is a bug in our command line scripts, I just sent a pull request (https://github.com/BaseXdb/basex/pull/1024) which should fix the issue. Cheers, Dirk
Quoted text · Mansi Sheth · 177 lines
On 11/07/2014 07:34 PM, Mansi Sheth wrote: > Christian, > > I am running out of ideas in debugging this. When I directly execute this > query within XQUERY file, its working perfectly. Just when I pass it thru > command line, its breaking. > > Infact the actual .xq file also doesn't matter, as you pointed out, parsing > from command line is broken. I tried "-d" switch and escaping spaces, but > didn't help. Also, I tested, this is a valid XPATH query. > > Please pardon my XQUERY knowledge, its really not my background. > > - Mansi > > > > On Thu, Nov 6, 2014 at 8:45 AM, Christian Grün <christian.gruen at gmail.com> > wrote: > > > Hi Mansi, > > > >> ~/Downloads/basex/bin/basex -bn='/Archives/*//class[contains(@name,"abc") > >> and contains(@name,"pqr")]' get_paths.xq > >> Stopped at /Users/mansiadmin/Documents/Research-Projects/BigData, 1/4: > >> [XPDY0002] and: no context value bound. > > > > It seems that "and" was interpreted as XPath step, so it seems as if > > something went wrong when parsing your query on command line (I doubt > > that it's something specific to BaseX). > > > > Maybe you can simply try to output the query that causes the error, > > instead of trying to evaluate it? > > > > Christian > > > > > >> > >> However, below query works as a charm: > >> > >> ~/Downloads/basex/bin/basex > > -bn='/Archives/*//class[contains(@name,"abc")]' > >> get_paths.xq > >> > >> I am hoping, for first query above, its some syntactic issue at my end. > > But, > >> couldn't fix it, so thought should point out. Please advise. > >> > >> Code: > >> > >> declare variable $n as xs:string external; > >> declare option output:item-separator "&#xa;"; > >> > >> let $aPath := > >> for $db in db:list() > >> let $query := > >> "declare variable $db external; " || > >> "db:open($db)" || $n > >> return xquery:eval($query, > >> map { 'db': $db, 'query': $n }) > >> > >> let $paths := > >> for $elem in $aPath > >> return db:path($elem) > >> > >> return distinct-values($paths) > >> > >> On Mon, Nov 3, 2014 at 6:48 PM, Christian Grün < > > christian.gruen at gmail.com> > >> wrote: > >>> > >>> …in the meanwhile, could you please check if the bug has possibly been > >>> fixed in the latest 8.0 snapshot [1]? > >>> > >>> [1] http://files.basex.org/releases/latest > >>> > >>> > >>> On Tue, Nov 4, 2014 at 12:46 AM, Christian Grün > >>> <christian.gruen at gmail.com> wrote: > >>>>> Improper use? Potential bug? Your feedback is welcome: > >>>> > >>>> Sounds like a little bug indeed; I will check it tomorrow! > >>>> > >>>> > >>>>> Contact: basex-talk at mailman.uni-konstanz.de > >>>>> Version: BaseX 7.9 > >>>>> Java: Oracle Corporation, 1.7.0_45 > >>>>> OS: Mac OS X, x86_64 > >>>>> Stack Trace: > >>>>> java.lang.NullPointerException > >>>>> at org.basex.query.value.item.Str.get(Str.java:49) > >>>>> at org.basex.query.func.FNDb.path(FNDb.java:489) > >>>>> at org.basex.query.func.FNDb.item(FNDb.java:128) > >>>>> at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:45) > >>>>> at org.basex.query.func.FNDb.iter(FNDb.java:92) > >>>>> at org.basex.query.gflwor.GFLWOR$2.next(GFLWOR.java:78) > >>>>> at org.basex.query.MainModule$1.next(MainModule.java:98) > >>>>> at org.basex.core.cmd.AQuery.query(AQuery.java:91) > >>>>> at org.basex.core.cmd.XQuery.run(XQuery.java:22) > >>>>> at org.basex.core.Command.run(Command.java:329) > >>>>> at org.basex.core.Command.execute(Command.java:94) > >>>>> at org.basex.server.LocalSession.execute(LocalSession.java:121) > >>>>> at org.basex.server.Session.execute(Session.java:37) > >>>>> at org.basex.core.CLI.execute(CLI.java:106) > >>>>> at org.basex.BaseX.<init>(BaseX.java:123) > >>>>> at org.basex.BaseX.main(BaseX.java:42) > >>>>> > >>>>> > >>>>> On Thu, Oct 30, 2014 at 5:54 AM, Christian Grün > >>>>> <christian.gruen at gmail.com> > >>>>> wrote: > >>>>>> > >>>>>> Hi Mansi, > >>>>>> > >>>>>> you have been close! It could work with the following query (I > > haven't > >>>>>> tried it out, though): > >>>>>> > >>>>>> _ get_query_result.xq ____________________ > >>>>>> > >>>>>> declare variable $n external; > >>>>>> declare option output:item-separator "&#xa;"; > >>>>>> > >>>>>> let $aList := > >>>>>> for $name in db:list() > >>>>>> let $db := db:open($name) > >>>>>> return xquery:eval($n, map { '': $db }) > >>>>>> > >>>>>> return distinct-values($aList) > >>>>>> ______________________________________ > >>>>>> > >>>>>> In this code, I'm opening the database in the main loop, and I then > >>>>>> bind it to the empty string. This way, the database will be the > >>>>>> context of the query to be evaluated query, and you won't have to > > deal > >>>>>> with bugs that arise from the concatenation of "db:open" and the > > query > >>>>>> string. > >>>>>> > >>>>>>> 1. Can we assign dynamic values as a value to a map's key ? > >>>>>>> 2. Can I map have more than one key, in query:eval ? > >>>>>> > >>>>>> This is both possible. As you see in the following query, you'll > > again > >>>>>> have to declare the variables that you want to bind. I agree this > >>>>>> causes a lot of code, so we may simplify it again in a future > > version > >>>>>> of BaseX: > >>>>>> ______________________________________ > >>>>>> > >>>>>> let $n := "/a/b/c" > >>>>>> for $db in db:list() > >>>>>> let $query := > >>>>>> "declare variable $db external; " || > >>>>>> "db:open($db)" || $n > >>>>>> return xquery:eval($query, > >>>>>> map { 'db': $db, 'query': $n }) > >>>>>> ______________________________________ > >>>>>> > >>>>>> Best, > >>>>>> Christian > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> -- > >>>>> - Mansi > >> > >> > >> > >> > >> -- > >> - Mansi > > > > >
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
CG
Christian Grün10 Nov 2014 13:12 #
…a new snapshot is available.
Quoted text · Dirk Kirsten · 193 lines
On Mon, Nov 10, 2014 at 10:35 AM, Dirk Kirsten <dk at basex.org> wrote: > Hi Mansi, > > the same as in my other mail on the list a few minutes ago. I do think this is a bug in our command line scripts, I just sent a pull request (https://github.com/BaseXdb/basex/pull/1024) which should fix the issue. > > Cheers, > Dirk > > On 11/07/2014 07:34 PM, Mansi Sheth wrote: >> Christian, >> >> I am running out of ideas in debugging this. When I directly execute this >> query within XQUERY file, its working perfectly. Just when I pass it thru >> command line, its breaking. >> >> Infact the actual .xq file also doesn't matter, as you pointed out, parsing >> from command line is broken. I tried "-d" switch and escaping spaces, but >> didn't help. Also, I tested, this is a valid XPATH query. >> >> Please pardon my XQUERY knowledge, its really not my background. >> >> - Mansi >> >> >> >> On Thu, Nov 6, 2014 at 8:45 AM, Christian Grün <christian.gruen at gmail.com> >> wrote: >> >> > Hi Mansi, >> > >> >> ~/Downloads/basex/bin/basex -bn='/Archives/*//class[contains(@name,"abc") >> >> and contains(@name,"pqr")]' get_paths.xq >> >> Stopped at /Users/mansiadmin/Documents/Research-Projects/BigData, 1/4: >> >> [XPDY0002] and: no context value bound. >> > >> > It seems that "and" was interpreted as XPath step, so it seems as if >> > something went wrong when parsing your query on command line (I doubt >> > that it's something specific to BaseX). >> > >> > Maybe you can simply try to output the query that causes the error, >> > instead of trying to evaluate it? >> > >> > Christian >> > >> > >> >> >> >> However, below query works as a charm: >> >> >> >> ~/Downloads/basex/bin/basex >> > -bn='/Archives/*//class[contains(@name,"abc")]' >> >> get_paths.xq >> >> >> >> I am hoping, for first query above, its some syntactic issue at my end. >> > But, >> >> couldn't fix it, so thought should point out. Please advise. >> >> >> >> Code: >> >> >> >> declare variable $n as xs:string external; >> >> declare option output:item-separator "&#xa;"; >> >> >> >> let $aPath := >> >> for $db in db:list() >> >> let $query := >> >> "declare variable $db external; " || >> >> "db:open($db)" || $n >> >> return xquery:eval($query, >> >> map { 'db': $db, 'query': $n }) >> >> >> >> let $paths := >> >> for $elem in $aPath >> >> return db:path($elem) >> >> >> >> return distinct-values($paths) >> >> >> >> On Mon, Nov 3, 2014 at 6:48 PM, Christian Grün < >> > christian.gruen at gmail.com> >> >> wrote: >> >>> >> >>> …in the meanwhile, could you please check if the bug has possibly been >> >>> fixed in the latest 8.0 snapshot [1]? >> >>> >> >>> [1] http://files.basex.org/releases/latest >> >>> >> >>> >> >>> On Tue, Nov 4, 2014 at 12:46 AM, Christian Grün >> >>> <christian.gruen at gmail.com> wrote: >> >>>>> Improper use? Potential bug? Your feedback is welcome: >> >>>> >> >>>> Sounds like a little bug indeed; I will check it tomorrow! >> >>>> >> >>>> >> >>>>> Contact: basex-talk at mailman.uni-konstanz.de >> >>>>> Version: BaseX 7.9 >> >>>>> Java: Oracle Corporation, 1.7.0_45 >> >>>>> OS: Mac OS X, x86_64 >> >>>>> Stack Trace: >> >>>>> java.lang.NullPointerException >> >>>>> at org.basex.query.value.item.Str.get(Str.java:49) >> >>>>> at org.basex.query.func.FNDb.path(FNDb.java:489) >> >>>>> at org.basex.query.func.FNDb.item(FNDb.java:128) >> >>>>> at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:45) >> >>>>> at org.basex.query.func.FNDb.iter(FNDb.java:92) >> >>>>> at org.basex.query.gflwor.GFLWOR$2.next(GFLWOR.java:78) >> >>>>> at org.basex.query.MainModule$1.next(MainModule.java:98) >> >>>>> at org.basex.core.cmd.AQuery.query(AQuery.java:91) >> >>>>> at org.basex.core.cmd.XQuery.run(XQuery.java:22) >> >>>>> at org.basex.core.Command.run(Command.java:329) >> >>>>> at org.basex.core.Command.execute(Command.java:94) >> >>>>> at org.basex.server.LocalSession.execute(LocalSession.java:121) >> >>>>> at org.basex.server.Session.execute(Session.java:37) >> >>>>> at org.basex.core.CLI.execute(CLI.java:106) >> >>>>> at org.basex.BaseX.<init>(BaseX.java:123) >> >>>>> at org.basex.BaseX.main(BaseX.java:42) >> >>>>> >> >>>>> >> >>>>> On Thu, Oct 30, 2014 at 5:54 AM, Christian Grün >> >>>>> <christian.gruen at gmail.com> >> >>>>> wrote: >> >>>>>> >> >>>>>> Hi Mansi, >> >>>>>> >> >>>>>> you have been close! It could work with the following query (I >> > haven't >> >>>>>> tried it out, though): >> >>>>>> >> >>>>>> _ get_query_result.xq ____________________ >> >>>>>> >> >>>>>> declare variable $n external; >> >>>>>> declare option output:item-separator "&#xa;"; >> >>>>>> >> >>>>>> let $aList := >> >>>>>> for $name in db:list() >> >>>>>> let $db := db:open($name) >> >>>>>> return xquery:eval($n, map { '': $db }) >> >>>>>> >> >>>>>> return distinct-values($aList) >> >>>>>> ______________________________________ >> >>>>>> >> >>>>>> In this code, I'm opening the database in the main loop, and I then >> >>>>>> bind it to the empty string. This way, the database will be the >> >>>>>> context of the query to be evaluated query, and you won't have to >> > deal >> >>>>>> with bugs that arise from the concatenation of "db:open" and the >> > query >> >>>>>> string. >> >>>>>> >> >>>>>>> 1. Can we assign dynamic values as a value to a map's key ? >> >>>>>>> 2. Can I map have more than one key, in query:eval ? >> >>>>>> >> >>>>>> This is both possible. As you see in the following query, you'll >> > again >> >>>>>> have to declare the variables that you want to bind. I agree this >> >>>>>> causes a lot of code, so we may simplify it again in a future >> > version >> >>>>>> of BaseX: >> >>>>>> ______________________________________ >> >>>>>> >> >>>>>> let $n := "/a/b/c" >> >>>>>> for $db in db:list() >> >>>>>> let $query := >> >>>>>> "declare variable $db external; " || >> >>>>>> "db:open($db)" || $n >> >>>>>> return xquery:eval($query, >> >>>>>> map { 'db': $db, 'query': $n }) >> >>>>>> ______________________________________ >> >>>>>> >> >>>>>> Best, >> >>>>>> Christian >> >>>>> >> >>>>> >> >>>>> >> >>>>> >> >>>>> -- >> >>>>> - Mansi >> >> >> >> >> >> >> >> >> >> -- >> >> - Mansi >> > >> >> >> > > -- > Dirk Kirsten, BaseX GmbH, http://basex.org > |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz > |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: > | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle > `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 >

⚡Generated with XQuery