some eq versus =
Monday, 8 April 2024 · 5 messages · last reply 10 Apr 2024
LS
Leo Studer8 Apr 2024 23:58 #
Hello
are the following queries equivalent?
1. //city[some $city in following::city satisfies string(.) eq string($city)]
2. //city[. = following::city ]
Thanks in advance,
Leo
MH
Martin Honnen9 Apr 2024 00:08 #
Quoted text · Leo Studer · 13 lines
On 08/04/2024 23:58, Leo Studer wrote: > Hello > > are the following queries equivalent? > > 1. //*city*[*some* *$city* *in* following::*city* *satisfies* > /string/(.) eq /string/(*$city*)] > > > 2. //*city*[.=following::*city*] > > >
More or less, I would say, depending on whether there is schema-aware processing done or not where perhaps . = following::city might not do string comparison.
CG
Hi Leo,
Yes, they are equivalent. Version 2 is a bit faster because "." will only need to be atomized once.
We’ll examine if BaseX can automatically rewrite version 1 to version 2.
Best,
Christian
Quoted text · Leo Studer · 17 lines
On Mon, Apr 8, 2024 at 11:59 PM Leo Studer <leo.studer at varioweb.ch> wrote: > Hello > > are the following queries equivalent? > > 1. //*city*[*some* *$city* *in* following::*city* *satisfies* *string*(.) > eq *string*(*$city*)] > > 2. //*city*[. = following::*city* ] > > > > Thanks in advance, > Leo > > >
LS
Leo Studer10 Apr 2024 08:53 #
Hi Christian Thanks for your answer. I came across this question because I needed to know whether there are city elements twice in the file. For that I wrote version 2 and the result was wrong. Then I wrote version 1 with … satisfies . => deep-equal($city)
that gave the correct answer. I noticed that I do not fully understand the cast behavior of the = operator… Blessings,
Leo
Sent from my dish washer
Quoted text · Christian Grün · 37 lines
> On 9 Apr 2024, at 11:28, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Leo, > > > Yes, they are equivalent. Version 2 is a bit faster because "." will only need to be atomized once. > > > We’ll examine if BaseX can automatically rewrite version 1 to version 2. > > > > Best, > Christian > > > > > On Mon, Apr 8, 2024 at 11:59 PM Leo Studer <leo.studer at varioweb.ch> wrote: > > > > Hello > > > > are the following queries equivalent? > > > > > > 1. //city[some $city in following::city satisfies string(.) eq string($city)] > > > > > > > > 2. //city[. = following::city ] > > > > > > > > > > > > Thanks in advance, > > Leo
CG
Christian Grün10 Apr 2024 09:09 #
Hi Leo,
Quoted text · Leo Studer · 7 lines
I came across this question because I needed to know whether there are city > elements twice in the file. For that I wrote version 2 and the result was > wrong. Then I wrote version 1 with > … satisfies . => deep-equal($city) > that gave the correct answer. I noticed that I do not fully understand the > cast behavior of the = operator… >
Thanks. deep-equal() is probably what you want. If you use generalized comparisons (=, !=, etc.), or if you use “data(.)” or “string(.)”, the descendant text nodes of the referenced node will be concatenated and returned as single string. As a result, queries like the following one…
<a><b>X</b></a> = <a><c>X</c></a>…will return “true” because the atomized value of both operands is“X”.
Sibling node traversals are often slow, as the same nodes are repatedly processed.
for $city-group in //city
group by $string := serialize($city-group)
where count($city-group) > 1
return head($city-group)With the latest BaseX 11 snapshot and the upcoming XQuery 4 features, it could be:
for value $v in map:build(//city, serialize#1)
where count($v) > 1
return head($v)Hope this helps,
Christian
Written for BaseX 10.7. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery