Prologue to XQuery

Introduction to xquery l.jpg
1 / 30
0
0
1026 days ago, 351 views
PowerPoint PPT Presentation

Presentation Transcript

Slide 1

Prologue to XQuery Resources: Official URL: www.w3.org/TR/xquery Short introductions: http://www.xml.com/bar/a/2002/10/16/xquery.html www.brics.dk/~amoeller/XML/questioning Or see Ramakrishnan & Gehrke content Lecture adjusted from slides by Dan Suciu

Slide 2

{ push : { name : "John", telephone : 3634 }, push : { name : "Sue", telephone : 6343 }, push : { name : "Dick", telephone : 6363 } XML versus Social Data push telephone name "Sue" "John" 3634 6343 "Dick" 6363 Relation … in XML

Slide 3

Relational to XML Data A connection occasion is fundamentally a tree with: Unbounded fanout at level 1 (i.e., any # of columns) Fixed fanout at level 2 (i.e., settled # fields) XML information is basically a self-assertive tree Unbounded fanout at all hubs/levels Any number of levels Variable # of youngsters at various hubs, variable way lengths

Slide 4

Query Language for XML Must be abnormal state; "SQL for XML" Must adjust to XSchema But likewise work without mapping information Support straightforward and complex/settled datatypes Support general and existential quantifiers, accumulation Operations on groupings and chains of importance of doc structures Capability to change and make XML structures

Slide 5

XQuery Influenced by XML-QL, Lorel, Quilt, YATL Also, XPath and XML Schema Reads an arrangement of XML parts or nuclear values and returns a succession of XML sections or nuclear qualities Inputs/yields are items characterized by XML-Query information display, as opposed to strings in XML punctuation

Slide 6

Overview of XQuery Path expressions Element constructors FLWOR ("blossom") expressions Several different sorts of expressions too, including contingent expressions, list expressions, evaluated expressions, and so forth. Expressions assessed w.r.t. a unique situation: Context thing (current hub) Context position (in arrangement being prepared) Context size (of the grouping being handled) Context likewise incorporates namespaces, factors, capacities, date, and so forth

Slide 7

Path Expressions Examples: Bib/paper Bib/book/distributer Bib/paper/writer/lastname Given a XML archive, the estimation of a way expression p is an arrangement of items

Slide 8

Path Expression Examples Bib &o1 paper book Doc = references &o12 &o24 &o29 references writer page writer year writer title http title distributer writer &o43 &25 &o44 &o45 &o46 &o52 &96 1997 &o51 &o50 &o49 &o47 &o48 first last firstname lastname firstname &o70 &o71 &243 &206 "Serge" "Abiteboul" "Victor" 122 133 "Vianu" Bib/paper = < &o12 , &o29 > Bib/book/distributer = < &o51 > Bib/paper/writer/lastname = < &o71 , &206 > Note that request of components matters!

Slide 9

Element Construction A XQuery expression can build new values or structures Example: Consider the way expressions from the past slide. Each of them returns a recently developed grouping of components Key point is that we don't simply return existing structures or nuclear qualities; we can re-mastermind them as we wish into new structures

Slide 10

FLWOR Expressions FOR-LET-WHERE-ORDERBY-RETURN = FLWOR FOR/LET Clauses List of tuples WHERE Clause List of tuples ORDERBY/RETURN Clause Instance of XQuery information show

Slide 11

FOR versus LET FOR $x IN rundown expr Binds $x thusly to every esteem in the rundown expr LET $x = list-expr Binds $x to the whole rundown expr Useful for normal sub-expressions and for collections

Slide 12

FOR versus LET: Example Returns: <result> <book>...</book></result> <result> <book>...</book></result> <result> <book>...</book></result> ... FOR $x IN document("bib.xml")/tucker/book RETURN < result > $x </result > Notice that outcome has a few components Returns: <result> <book>...</book> <book>...</book> <book>...</book> ... </result> LET $x IN document("bib.xml")/face cloth/book RETURN < result > $x </result > Notice that outcome has precisely one component

Slide 13

XQuery Example 1 Find all book titles distributed after 1995: FOR $x IN document("bib.xml")/kiddie apron/book WHERE $x/year > 1995 RETURN $x/title Result: < title > abc </title > < title > def </title > < title > ghi </title >

Slide 14

XQuery Example 2 For every writer of a book by Morgan Kaufmann, list all books she distributed: FOR $a IN particular ( document("bib.xml")/napkin/book [ distributer ="Morgan Kaufmann"]/writer ) RETURN < result > $a, FOR $t IN/face cloth/book [ writer = $a ]/title RETURN $t </result > unmistakable = a capacity that dispenses with copies (in the wake of changing over contributions to nuclear qualities)

Slide 15

Results for Example 2 < result > < writer >Jones</writer > < title > abc </title > < title > def </title > </result > < result > < writer > Smith </writer > < title > ghi </title > </result> Observe how settled structure of result components is controlled by the settled structure of the inquiry.

Slide 16

XQuery Example 3 < big_publishers > FOR $p IN unmistakable (document("bib.xml")//distributer ) LET $b := document("bib.xml")/book [ distributer = $p ] WHERE tally ( $b ) > 100 RETURN $p </big_publishers > For every distributer p Let the rundown of books distributed by p be b Count the # books in b, and return p if b > 100 check = (total) work that profits the quantity of components

Slide 17

XQuery Example 4 Find books whose cost is bigger than normal: LET $a = avg ( document("bib.xml")/face cloth/book/cost ) FOR $b in document("bib.xml")/kiddie apron/book WHERE $b/cost > $a RETURN $b

Slide 18

Collections in XQuery Ordered and unordered accumulations/napkin/book/writer = a requested gathering Distinct(/tucker/book/writer ) = an unordered accumulation Examples: LET $a =/face cloth/book ��  $a is a gathering; stmt repeats over all books in collecion $b/writer ��  additionally an accumulation (a few authors...) Returns a solitary accumulation! < result > < creator >...</creator > < creator >...</creator > < creator >...</creator > ... </result > However: RETURN < result > $b/creator </result >

Slide 19

Collections in XQuery What about accumulations in expressions ? $b/cost ��  rundown of n costs $b/cost * 0.7 ��  rundown of n numbers?? $b/cost * $b/amount ��  rundown of n x m numbers ?? Legitimate just if the two arrangements have at most one component Atomization $book1/writer eq "Kennedy" - Value Comparison $book1/writer = "Kennedy" - General Comparison

Slide 20

Sorting in XQuery < publisher_list > FOR $p IN unmistakable (document("bib.xml")//distributer ) ORDERBY $p RETURN < distributer > < name > $p/content() </name > , FOR $b IN document("bib.xml")//book [ distributer = $p ] ORDERBY $b/cost DESCENDING RETURN < book > $b/title , $b/cost </book > </distributer > </publisher_list >

Slide 21

Conditional Expressions: If-Then-Else FOR $h IN/holding ORDERBY $h/title RETURN < holding > $h/title , IF $h/@type = "Journal" THEN $h/proofreader ELSE $h/writer </holding >

Slide 22

Existential Quantifiers FOR $b IN/book WHERE SOME $p IN $b/para SATISFIES contains( $p , "sailing") AND contains( $p , "windsurfing") RETURN $b/title

Slide 23

Universal Quantifiers FOR $b IN/book WHERE EVERY $p IN $b/para SATISFIES contains( $p , "sailing") RETURN $b/title

Slide 24

Other Stuff in XQuery Before and After for managing request in the information Filter erases a few edges in the outcome tree Recursive capacities Namespaces References, joins … Lots more stuff …

Slide 25

Appendix XML Schema and XQuery Data Model

Slide 26

XML Schema Includes primitive information sorts (whole numbers, strings, dates, and so on.) Supports esteem based limitations (whole numbers > 100) User-perceptible organized sorts Inheritance (augmentation or confinement) Foreign keys Element-sort reference requirements

Slide 27

Sample XML Schema <schema version="1.0" xmlns="http://www.w3.org/1999/XMLSchema"> <element name=" writer " type="string"/> <element name=" date " sort = "date"/> <element name=" theoretical" > <type> … </type> </element> <element name=" paper "> <type> <attribute name=" catchphrases " type="string"/> <element ref=" writer " minOccurs="0" maxOccurs="*"/> <element ref=" date "/> <element ref=" unique " minOccurs="0" maxOccurs="1"/> <element ref=" body "/> </type> </element> </schema>

Slide 28

XML-Query Data Model Describes XML information as a tree Node ::= DocNode | ElemNode | ValueNode | AttrNode | NSNode | PINode | CommentNode | InfoItemNode | RefNode http://www.w3.org/TR/inquiry datamodel/2/2001

Slide 29

XML-Query Data Model Element hub (rearranged definition): elemNode : ( QNameValue , { AttrNode },

SPONSORS