pre discussion xquery an xml query
play

Pre-Discussion XQuery: An XML Query After the presentation, we will - PDF document

Pre-Discussion XQuery: An XML Query After the presentation, we will evaluate XQuery. During the presentation, think Language about consequences of the design decisions on the usability of the language. D. Chamberlin Outline 1. The story, in


  1. Pre-Discussion XQuery: An XML Query After the presentation, we will evaluate XQuery. During the presentation, think Language about consequences of the design decisions on the usability of the language. D. Chamberlin Outline 1. The story, in brief is… 1. The story, in brief is… • XQuery : XML :: SQL : relational tables 2. XQuery’s design is influenced by: 1. XML data • Intended as a ‘standard’ way to query ‘different’ XML data sources 2. Pre-existing standards and languages 3. The vision behind XQuery, it’s intended use • Declarative, Uses expressions to assemble 3. XQuery, the language queries and results 4. Current affairs • A number of factors influenced XQuery XML vs. Relational Data Other query languages • Relational Data • Constrained by existing standards ( XML Schema, XPath) – Flat Structure – Optimized for efficient access and retrieval • Influenced by other languages • XML – XSLT, Quilt etc. – Hierarchical Structure • Each of these were good for a niche area – Optimized for representing intrinsic relationships of • XPath data that make up an XML document – Cannot create new XML, introduce variables or • Implications for query language design namespaces, select part of nodes etc. • Path Expressions • XSLT ( styling XML for display formats ) • FLWOR Expressions – Joins, querying etc…can be difficult to do (debatable!) • Case sensitive, 1

  2. Other query languages The vision • XQuery • Data Integration – Joins and Sorts – Built by people from the db and SQL community – Manipulating Sequences of Values – XML Schema included (allows validation) – User defined functions easy to write (even with recursion) • Designed to support query processing – Create temporary results and navigate them – Procedural query processing – Restructure using FLWOR expressions • User defined functions • FLWOR expressions – Element Constructors for temporary results Outline Data Model 1. The story, in brief is… • Abstract representation for XML docs 2. XQuery’s design is influenced by: • Based on the notion of sequences of 1. XML data nodes or atomic values 2. Pre-existing languages • Nodes form hierarchies to represent 3. The vision behind XQuery, it’s intended use relationships implicitly 3. XQuery, the language • Document order is important 1. Data Model 2. Query Processing Steps 3. Language Features items.xml 1. Data Model <item status = “available”> <itemno>0021</itemno> <description>Scooter</description> <seller>Vespa</seller> <reserve-price>12000</reserve- price> </item> 2

  3. 2. Query Processing Steps 3. Language Features • Path Expressions • Predicates Query Data Model XML DOC • FLWOR Schema validation • Functions Query • Type System XML Representation Query Results Serialization Language Features Language Features • Path Expressions to navigate through elements in an • Predicates to filter a sequence of values XML document • Based on XPath syntax • Often used in the steps of a path • Series of steps separated by ‘/’ • Each step returns a sequence of nodes expression • The last sequence is the value of the Expression item[seller = “Vespa”] • doc(“items.xml")/ • Evaluated on each item of the sequence child::*/ – seller = “Vespa” used to select some item nodes and child::item[child::seller = “Vespa”]/ discard others child::description FLWOR FLWR for $i in doc(“items.xml”)/*/item • Iteration over sequences of values let $b := doc(“bids.xml”) • FLWOR /*/bid[itemno = $i/itemno] – for, let , when, order-by, return where count ($b) > 10 • Adopted from Quilt return • For each item that has more than ten bids, <popular-item> generate a popular-item element containing { item-description (pg: 606) $i/description } </popular-item> 3

  4. Functions Type System • Functions • Based on the Type System of XML Schema – Libraries as well as User defined – Recursion supported • Queries need to refer to types sometimes define function depth( element $e) – Can use qualified name, generic keywords returns integer • Occurrence indicators { – Element of type order+ … • Dynamic type information: typeswitch } • Typecasting available: cast, treat and depth(doc(“bids.xml”)) assert Outline Current affairs 1. The story, in brief is… • Supported by all major vendors 2. XQuery’s design is influenced by: – IBM, Oracle, Microsoft etc 1. XML data – XQuery code should work across vendors 2. Pre-existing languages • Compatible with several W3C standards 3. The vision behind XQuery, it’s inteded use 3. XQuery, the language – XML, Namespaces, XSLT, XPath, and XML Schema. 4. Current affairs • XQuery 1.0 is still a working draft Discussion: Evaluating XQuery For and Return Full-class discussion: How would you evaluate • for and return XQuery? variable • As a query language, how does it compare to for $m in (2,3), $n in (5,10) Comma operator SQL? return <fact> {m} times {n} is • What are your general feelings about usability? {$m * $n} </fact> Element constructor • When would you use it? • When would you prefer something else like XML-QL or XSLT (or even mapping XML to relational and using SQL)? 4

  5. For and Return Let • for and return • Let for $i in (1 to 3) for $m in (2,3), $n in (5,10) let $j := (1 to $i) return <fact> {m} times {n} is {$m * $n} </fact> $i = 1, $j = 1 RESULT $i = 2, $j = (1, 2) <fact> 2 times 5 is 10 </fact> $i = 3, $j = (1, 2, 3) <fact> 2 times 10 is 20 </fact> <fact> 3 times 5 is 15 </fact> <fact> 3 times 10 is 30 </fact> 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend