Query Languages
description
Transcript of Query Languages
![Page 1: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/1.jpg)
Query Languages
Aswin Yedlapalli
![Page 2: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/2.jpg)
XML Query data model
• Document is viewed as a labeled tree with nodes
• Successors of node may be : - an ordered sequence of nodes (eg.
for sub elements).- an unordered set of nodes (eg. For attributes).
• Compatible with XML schemas
![Page 3: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/3.jpg)
Comparison of XML and semi structured data
• Similarities:- both are best described by a labeled
graph.- both are schema-less self describing.
• Differences:- XML is ordered; semi structured
data is unordered.- XML can mix text and elements
![Page 4: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/4.jpg)
Required features for a Query Language
• Expressive power- The Query language must be at least as
expressive as SQL on relational data.- The Query language should have the
ability to restructure data.- The Query language should be able to
navigate data with arbitrary nesting.• Semantics
- It is very important in a query language for query transformation and optimization.
![Page 5: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/5.jpg)
• Compositionality
- Our queries must remain in the same data model. They cannot take data in one model and produce output in another model.
• Schema
- when structure is defined, a query language should be exploited for optimization, type checking etc.,
![Page 6: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/6.jpg)
Query languages
• For semi structured data- Lorel (Lightweight Object REpository Language)- UnQL (Unstructured Query Language)-StruQL, MSL, W3QL, WebSQL, Weblog, etc.,
• For XML- XML-QL (XML Query Language)- XSLT & structural recursion.- XML Query Algebra.
![Page 7: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/7.jpg)
Formal Semantics
• Given query Q = SELECT E[X1,……. Xn] FROM F WHERE Cand database DB
Answer: (Q,DB) is defined in two steps:
–Step 1: compute all bindings:
•Cij are node oids or atomic values
![Page 8: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/8.jpg)
•Must satisfy paths in F
•Must satisfy conditions in C
–Step 2: answer is E[C11, …, C1n] …
E[Cm1, …, Cmn]
![Page 9: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/9.jpg)
• When E has nested sub queries, apply semantics recursively
• Note: so far we have dealt with an unordered model
• –What do we need to do for order ?
• •Complexity: PTIME in |DB| (not in |Q|).
![Page 10: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/10.jpg)
LOREL
• Minor syntactic differences in regular pathexpressions (% instead of _, # instead of _*)
• Common path convention SELECT biblio.book.author
FROM biblio.bookWHERE biblio.book.year = 1999
![Page 11: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/11.jpg)
Becomes
SELECT X.author
FROM biblio.book X
WHERE X.year = 1999
![Page 12: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/12.jpg)
Lorel
• Query language of LORE system adapts OQL to semi structured data.
Select X.title
from bib.article X
where “tova milo” in X.author
returns {title: “type inf…”}
![Page 13: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/13.jpg)
Features of Lorel
• Differences with typed query languages- performs implicit coercions.- deals with missing attributes.- deals with set valued attributes.
eg., x.year > 1998 may have several years.
• Select clause creates new nodes.• Allows for nested queries.• Allows for regular path expressions.
![Page 14: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/14.jpg)
UnQL (Unstructured Query language)
• UnQL is an extension of basic LOREL.• UnQL does not make use of coercion unlike
LOREL.• “Where” clause contains 2 kinds of constructs.
- generators; variables are bound via patterns.
- conditions; as in LOREL• “from” clause is not needed as variables are bound
in patterns.
![Page 15: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/15.jpg)
UnQL Queries
• Eg., Select title:Twhere {bib:article:{title:T, year:Y}}in db,
y>1998.• Root of the database is explicitly represented: db• UnQL queries can be rewritten in LOREL.
The equivalent LOREL for the above query is: select title:Tfrom bib.article A, A.title T, A.year Y
where Y>1998.
![Page 16: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/16.jpg)
Additional features of LOREL
• Label variables
- can combine “schema” and “data” information.
- can turn tables to data and vice-versa.
- perform group-by operations.
• Can match variables with regular expressions.
![Page 17: Query Languages](https://reader036.fdocuments.in/reader036/viewer/2022072112/56813e7a550346895da8a344/html5/thumbnails/17.jpg)
References
• Managing XML and semi structured data – Lecture series by Prof. Dan Suciu.
• website:www.cs.washington.edu/homes/suciu/COURSES/590DS/