Presentation is loading. Please wait.

Presentation is loading. Please wait.

Friday, September 4 th, 2009 The Systems Group at ETH Zurich XML and Databases Exercise Session 6 courtesy of Ghislain Fourny/ETH © Department of Computer.

Similar presentations


Presentation on theme: "Friday, September 4 th, 2009 The Systems Group at ETH Zurich XML and Databases Exercise Session 6 courtesy of Ghislain Fourny/ETH © Department of Computer."— Presentation transcript:

1 Friday, September 4 th, 2009 The Systems Group at ETH Zurich XML and Databases Exercise Session 6 courtesy of Ghislain Fourny/ETH © Department of Computer Science | ETH Zürich

2 Friday, September 4 th, 2009 PUL Algebra Theory Document Well- Formedness (Validation)Data ModelProcessing Previously, in XML&Databases 2 DTD XML Schema Infoset PSVI XDM All of this should be familiar to you by now. All of this should be familiar to you by now. XML with/without namespaces

3 Friday, September 4 th, 2009 PUL Algebra Theory Document Well- Formedness (Validation)Data ModelProcessing Previously, in XML&Databases 3 DTD XML Schema Infoset PSVI XDM So, now we can leverage the power of XML. XQuery XSLT XML with/without namespaces

4 Friday, September 4 th, 2009 PUL Algebra Theory Document Well- Formedness (Validation)Data ModelProcessing Previously, in XML&Databases 4 XML with namespaces (XML Schema) optional XDM This would be the typical setup. XQuery

5 Friday, September 4 th, 2009 PUL Algebra Theory Reminder: XML and Data Models 5 This is text. Physical view (syntax) Logical view (data model) a a d d This is c c b b.. text e:f

6 Friday, September 4 th, 2009 PUL Algebra Theory Reminder: XQuery and XPath Data Model 6 In XQuery, anything that goes into or comes out of an expression is a sequence of items! Expression for if then else where order by while any every let return exit with = +

7 Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 7

8 Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 8 if( ) then else

9 Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 9 if( ) then else my:func( )

10 Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 10 if( ) then else my:func( )

11 Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 11 if( ) then else my:func( ) 2

12 Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 12 if( ) then else for $x in let $y := return my:func( ) 2

13 Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 13 if( ) then else for $x in let $y := return my:func( ) 2

14 Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 14 if( ) then else for $x in let $y := return my:func( ) 2

15 Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 15 if( ) then else for $x in let $y := return my:func( ) 2

16 Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 16 if( ) then else for $x in let $y := return my:func( ) 2

17 Friday, September 4 th, 2009 PUL Algebra Theory XQuery Expressions 17 if( ) then else

18 Friday, September 4 th, 2009 PUL Algebra Theory XQuery Expressions 18 for $x in let $y := for $z in where order by return

19 Friday, September 4 th, 2009 PUL Algebra Theory XQuery Expressions 19 / / / /...

20 Friday, September 4 th, 2009 PUL Algebra Theory Precedence  Some expressions have priority over others while parsing an XQuery program:  Lowest priority: comma (,)  Then FLWOR, if/then/else,... on same level  Operators (+,...)  Path expressions (/)  Highest priority: literals, variables, function calls, element constructors...  Use parentheses when in doubt! 

21 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Simple queries 21

22 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Simple queries 22

23 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Titles sorted by price 23

24 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Titles sorted by price 24

25 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Titles sorted by price 25

26 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Titles sorted by price 26

27 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: How many books written by Abiteboul? 27

28 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: How many books written by Abiteboul? 28

29 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: How many books written by Abiteboul? 29

30 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: How many books written by Abiteboul? 30 2

31 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 31

32 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 32

33 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 33

34 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 34

35 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 35 Stevens Abiteboul Buneman Suciu

36 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 36 Stevens 2 Abiteboul 2 Buneman 1 Suciu 1

37 Friday, September 4 th, 2009 PUL Algebra Theory The document (from first exercise sheet) 37 You (should) know how namespaces work in XML (prefix-binding)

38 Friday, September 4 th, 2009 PUL Algebra Theory The document (from first exercise sheet) 38 How should we navigate a document which has namespaces with XQuery?

39 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: How prefixes are bound to namespaces in XQuery (Basics)  Very simple! Just a prolog declaration...  And then you can use the prefix in the XQuery code (e.g., in path expressions). 39

40 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: How prefixes are bound to namespaces in XQuery (Basics)  Very simple! Just a prolog declaration...  And then you can use the prefix in the XQuery code (e.g., in path expressions).  Actually, you can also bind them in element constructors just like in XML. 40

41 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 41

42 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 42

43 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 43

44 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 44

45 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 45

46 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 46

47 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 47

48 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 48

