1 XQuery Values FLWR Expressions Other Expressions.

Slides:



Advertisements
Similar presentations
Advanced XSLT. Branching in XSLT XSLT is functional programming –The program evaluates a function –The function transforms one structure into another.
Advertisements

2/10/05Salman Azhar: Database Systems1 XML Query Languages Salman Azhar XPATH XQUERY These slides use some figures, definitions, and explanations from.
XML Data Management 8. XQuery Werner Nutt. Requirements for an XML Query Language David Maier, W3C XML Query Requirements: Closedness: output must be.
XML Examples. Bank Information Basic structure: A-101 Downtown 500 … Johnson Alma Surrey … A-101 Johnson …
1 Relational Algebra* and Tuple Calculus * The slides in this lecture are adapted from slides used in Standford's CS145 course.
1 Introduction to SQL Select-From-Where Statements Multirelation Queries Subqueries.
XML, XML Schema, Xpath and XQuery Slides collated from various sources, many from Dan Suciu at Univ. of Washington.
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.
1 XQuery Web and Database Management System. 2 XQuery XQuery is to XML what SQL is to database tables XQuery is designed to query XML data What is XQuery?
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.
From Semistructured Data to XML: Migrating The Lore Data Model and Query Language Roy Goldman, Jason McHugh, Jennifer Widom Stanford University
1 XPath Path Expressions Conditions. 2 Paths in XML Documents uXPath is a language for describing paths in XML documents. uReally think of the semistructured.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 357 Database Systems I Query Languages for XML.
1 COS 425: Database and Information Management Systems XML and information exchange.
Winter 2002Arthur Keller – CS 18018–1 Schedule Today: Mar. 12 (T) u Semistructured Data, XML, XQuery. u Read Sections Assignment 8 due. Mar. 14.
1 XML Document Type Definitions XML Schema. 2 Well-Formed and Valid XML uWell-Formed XML allows you to invent your own tags. uValid XML conforms to a.
Fall 2001Arthur Keller – CS 18017–1 Schedule Nov. 27 (T) Semistructured Data, XML. u Read Sections Assignment 8 due. Nov. 29 (TH) The Real World,
1 SQL/PSM Procedures Stored in the Database General-Purpose Programming.
1 XML Semistructured Data Extensible Markup Language Document Type Definitions.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
1 XML Query Languages XPATH XQUERY. 2 XPATH and XQUERY uXPATH is a language for describing paths in XML documents. wReally think of the semistructured.
Credit: Slides are an adaptation of slides from Jeffrey D. Ullman 1.
1 Query Languages for XML XPath XQuery XSLT. 2 The XPath/XQuery Data Model uCorresponding to the fundamental “relation” of the relational model is: sequence.
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
1 XML Semistructured Data Extensible Markup Language Document Type Definitions.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
XML Document Type Definitions XML Schema. Motivation for Semistructured data Serves as a model suitable for integration of databases Notations such as.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
XML Semi-structured data XML Document Type Definitions (DTD)
1 Lecture 5: XML and XQuery. 2 Semistructured Data uAnother data model, based on trees. uMotivation: flexible representation of data. wOften, data comes.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
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.
CSCE 520- Relational Data Model Lecture 2. Relational Data Model The following slides are reused by the permission of the author, J. Ullman, from the.
Document Type Definitions XML Schema
Advance Database S Week-7 Dr.Kwanchai Eurviriyanukul
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
Lecture 22 XML querying. 2 Example 31.5 – XQuery FLWOR Expressions ‘=’ operator is a general comparison operator. XQuery also defines value comparison.
Winter 2006Keller, Ullman, Cushing18–1 Plan 1.Information integration: important new application that motivates what follows. 2.Semistructured data: a.
XSLT part of XSL (Extensible Stylesheet Language) –includes also XPath and XSL Formatting Objects used to transform an XML document into: –another XML.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Nikos dimitrakas – IS4/2i1242/2i4042 spring XML Query Languages Database Systems (4th edition) Chapter 30.5, , Articles & Excerpts.
Unit 04 : XQuery COMP 5323 Web Database Technologies and Applications 2014.
1 XQuery uXQuery extends XPath to a query language that has power similar to SQL. uUses the same sequence-of-items data model. uXQuery is an expression.
Database Systems Part VII: XML Querying Software School of Hunan University
1 Real SQL Programming Persistent Stored Modules (PSM) PL/SQL Embedded SQL.
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.
1 Information Integration Mediators Warehousing Answering Queries Using Views Slides are modified from Dr. Ullman’s notes.
Jeff Ullman: Introduction to XML 1 XML Semistructured Data Extensible Markup Language Document Type Definitions.
Semistructured Data Extensible Markup Language Document Type Definitions Zaki Malik November 04, 2008.
Databases 1 Second lecture.
Exam II Syllabus uStorage & Buffer Management uIndexing: Btrees & Hash uMulti-dimensional Indexing uQuery processing (relational ops) uQuery optimization.
1 XML Data Management XPath Principles Werner Nutt.
CSCE 520- Relational Data Model Lecture 2. Oracle login Login from the linux lab or ssh to one of the linux servers using your cse username and password.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
1 Introduction to SQL Database Systems. 2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation.
XML Query Languages XPATH XQUERY Zaki Malik November 11, 2008.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
CSE 6331 © Leonidas Fegaras XQuery 1 XQuery Leonidas Fegaras.
XQUERY The contents of this slide are obtained from various sources including, Wikipedia, W3School, Stanford website etc. January 2011 Dr.Kwanchai Eurviriyanukul.
Query Languages for XML
Slides are reused by the approval of Jeffrey Ullman’s
Querying and Transforming XML Data
Introduction to Database Systems, CS420
Basic SQL Lecture 6 Fall
Basic Operations Algebra of Bags
XQuery Leonidas Fegaras.
Query Languages for XML
REPETITION Why Repetition?
Select-From-Where Statements Multirelation Queries Subqueries
Presentation transcript:

