A Quilt, not a Camel Don Chamberlin Jonathan Robie Daniela Florescu May 19, 2000.

Slides:



Advertisements
Similar presentations
XML Data Management 8. XQuery Werner Nutt. Requirements for an XML Query Language David Maier, W3C XML Query Requirements: Closedness: output must be.
Advertisements

Web Data Management XQuery 1. In this lecture Summary of XQuery FLWOR expressions – For, Let, Where, Order by, Return FOR and LET expressions Collections.
XML May 3 rd, XQuery Based on Quilt (which is based on XML-QL) Check out the W3C web site for the latest. XML Query data model –Ordered !
XML, XML Schema, Xpath and XQuery Slides collated from various sources, many from Dan Suciu at Univ. of Washington.
TIMBER A Native XML Database Xiali He The Overview of the TIMBER System in University of Michigan.
XQuery Or, what about REAL databases?. XQuery - its place in the XML team XLink XSLT XQuery XPath XPointer.
XQUERY. What is XQuery? XQuery is the language for querying XML data The best way to explain XQuery is to say that XQuery is to XML what SQL is to database.
Database Management Systems, R. Ramakrishnan1 Introduction to Semistructured Data and XML Chapter 27, Part D Based on slides by Dan Suciu University of.
1 Part 3: Query Languages Managing XML and Semistructured Data.
Managing XML and Semistructured Data Lecture 8: Query Languages - XML-QL Prof. Dan Suciu Spring 2001.
Querying XML (cont.). Comments on XPath? What’s good about it? What can’t it do that you want it to do? How does it compare, say, to SQL?
IS432: Semi-Structured Data Dr. Azeddine Chikh. 7. XQuery.
1 Lecture 12: XQuery in SQL Server Monday, October 23, 2006.
A Graphical Environment to Query XML Data with XQuery
Query Languages Aswin Yedlapalli. XML Query data model Document is viewed as a labeled tree with nodes Successors of node may be : - an ordered sequence.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 357 Database Systems I Query Languages for XML.
XQL (XML Query Language) Jonathan Robie (Software AG) Eduard Derksen (CSCIO) Peter Fankhauser (GMD-IPSI) Ed Howland (DEGA) Gerald Huck (GMD-IPSI) Ingo.
XQuery language Presented by: Tayeb sbihi supervised by: Dr. H. Haddouti.
1 COS 425: Database and Information Management Systems XML and information exchange.
Query Languages - XQuery Slides partially from Dan Suciu.
XML May 1 st, XML for Representing Data John 3634 Sue 6343 Dick 6363 John 3634 Sue 6343 Dick 6363 row name phone “John”3634“Sue”“Dick” persons.
SDPL 2001Notes 8.2: XQuery1 8.2 W3C XML Query Language –Thanks for Helena Ahonen-Myka (University of Helsinki) for borrowing her slide originals for this.
XQuery – The W3C XML Query Language Jonathan Robie, Software AG Don Chamberlin, IBM Research Daniela Florescu, INRIA.
XML QUERY LANGUAGE Prepared by Prof. Zaniolo, Hung-chih Yang, Ling-Jyh Chen Modified by Fernando Farfán.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
XML, XML Schema, XPath and XQuery Query Languages CS561 Slides collated from several sources, including D. Suciu at Univ. of Washington.
Xpath to XQuery February 23rd, Other Stuff HW 3 is out. Instructions for Phase 3 are out. Today: finish Xpath, start and finish Xquery. From Wednesday:
Querying XML February 12 th, Querying XML Data XPath = simple navigation through the tree XQuery = the SQL of XML XSLT = recursive traversal –will.
Processing of structured documents Spring 2003, Part 8 Helena Ahonen-Myka.
Advisor: Prof. Zaniolo Hung-chih Yang Ling-Jyh Chen XML Query Language.
Xquery. Summary of XQuery FLWR expressions FOR and LET expressions Collections and sorting Resource W3C recommendation:
Lecture 21 XML querying. 2 XSL (eXtensible Stylesheet Language) In HTML, default styling is built into browsers as tag set for HTML is predefined and.
Introduction to XQuery Resources: Official URL: Short intros:
XML-QL A Query Language for XML Charuta Nakhe
SDPL 20067: Querying XML with XQuery1 7 Querying XML n How to access data sources as XML? n XQuery, W3C XML Query Language –Candidate Rec, November 2005.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XQuery.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XQuery.
End of XML February 19 th, FLWR (“Flower”) Expressions FOR... LET... WHERE... RETURN... FOR... LET... WHERE... RETURN...
Introduction to XQuery Bun Yue Professor, CS/CIS UHCL.
Processing of structured documents Spring 2003, Part 7 Helena Ahonen-Myka.
XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000.
XPath. Why XPath? Common syntax, semantics for [XSLT] [XPointer][XSLT] [XPointer] Used to address parts of an XML document Provides basic facilities for.
Processing of structured documents. XML Query language zW3C : working drafts yA Data model yXML Query Algebra yXQuery: A Query Language for XML.
Database Systems Part VII: XML Querying Software School of Hunan University
SDPL 2002Notes 9: XQuery1 9 Querying XML Data and Documents n XQuery, W3C XML Query Language –"work in progress", Working Draft, 30 April 2002 –joint work.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
XML query. introduction An XML document can represent almost anything, and users of an XML query language expect it to perform useful queries on whatever.
SDPL 20077: Querying XML with XQuery1 7 Querying XML n How to access XML data sources? n XQuery, XML Query Lang, W3C Rec, 01/ '07 –joint work by XML Query.
1 XML Data Management XPath Principles Werner Nutt.
CBU 2007XQuery and XPath1 W3C XML Query n How to access various XML data sources? n XQuery, XML Query Lang, W3C Rec, Jan '07 –joint work by XML Query and.
XML May 6th, Instructor AnHai Doan Brief bio –high school in Vietnam & undergrad in Hungary –M.S. at Wisconsin –Ph.D. at Washington under Alon &
IS432 Semi-Structured Data Lecture 6: XQuery Dr. Gamal Al-Shorbagy.
19 th International Unicode Conference San Jose, CA September W3C XML Query Paul Cotton, Microsoft 19 th Unicode Conference Sept 12, 2001.
CSE 6331 © Leonidas Fegaras XQuery 1 XQuery Leonidas Fegaras.
Processing of structured documents Part 6. 2 XML Query language zW3C : working drafts yA data model (XQuery 1.0 and XPath 2.0) yXQuery 1.0 Formal.
XQuery 1. In this lecture Summary of XQuery FLWOR expressions – For, Let, Where, Order by, Return FOR and LET expressions Collections and sorting 2.
Lecture 17: XPath and XQuery Wednesday, Nov. 7, 2001.
1 CSE544: Lecture 7 XQuery, Relational Algebra Monday, 4/22/02.
SDPL 2005Notes 7: XQuery1 7 Querying XML n How to access different sources (DBs, docs) as XML? n XQuery, W3C XML Query Language –"work in progress", (last.
1 Relational Algebra and SQL. 2 Relational Query Languages Languages for describing queries on a relational database Relational AlgebraRelational Algebra.
Querying and Transforming XML Data
8 Querying XML How to access different sources (DBs, docs) as XML?
Querying XML and Semistructured Data
Universal Database Systems
Lecture 12: XML, XPath, XQuery
Introduction to Database Systems CSE 444 Lecture 12 More Xquery and Xquery in SQL Server April 25, 2008.
Alin Deutsch, University of Pennsylvania Mary Mernandez, AT&T Labs
XQuery Leonidas Fegaras.
Lecture 12: XQuery in SQL Server
Introduction to Database Systems CSE 444 Lecture 12 Xquery in SQL Server October 22, 2007.
Presentation transcript:

A Quilt, not a Camel Don Chamberlin Jonathan Robie Daniela Florescu May 19, 2000

2 The Web Changes Everything l All kinds of information can be made available everywhere, all the time l XML is the leading candidate for a universal language for information interchange l To realize its potential, XML needs a query language of comparable flexibility l Several XML query languages have been proposed and/or implemented l XPath, XQL, XML-QL, Lorel, YATL l Most are oriented toward a particular domain such as semi-structured documents or databases

3 Goals of the Quilt Proposal l Leverage the most effective features of several existing and proposed query languages l Design a small, clean, implementable language l Cover the functionality required by all the XML Query use cases in a single language l Write queries that fit on a slide l Design a quilt, not a camel l "Quilt" refers both to the origin of the language and to its intended use in knitting together heterogeneous data sources

4 Antecedents: XPath and XQL l Closely-related languages for navigating in a hierarchy l A path expression is a series of steps l Each step moves along an axis (children, ancestors, attributes, etc.) and may apply a predicate l XPath has a well-defined abbreviated syntax: /book[title = "War and Peace"] /chapter[title = "War"] //figure[contains(caption, "Korea")] l XQL adds some operators: BEFORE, AFTER,...

5 Antecedent: XML-QL l Proposed by Alin Deutsch, Mary Fernandez, Daniela Florescu, Alon Levy, Dan Suciu l WHERE-clause binds variables according to a pattern, CONSTRUCT-clause generates output document WHERE $pname in "parts.xml", $sname in "supp.xml", in "sp.xml" CONSTRUCT $pname $sname

6 Antecedents: SQL and OQL l SQL and OQL are database query languages l SQL derives a table from other tables by a stylized series of clauses: SELECT - FROM - WHERE l OQL is a functional language l A query is an expression l Expressions can take several forms l Expressions can be nested and combined l SELECT-FROM-WHERE is one form of OQL expression

7 A First Look at Quilt l "Find the description and average price of each red part that has at least 10 orders" FOR $p IN document("parts.xml") //part[color = "Red"]/partno LET $o := document("orders.xml") //order[partno = $p] WHERE count($o) >= 10 RETURN $p/description, avg($o/price)

8 Quilt Expressions l Like OQL, Quilt is a functional language (a query is an expression, and expressions can be composed.) l Some types of Quilt expressions: l A path expression (using abbreviated XPath syntax): document("bids.xml")//bid[itemno="47"]/bid_amount l An expression using operators and functions: ($x + $y) * foo($z) l An element constructor: $u, $a l A "FLWR" expression

9 A FLWR Expression FOR_clause LET_clause WHERE_clause RETURN_clause FOR... LET... WHERE... RETURN l A FLWR expression binds some variables, applies a predicate, and constructs a new result.

10 FOR Clause l Each expression evaluates to a collection of nodes l The FOR clause produces many binding-tuples from the Cartesian product of these collections l In each tuple, the value of each variable is one node and its descendants. l The order of the tuples preserves document order unless some expression contains a non-order-preserving function such as distinct( ). FOR variable IN expression,

11 LET Clause l A LET clause produces one binding for each variable (therefore the LET clause does not affect the number of binding-tuples) l The variable is bound to the value of expression, which may contain many nodes. l Document order is preserved among the nodes in each bound collection, unless expression contains a non-order-preserving function such as distinct( ). LET, variable := expression

12 WHERE Clause l Applies a predicate to the tuples of bound variables l Retains only tuples that satisfy the predicate l Preserves order of tuples, if any l May contain AND, OR, NOT l Applies scalar conditions to scalar variables: $color = "Red" l Applies set conditions to variables bound to sets: avg($emp/salary) > WHERE boolean-expression

13 RETURN Clause l Constructs the result of the FLWR expression l Executed once for each tuple of bound variables l Preserves order of tuples, if any,... l OR, can impose a new order using a SORTBY clause l Often uses an element constructor: $item/itemno, avg($b/bid_amount) SORTBY itemno RETURN expression

14 Summary of FLWR Data Flow RETURN WHERE FOR/LET List of tuples of bound variables List of tuples of bound variables XML XML = ordered forest of nodes ($x = value, $y = value, $z = value), ($x = value, $y = value, $z = value)

15 Simple Quilt queries l "Find all the books published in 1998 by Penguin" FOR $b IN document("bib.xml")//book WHERE $b/year = "1998" AND $b/publisher = "Penguin" RETURN $b SORTBY(author, title) l "Find titles of books that have no authors" FOR $b IN document("bib.xml")//book WHERE empty($b/author) RETURN $b/title SORTBY(.)

16 Nested queries l "Invert the hierarchy from publishers inside books to books inside publishers" FOR $p IN distinct(//publisher) RETURN $p/text(), FOR $b IN //book[publisher = $p] RETURN $b/title, $b/price SORTBY(price DESCENDING) SORTBY(name)

17 Operators based on global ordering l Returns nodes in expr1 that are before (after) some node in expr2 l "Find procedures where no anesthesia occurs before the first incision." FOR $proc IN //section[title="Procedure"] WHERE empty( $proc//anesthesia BEFORE ($proc//incision)[1] ) RETURN $proc expr1expr2 BEFORE AFTER

18 The FILTER Operator expression FILTER path-expression l Returns the result of the first expression, "filtered" by the second expression l Result is an "ordered forest" that preserves sequence and hierarchy. A A A B B B C C C C A B C C C CAB A B B B A A A B A B LET $x := /C $x FILTER //A | //B

19 Projection (Filtering a document) l "Generate a table of contents containing nested sections and their titles" document("cookbook.xml") FILTER //section | //section/title | //section/title/text()

20 Conditional Expressions l "Make a list of holdings, ordered by title. For journals, include the editor; otherwise include the author." FOR $h IN //holding RETURN $h/title, IF = "Journal" THEN $h/editor ELSE $h/author SORTBY(title) IF expr1 THEN expr2 ELSE expr3

21 Functions l A query can define its own local functions If f is a scalar function, f(S) is defined as { f(s): s c S } l Functions can be recursive l "Compute the maximum depth of nested parts in the document named partlist.xml" FUNCTION depth($e) { IF empty($e/*) THEN 0 ELSE max(depth($e/*)) + 1 } depth(document("partlist.xml") FILTER //part)

22 Quantified Expressions l Quantified expressions are a form of predicate (return Boolean) l "Find titles of books in which both sailing and windsurfing are mentioned in the same paragraph" FOR $b IN //book WHERE SOME $p IN $b//para SATISFIES contains($p, "Sailing") AND contains($p, "Windsurfing") RETURN $b/title var IN expr SATISFIES predicate SOME EVERY

23 Variable Bindings l "For each book that is more expensive than average, list the title and the amount by which the book's price exceeds the average price" LET $a := avg(//book//price) EVAL FOR $b IN //book WHERE $b/price > $a RETURN $b/title, $b/price - $a LET variable := expression EVAL expression

24 Relational Queries PNO DESCRIP PARTS SNO SNAME SUPPLIERS SNO PNO PRICE CATALOG l Tables can be represented by simple XML trees l Table = root l Each row becomes a nested element l Each data value becomes a further nested element

25 SQL vs. Quilt l SQL: SELECT pno, descrip FROM parts AS p WHERE descrip LIKE 'Gear' ORDER BY pno; l Quilt: FOR $p IN document("parts.xml")//p_tuple WHERE contains($p/descrip, "Gear") RETURN $p/pno SORTBY(.) "Find part numbers of gears, in numeric order"

26 GROUP BY and HAVING l SQL: SELECT pno, avg(price) AS avg_price FROM catalog AS c GROUP BY pno HAVING count(*) >= 3 ORDER BY pno; l Quilt: FOR $p IN distinct(document("parts.xml")//pno) LET $c := document("catalog.xml") //c_tuple[pno = $p] WHERE count($c) >= 3 RETURN $p, avg($c/price) SORTBY(pno) "Find part no's and avg. prices for parts with 3 or more suppliers"

27 Inner Join "Return a 'flat' list of supplier names and their part descriptions" l Quilt: FOR $c IN document("catalog.xml")//c_tuple, $p IN document("parts.xml") //p_tuple[pno = $c.pno], $s IN document("suppliers.xml") //s_tuple[sno = $c.sno] RETURN $s/sname, $p/descrip SORTBY(sname, descrip)

28 Outer Join l Quilt: FOR $s IN document("suppliers.xml")//s_tuple RETURN $s/sname, FOR $c IN document("catalog.xml") //c_tuple[sno = $s/sno], $p IN document("parts.xml") //p_tuple[pno = $c/pno] RETURN $p/descrip SORTBY(.) SORTBY(sname) "List names of all suppliers in alphabetic order; within each supplier, list the descriptions of parts it supplies (if any)"

29 Defining XML Views of Relations l Use an SQL query to define the data you want to extract (in tabular form) l Use a simple default mapping from tables to XML trees l Use a Quilt query to compose the XML trees into a view with any desired structure l Quilt queries against the view are composed with the Quilt query that defines the view

30 Quilt grammar (1) l Queries and Functions: query ::= function_defn* expr function_defn ::= 'FUNCTION' function_name '(' variable_list ')' '{' expr '}' l Example of a function definition: FUNCTION spouse_age($x) { $x/spouse/age } l Functions: l Core XML Query Language library: avg, contains, empty,... l domain-dependent library: eg. area of a polygon l local functions: eg. spouse_age($x)

31 Quilt grammar (2) l Expressions: expr ::= variable | constant | expr infix_operator expr | prefix_operator expr | function_name '(' expr_list? ')' | '(' expr ')' | expr '[' expr ']' | 'IF' expr 'THEN' expr 'ELSE' expr | 'LET' variable ':=' expr 'EVAL' expr l Infix operators: + - * div mod = >= != | AND OR NOT UNION INTERSECT EXCEPT BEFORE AFTER Prefix operators: + - NOT

32 Quilt grammar (3) l Expressions, continued: expr ::= path_expression | element_constructor | FLWR_expression element_constructor ::= start_tag expr_list? end_tag start_tag ::= ' ' attributes ::= ( attr_name '=' expr )+ | 'ATTRIBUTES' expr ::= ' ' ::= QName | variable ::= QName | variable

33 Quilt grammar (4) l FLWR_Expressions: FLWR_expression ::= for_clause ( for_clause | let_clause )* where_clause? return_clause for_clause ::= 'FOR' variable 'IN' expr (',' variable 'IN' expr)* let_clause ::= 'LET' variable ':=' expr (',' variable ':=' expr)* where_clause ::= 'WHERE' expr return_clause ::= 'RETURN' expr

34 Quilt grammar (5) l Second-order expressions: expr ::= expr 'FILTER' path_expression | quantifier variable 'IN' expr 'SATISFIES' expr | expr 'SORTBY' '(' expr order?,... ')' quantifier ::= 'SOME' | 'EVERY' order ::= 'ASCENDING' | 'DESCENDING'

35 Comments on the Grammar l In general the correctness of a program/query is enforced by: l Syntactic rules (e.g. grammar) l Semantic rules (e.g. variable and function scope) l Type checking rules (e.g. the expression in the WHERE clause must be of type Boolean) l The Quilt grammar is quite permissive l It deals with only the first of the above items l The Quilt grammar is just a beginning. Still to come: l Core function library l Type checking rules l Formal semantic specification

36 Summary l XML is very versatile markup language l Quilt is a query language designed to be as versatile as XML l Quilt draws features from several other languages l Quilt can pull together data from heterogeneous sources l Quilt can help XML to realize its potential as a universal language for data interchange