49 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 49

50 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 50

51 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 51

52 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 52

53 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 53

54 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 54

55 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 55

56 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 56

57 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: The other way 57

58 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Comparison Operators in XQuery 58

59 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Comparison Operators in XQuery  In XQuery, there are three kinds of comparisons  General Comparisons  Value Comparisons  Node Comparisons 59

60 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Comparison Operators in XQuery  In XQuery, there are three kinds of comparisons  General Comparisons =  Value Comparisons  Node Comparisons 60

61 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Comparison Operators in XQuery  In XQuery, there are three kinds of comparisons  General Comparisons =  Value Comparisons eq lt gt le ge  Node Comparisons 61

62 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Comparison Operators in XQuery  In XQuery, there are three kinds of comparisons  General Comparisons =  Value Comparisons eq lt gt le ge  Node Comparisons is 62

63 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node item which is atomized 63 In XQuery, if you receive a node item where an atomic item is expected, the node is atomized. =

64 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node which is atomized  Answers to the question: does any combination of  a value from the first sequence  and a value from the second sequence fulfil the condition? 64 = =

65 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node which is atomized  Answers to the question: does any combination of  a value from the first sequence  and a value from the second sequence fulfil the condition? (1,2) = (3, 1 ) 65 =

66 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node which is atomized  Answers to the question: does any combination of  a value from the first sequence  and a value from the second sequence fulfil the condition? (1,2) = (3, 1 ) 66 =

67 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node which is atomized  Answers to the question: does any combination of  a value from the first sequence  and a value from the second sequence fulfil the condition? (1,2) = (3, 1 ) (1,2) > (3,4) 67 =

68 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node which is atomized  Answers to the question: does any combination of  a value from the first sequence  and a value from the second sequence fulfil the condition? (1,2) = (3, 1 ) (1,2) > (3,4) 68 =

69 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Value Comparisons  Compares one value to one value (Empty sequence allowed) 69 le eq lt gt le ge

70 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Value Comparisons  Compares one value to one value (Empty sequence allowed) 32 eq xs:integer( 32 ) 70 eq lt gt le ge

71 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Value Comparisons  Compares one value to one value (Empty sequence allowed) 32 eq xs:integer( 32 ) 71 eq lt gt le ge

72 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Value Comparisons  Compares one value to one value (Empty sequence allowed) 32 eq xs:integer( 32 ) 31 gt xs:integer( 32 ) 72 eq lt gt le ge

73 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Value Comparisons  Compares one value to one value (Empty sequence allowed) 32 eq xs:integer( 32 ) 31 gt xs:integer( 32 ) 73 eq lt gt le ge

74 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Node Comparisons  Compares node identities 74 is

75 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Node Comparisons  Compares node identities let $a := let $b := $a return $a is $b 75 is

76 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Node Comparisons  Compares node identities let $a := let $b := $a return $a is $b 76 is

77 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Node Comparisons  Compares node identities let $a := let $b := $a return $a is $b let $a := let $b := return $a is $b 77 is

78 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Node Comparisons  Compares node identities let $a := let $b := $a return $a is $b let $a := let $b := return $a is $b 78 is

79 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General/Value comparisons 79

80 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General/Value comparisons  For both, values have to have comparable types (e.g., string is not comparable to integer) 80

81 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General/Value comparisons  For both, values have to have comparable types (e.g., string is not comparable to integer)  Empty sequence treated differently  General comparison returns false  Value comparison returns () 81

82 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General/Value comparisons  For both, values have to have comparable types (e.g., string is not comparable to integer)  Empty sequence treated differently  General comparison returns false  Value comparison returns ()  Untyped data treated differently  General comparison casts to type of other operand  Value comparison casts to string 82

83 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: 1=2  Find $x s.t. $x = 1 and $x = 2 83

84 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: 1=2  Find $x s.t. $x = 1 and $x = 2 84 (1,2)

85 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Transitivity of >  Find $x, $y, $z s.t. $x > $y and $y > $z and not $x > $z 85

86 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Transitivity of >  Find $x, $y, $z s.t. $x > $y and $y > $z and not $x > $z 86 $x := 2 $y := (1,4) $z := 3

87 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: $x eq $x, $x = $x  Find $x so that both $x eq $x and $x = $x are not true. 87

88 Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: $x eq $x, $x = $x  Find $x so that both $x eq $x and $x = $x are not true. 88 ()

89 Friday, September 4 th, 2009 PUL Algebra Theory 89 Hope to see you next week!


Download ppt "Friday, September 4 th, 2009 The Systems Group at ETH Zurich XML and Databases Exercise Session 6 courtesy of Ghislain Fourny/ETH © Department of Computer."

Similar presentations


Ads by Google