Managing XML and Semistructured Data - PowerPoint PPT Presentation

Loading...

PPT – Managing XML and Semistructured Data PowerPoint presentation | free to download - id: f271-NTM1O



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Managing XML and Semistructured Data

Description:

For each author of a book by Morgan Kaufmann, list all books she published: ... ELSE $h/author /holding SORTBY (title) Existential Quantifiers. FOR $b IN //book ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 26
Provided by: csWash
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Managing XML and Semistructured Data


1
Managing XML and Semistructured Data
  • Lecture 7 Query Languages - XQuery

Prof. Dan Suciu
Spring 2001
2
In this lecture
  • Summary of XQuery
  • FLWR expressions
  • FOR and LET expressions
  • Collections and sorting
  • Resources
  • XQuery A Query Language for XML Chamberlin,
    Florescu, et al.
  • W3C recommendation www.w3.org/TR/xquery/

3
XQuery
  • Based on Quilt (which is based on XML-QL)
  • http//www.w3.org/TR/xquery/2/2001
  • XML Query data model (of course ?)
  • Ordered !

4
FLWR (Flower) Expressions
  • FOR ... LET... FOR... LET...
  • WHERE...
  • RETURN...

5
XQuery
  • Find all book titles published after 1995

FOR x IN document("bib.xml")/bib/book WHERE
x/year 1995 RETURN x/title
Result abc def
ghi
6
XQuery
  • For each author of a book by Morgan Kaufmann,
    list all books she published

FOR a IN distinct(document("bib.xml")
/bib/bookpublisherMorgan
Kaufmann/author) RETURN
a, FOR t IN
/bib/bookauthora/title
RETURN t
distinct a function that eliminates duplicates
7
XQuery
  • Result
  • Jones
  • abc
  • def
  • Smith
  • ghi

8
XQuery
  • FOR x in expr -- binds x to each element in
    the list expr
  • LET x expr -- binds x to the entire list
    expr
  • Useful for common subexpressions and for
    aggregations

9
XQuery
FOR p IN
distinct(document("bib.xml")//publisher)
LET b document("bib.xml")/bookpublisher
p WHERE count(b) 100 RETURN
p
count a (aggregate) function that returns the
number of elms
10
XQuery
  • Find books whose price is larger than average

LET aavg(document("bib.xml")/bib/book/_at_price) FO
R b in document("bib.xml")/bib/book WHERE
b/_at_price a RETURN b
11
XQuery
  • Summary
  • FOR-LET-WHERE-RETURN FLWR

FOR/LET Clauses
List of tuples
WHERE Clause
List of tuples
RETURN Clause
Instance of Xquery data model
12
FOR v.s. LET
  • FOR
  • Binds node variables ? iteration
  • LET
  • Binds collection variables ? one value

13
FOR v.s. LET
Returns ...
...
... ...
FOR x IN document("bib.xml")/bib/book RETURN
x
LET x document("bib.xml")/bib/book RETURN
x
Returns ...
...
... ...
14
Collections in XQuery
  • Ordered and unordered collections
  • /bib/book/author an ordered collection
  • Distinct(/bib/book/author) an unordered
    collection
  • LET a /bib/book ? a is a collection
  • b/author ? a collection (several authors...)

Returns ...
...
...
...
RETURN b/author
15
Collections in XQuery
  • What about collections in expressions ?
  • b/_at_price ? list of n
    prices
  • b/_at_price 0.7 ? list of n numbers
  • b/_at_price b/_at_quantity ? list of n x m numbers
    ??
  • b/_at_price (b/_at_quant1 b/_at_quant2) ?
    b/_at_price b/_at_quant1 b/_at_price b/_at_quant2
    !!

16
Sorting in XQuery
FOR p IN distinct(document("
bib.xml")//publisher) RETURN
p/text() ,
FOR b IN document("bib.xml")//bookpublisher
p RETURN

b/title ,
b/_at_price
SORTBY(price DESCENDING)
SORTBY(name)

17
Sorting in XQuery
  • Sorting arugments refer to the name space of the
    RETURN clause, not the FOR clause
  • To sort on an element you dont want to display,
    first return it, then remove it with an
    additional query.

18
If-Then-Else
FOR h IN //holding RETURN
h/title, IF
h/_at_type "Journal"
THEN h/editor ELSE
h/author SORTBY
(title)
19
Existential Quantifiers
FOR b IN //book WHERE SOME p IN b//para
SATISFIES contains(p, "sailing") AND
contains(p, "windsurfing") RETURN b/title
20
Universal Quantifiers
FOR b IN //book WHERE EVERY p IN b//para
SATISFIES contains(p, "sailing") RETURN
b/title
21
Other Stuff in XQuery
  • BEFORE and AFTER
  • for dealing with order in the input
  • FILTER
  • deletes some edges in the result tree
  • Recursive functions
  • Currently arbitrary recursion
  • Perhaps more restrictions in the future ?

22
Group-By in Xquery ??
  • No GROUPBY currently in XQuery
  • A recent proposal (next)
  • What do YOU think ?

23
Group-By in Xquery ??
FOR b IN document("http//www.bn.com")/bib/book,
y IN b/_at_year WHERE
b/publisher"Morgan Kaufmann" RETURN
GROUPBY y WHERE count(b)
10 IN y
? with GROUPBY
SELECT year FROM Bib WHERE Bib.publisher"Morga
n Kaufmann" GROUPBY year HAVING count() 10
Equivalent SQL ?
24
Group-By in Xquery ??
FOR b IN document("http//www.bn.com")/bib/book,
a IN b/author, y IN
b/_at_yearRETURN GROUPBY a, y
IN a,
y ,
count(b)

? with GROUPBY
FOR Tup IN distinct(FOR b IN
document("http//www.bn.com")/bib,
a IN b/author,
y IN b/_at_year
RETURN a y ),
a IN Tup/a/node(), y IN
Tup/y/node() LET b document("http//www.bn.
com")/bib/bookauthora,_at_yeary RETURN
a,
y ,
count(b)

Without GROUPBY ?
25
Group-By in Xquery ??
FOR b IN document("http//www.bn.com")/bib/book,
a IN b/author, y IN
b/_at_year, t IN b/title, p
IN b/publisher RETURN GROUPBY p, y
IN p, y
, GROUPBY a
IN
a,
GROUPBY t IN
t

? Nested GROUPBYs
About PowerShow.com