Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMPSCI 752

Big Data Management

Strategic Exercise 3

XQuery

Application domain. Consider the following XML document:

<?xml   version =”1.0”   encoding=”UTF−8”?>

<bib>

<book   year =”1994”>

< title >TCP/ IP  Illustrated </ title >

<author >

<last >Stevens </ last >

< first >W.</ first >

</author >

<publisher >Addison −Wesley </ publisher >

<price >65.95 </ price >

</book>

<book   year =”1992”>

< title >Advanced  Programming   in   the   Unix   environment </ title >

<author >

<last >Stevens </ last >

< first >W.</ first >

</author >

<publisher >Addison −Wesley </ publisher >

<price >65.95 </ price >

</book>

<book   year =”2000”>

< title >Data  on   the  Web</ title >

<author >

<last >A bite bou l </ last >

< first >Serge </ first >

</author >

<author >

<last >Buneman</ last >

< first >Peter </ first >

</author >

<author >

<last >Suciu </ last >

< first >Dan</ first >

</author >

<publisher >Morgan  Kaufmann   Publishers </ publisher >

<price >39.95 </ price >

</book>

<book   year =”1999”>

< title >The  Economics   of   Technology  and   Content   for   Digital  TV</ title > <editor >

<last >Gerbarg </ last >

< first >Darcy</ first >

< affiliation >CITI</ affiliation >

</ editor >

<publisher >Kluwer  Academic   Publishers </ publisher >

<price >129.95 </ price >

</book>

</bib>


Exercise 1 - XPath and Xquery.

Write the query “Return the names of all authors of books” in

a.   XPath

b.   XQuery

c.   and show the result when evaluated on the document above.

Exercise 2 - XPath and Xquery.

Write the query “Return the titles of all books published before 1997” in

a.   XPath

b.   XQuery

c.   and show the result when evaluated on the document above.

Exercise 3 - Construction.

a.   Write in XQuery ‘Return year and title of all books published before 1997’

b.   and show the result when evaluated on the document above.

Exercise 4 - Grouping.

a.   Write in XQuery ‘Return titles for each author’

b.   and show the result when evaluated on the document above.

Exercise 5 - Aggregation.

a.   Write in XQuery ‘Return the average length of authors’ surnames for each book’

b.   and show the result when evaluated on the document above.



Exercise 6 - Joins.

a.   Write in XQuery ‘Return pairs of books that share authors of the same name’ .

b.   and show the result when evaluated on the document above.

Exercise 7 - Quantification.

a.   Write in XQuery ‘Return the books where no author has a first name with less than three characters’

b.   and show the result when evaluated on the document above.

Exercise 8 - Grouping and Aggregation.

a.   Write in XQuery ‘Return titles for each author, provided there are at least two. ’

b.   and show the result when evaluated on the document above.

Exercise 9 - Interpreting and evaluating XQueries.

<bib>

{

for   $b   in   doc (” bib . xml ”)/ bib / book

where  $b/ publisher  =  ” Addison−Wesley ”  and  $b [ @year>  1 9 9 2 ] return

<book  year =”{  $b/@year  }” >

{ $b/ title }

</book>

}

</bib>

a.   What does the XQuery query above do?

b.   What is the result when evaluating the XQuery on the document above?


Exercise 10 - Interpreting and evaluating XQueries.

<results > {

for   $b $t $a

}

</results >

in   doc (” bib . xml”)/ bib /book ,

in   $b/ title  ,

in   $b/ author / last

return

<result >

{  $t   }

{  $a  }

</result >

a.   What does the XQuery query above do?

b.   What is the result when evaluating the XQuery on the document above?

Exercise 11 - Interpreting and evaluating XQueries.

<bib>

{

for   $b   in   doc (” bib . xml”)// book

where  $b/ publisher  =  ”Addison−Wesley”  and  $b/@year  >  ”1991” order  by  $b/ title

return  <book>  {  $b/@year  }  {  $b/ title   }  </book> }

</bib>

a.   What does the XQuery query above do?

b.   What is the result when evaluating the XQuery on the document above?