1 XQuery Values FLWR Expressions Other Expressions

2 XQuery uXQuery extends XPath to a query language that has power similar to SQL. uXQuery is an expression language. wLike relational algebra --- any XQuery expression can be an argument of any other XQuery expression. wUnlike RA, with the relation as the sole datatype, XQuery has a subtle type system.

3 The XQuery Type System 1.Atomic values : strings, integers, etc. uAlso, certain constructed values like true(), date(“ ”). 2.Nodes. uSeven kinds. uWe’ll only worry about four, on next slide.

4 Some Node Types 1.Element Nodes are like nodes of semistructured data. uDescribed by !ELEMENT declarations in DTD’s. 2.Attribute Nodes are attributes, described by !ATTLIST declarations in DTD’s. 3.Text Nodes = #PCDATA. 4.Document Nodes represent files.

5 Example Document … <BEER name = “Bud” soldBy = “JoesBar SuesBar … ”/> …

6 Example Nodes BARS PRICE BEERBAR name = “JoesBar” theBeer = “Miller” theBeer = “Bud” SoldBy = “…” name = “Bud” Green = element Gold = attribute Purple = text

7 Document Nodes uForm: document(“ ”). uEstablishes a document to which a query applies. uExample: document(“/usr/ullman/bars.xml”)

8 XQuery Values uItem = node or atomic value. uValue = ordered sequence of zero or more items. uExamples: 1.() = empty sequence. 2.(“Hello”, “World”) 3.(“Hello”, 2.50, 10)

9 Nesting of Sequences Ignored uA value can, in principle, be an item of another value. uBut nested list structures are expanded. uExample: ((1,2),(),(3,(4,5))) = (1,2,3,4,5) = 1,2,3,4,5. uImportant when values are computed by concatenating other values.

10 FLWR Expressions 1.One or more for and/or let clauses. 2.Then an optional where clause. 3.A return clause.

