Database Reference
In-Depth Information
UNION(
UNION(
EvaluateXQuery(
'for $o in $s/country
for $c in $o/capital_city/city
where $o/code = $c/country
and $c/name = "Manchester"',
null, null),
EvaluateXQuery(
'for $o in $s/country
for $c in $o/other_city/city
where $o/code = $c/country
and $c/name = "Manchester"',
null, null)),
EvaluateSQL(
'Select o.name, c.name
from country o, city c
where o.code = c.country
and c.name = "Manchester"',
null, null))
Fig. 3. Expanded and rewritten query Q 2
Require: s = query (fragment) to be translated, expressed in algebra introduced above
1: if s instance of SCAN(abstract c) | s instance of SCAN(structOfAttributes c) then
2: if !s.let.contains(c.source) then
3: s.let.add(c, c.source)
4: end if
5: s.for.add(c)
6: else if s instance of REDUCE(Collection c, { Lexical } ) then
7: for all Lexical l ∈{ Lexical } do
8: s.return.add(l)
9: end for
10: Translate2XQuery(c)
11: else if s instance of FILTER(Collection c, Predicate) then
12: s.where.add(p)
13: Translate2XQuery(c)
14: else if s instance of JOIN(Left Collection lc, Right Collection rc, Predicate) then
15: s.where.add(p)
16: Translate2XQuery(lc)
17: Translate2XQuery(rc)
18: end if
Fig. 4. Translate2XQuery(s)
traversing the SMql -algebra (Algorithm shown in Figure 4) followed by the gener-
ation of a string representation of the XQuery utilising the gathered information
(Algorithm shown in Figure 5). The algorithms presented are not the only way
to organise the information and generate the corresponding XQuery, as there are
several ways of expressing the same XQuery. For example, an equivalent XQuery
to query Q 1 in Figure 2 posed over S 2 could be written as one of the two versions
v1 or v2:
v1:for $c in doc("...")//country[population>"5000000"]
v2:let $s := doc("...") for $c in $s//country where $c/population > 5000000
We have decided to follow the structuring of the information and consequently
of the XQuery that is somewhat related to the structure of a SQL query, i.e.,
for corresponds to from , return corresponds to select , where corresponds to
where , and to capture only the reference to the source document in let ,which
results in queries structured as exemplified in v2.
 
Search WWH ::




Custom Search