11 Semantics of FLWR Expressions uEach for creates a loop. wlet produces only a local definition. uAt each iteration of the nested loops, if any, evaluate the where clause. uIf the where clause returns TRUE, invoke the return clause, and append its value to the output.

12 FOR Clauses for in,... uVariables begin with $. uA for-variable takes on each item in the sequence denoted by the expression, in turn. uWhatever follows this for is executed once for each value of the variable.

13 Example: FOR for $beer in return {$beer} u$beer ranges over the name attributes of all beers in our example document. uResult is a list of tagged names, like Bud Miller... “Expand the en- closed string by replacing variables and path exps. by their values.”

14 LET Clauses let :=,... uValue of the variable becomes the sequence of items defined by the expression. uNote let does not cause iteration; for does.

15 Example: LET let $d := document(“bars.xml”) let $beers := return {$beers} uReturns one element with all the names of the beers, like: Bud Miller …

16 Following IDREF’s uXQuery (but not XPath) allows us to use paths that follow attributes that are IDREF’s. uIf x denotes a sequence of one or more IDREF’s, then x =>y denotes all the elements with tag y whose ID’s are one of these IDREF’s.

17 Example uFind all the beer elements where the beer is sold by Joe’s Bar for less than uStrategy: 1.$beer will for-loop over all beer elements. 2.For each $beer, let $joe be either the Joe’s- Bar element, if Joe sells the beer, or the empty sequence if not. 3.Test whether $joe sells the beer for < 3.00.

18 Example: The Query let $d := document(”bars.xml”) for $beer in $d/BARS/BEER let $joe := let $joePrice := where $joePrice < 3.00 return {$beer} Attribute soldBy is of type IDREFS. Follow each ref to a BAR and check if its name is Joe’s Bar. Find that PRICE subelement of the Joe’s Bar element that represents whatever beer is currently $beer. Only pass the values of $beer, $joe, $joePrice to the RETURN clause if the string inside the PRICE element $joePrice is < 3.00

19 Order-By Clauses uFLWR is really FLWOR: an order-by clause can precede the return. uForm: order by wWith optional ascending or descending. uThe expression is evaluated for each output element. uDetermines placement in output sequence.

20 Example: Order-By uList all prices for Bud, lowest first. let $d := document(“bars.xml”) for $p in order by $p return { $p }

21 Predicates uNormally, conditions imply existential quantification. uExample: means “all the bars that have a name.” uExample: = means “Joe and Sue have at least one price in common.”

22 Other Operators uUse Fortran comparison operators to compare atomic values only. weq, ne, gt, ge, lt, le. uArithmetic operators: +, -, *, div, idiv, mod. wApply to any expressions that yield arithmetic or date/time values.

23 Effective Boolean Values uThe effective boolean value (EBV) of an expression is: 1.The actual value if the expression is of type boolean. 2.FALSE if the expression evaluates to 0, “” [the empty string], or () [the empty sequence]. 3.TRUE otherwise.

24 EBV Examples has EBV TRUE or FALSE, depending on whether the name attribute is ”JoesBar”. has EBV TRUE if some bar is named the Golden Rail, and FALSE if there is no such bar.

25 Boolean Operators uE 1 and E 2, E 1 or E 2, not(E ), if (E 1 ) then E 2 else E 3 apply to any expressions. uTake EBV’s of the expressions first. uExample: not(3 eq 5 or 0) has value TRUE. uAlso: true() and false() are functions that return values TRUE and FALSE.

26 Quantifier Expressions some $x in E 1 satisfies E 2 1.Evaluate the sequence E 1. 2.Let $x (any variable) be each item in the sequence, and evaluate E 2. 3.Return TRUE if E 2 has EBV TRUE for at least one $x. uAnalogously: every $x in E 1 satisfies E 2

27 Document Order uComparison by document order: >. uExample: << is true iff the Bud element appears before the Miller element in the document $d.

28 Set Operators uunion, intersect, except operate on sequences of nodes. wMeanings analogous to SQL. wResult eliminates duplicates. wResult appears in document order.