Static Typing in XQuery Mary Fernández, Jérôme Siméon, Philip Wadler Επιμέλεια Παρουσίασης: Μαγδαληνός Παναγής.

Slides:



Advertisements
Similar presentations
CS3012: Formal Languages and Compilers Static Analysis the last of the analysis phases of compilation type checking - is an operator applied to an incompatible.
Advertisements

XML Data Management 8. XQuery Werner Nutt. Requirements for an XML Query Language David Maier, W3C XML Query Requirements: Closedness: output must be.
Querying on the Web: XQuery, RDQL, SparQL Semantic Web - Spring 2006 Computer Engineering Department Sharif University of Technology.
XML Examples. Bank Information Basic structure: A-101 Downtown 500 … Johnson Alma Surrey … A-101 Johnson …
XML: Extensible Markup Language
Semantics Static semantics Dynamic semantics attribute grammars
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
Overview of Previous Lesson(s) Over View  Front end analyzes a source program and creates an intermediate representation from which the back end generates.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
1 XML DTD & XML Schema Monica Farrow G30
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
COEN Expressions and Assignment
Type Checking.
Compiler Construction
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.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
XQuery from the Experts Chapter 5 – Introduction to the formal Semantics Νίκος Λούτας.
Lecture 14 XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name.
Static Typing in XQuery Based on Xquery from the Experts [Katz], chap 4 Presented by Iris Rudner.
More XML XML schema, XPATH, XSLT CS 431 – February 21, 2005 Carl Lagoze – Cornell University acknowledgements to
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
1 Types Object Oriented Programming Spring 2007.
Programming Languages 2nd edition Tucker and Noonan Chapter 6 Types I was eventually persuaded of the need to design programming notations so as to maximize.
XML Schema Describing the structure of XML documents. A very brief introduction 1XML Schema.
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.
Lecture 15 XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name.
1/151/15 ENT Metamodel Implementation & Applications ENT metamodel, prototype implementation Component substitutability checking, ENT based component comparison.
XML Schema Vinod Kumar Kayartaya. What is XML Schema?  XML Schema is an XML based alternative to DTD  An XML schema describes the structure of an XML.
1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006.
An Introduction to XML Presented by Scott Nemec at the UniForum Chicago meeting on 7/25/2006.
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
Lecture 22 XML querying. 2 Example 31.5 – XQuery FLWOR Expressions ‘=’ operator is a general comparison operator. XQuery also defines value comparison.
3-1 Chapter 3: Describing Syntax and Semantics Introduction Terminology Formal Methods of Describing Syntax Attribute Grammars – Static Semantics Describing.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Optimization in XSLT and XQuery Michael Kay. 2 Challenges XSLT/XQuery are high-level declarative languages: performance depends on good optimization Performance.
410/510 1 of 18 Week 5 – Lecture 1 Semantic Analysis Compiler Construction.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
Looping and Counting Lecture 3 Hartmut Kaiser
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Programming Languages 2nd edition Tucker and Noonan Chapter 6 Type Systems I was eventually persuaded of the need to design programming notations so as.
Chapter 3 Part II Describing Syntax and Semantics.
1 Typing XQuery WANG Zhen (Selina) Something about the Internship Group Name: PROTHEO, Inria, France Research: Rewriting and strategies, Constraints,
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
1 Chapter 6 Methods. 2 Motivation Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively.
Semantic Analysis II. Messages Please check lecturer notices in the Moodle Appeals  Legitimate: “I don’t have the bug you mentioned…”  Illegitimate:
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name value pair;
CSE 6331 © Leonidas Fegaras XQuery 1 XQuery Leonidas Fegaras.
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
XML Schemas Dr. Awad Khalil Computer Science Department AUC.
Design issues for Object-Oriented Languages
XML: Extensible Markup Language
Programming Languages and Compilers (CS 421)
Semantic Analysis Type Checking
Chapter 6 Intermediate-Code Generation
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Subtype Substitution Principle
More XML XML schema, XPATH, XSLT
Presentation transcript:

Static Typing in XQuery Mary Fernández, Jérôme Siméon, Philip Wadler Επιμέλεια Παρουσίασης: Μαγδαληνός Παναγής

Contents Introduction XQuery Processing Phases Definitions Example Static Analysis Phase Dynamic Evaluation Phase Values and Types in XQuery XML Schema and XQuery Types Values Relating Values and Types Examples

Introduction Definitions Example Static Analysis Phase Dynamic Evaluation Phase

Definitions Dynamic Typing: The process of checking during dynamic evaluation that the type of a value is compatible with the context in which it is used. Static Typing: The process of checking during static analysis that the type of an expression is compatible with the context in which it is used Type Correct Program: Never raise a type error in any evaluation

Definitions (Cont.) Dynamic Typing ? Sort of run-time evaluation. Static Typing ? Sort of compile-time and pre-compile time evaluation. Type Correct ? An equivalent to a Java program being able to compile.

Example – Relation Data in XML Tom Jones B Red Bicycle

Example – XML Schema <xs:schema targetNamespace=“ xmlns:xs=“ xmlns=“ > ………………………………………………………………………….. ………………………………………………………………………… ……………………………. ………………………………………………………………………….

Static Analysis Phase Static type: A type such that, when the expression is evaluated, the resulting type will always conform to the static type Static Error: Parse Error Inconsistency between Op- Tree and Static Context Type Error: Incompatibility between the static type of an expression and the type required by the context. XQueryOp - Tree Static Context Parse Query Modules Normalize Static Type Check Resolve Names Static Query Prolog Environmental Initialization

Static Analysis Phase (Cont.) Static Analysis equiv. Writing & Compiling Static Type example: Java: Vector v; ……. v.elementAt(i);  Return type is always java.lang.Object Type Error example: Java: Vector v; v.add(new Integer(1)); int i =v.elementAt(0)  Type Error. Expected type java.lang.Object but primitive type int was found

Dynamic Evaluation Phase Dynamic Type: Associated with each value during computation. More specific than Static Type. Dynamic Error: Errors occurring at runtime Type casting Schema dis-conformance Type Error: The dynamic type of a value does not match the expected type of the context in which the value occurs. Execution Engine Dynamic Context Access Op - Tree Access and Change Environmental Initialization Provide Access Access and Create Data Model Instances Data

Dynamic Evaluation Phase (Cont.) Dynamic Evaluation equiv. Execution Dynamic Type Example: Java: Vector v; ……. v.elementAt(i);  Return type is always java.lang.Object Type Error & Dynamic Error Example Java: Vector v; v.add(new Integer(1)); double i =Double.valueOf((Double)v.elementAt(0)) Dynamic & Type Error

Values and Types in XQuery XML Schema and XQuery Types Values Relating Values and Types

XML Schema and XQuery Types XML Schema  XQuery type notation Global/Local element declaration A local element is distinguished by content Type can be either user-defined or predefined An element declaration associates an element name and a type. E.g define element name of type xs:string A complex type declaration associates name and content model define type User{ attribute id of type xs:ID, element name of AnonymousType 1, element rating ? } Types can be combined with operators (, | ? + *) define type IntegerList {xs:integer + } Derivation by Restriction define type NewUser restricts User

Values XML input document: Mary Doe A XQuery formal notation: element user of type User{ attribute id of type xs:ID { “U02” }, element name of type AnonymousType1{ element first of type xs:string { “Mary “}, element last of type xs:string { “Doe” }, }, element rating of type xs:string { “A” } }

Relating Values and Types Usage of XQuery Types Analysis time Evaluation time Both proceed bottom – up Labeled sub-expressions, label an overall expression Labeled values of sub-expressions, label the value of an overall expression

Examples

Literals and Operators The static type system checks that the type of an expression is compatible with the type required by the context in which the expression is used. Examples: “hello” has type xs:string has type xs:integer has type xs:decimal (type promotion) “42” is a static type error “one” < “two” has type xs:boolean “one” < 2 is a static type error

Variables Variable bounding: let $z:= return $z + $z has type xs:integer Variable sub-typing: let $x as xs:decimal :=1 + 2 return $x + $x has type xs:decimal Variable sub-typing is different than type promotion let $x as xs:double :=1 + 2 return $x + $x is a static type error Correct (sort of type-casting): let $x as xs:double :=xs:double( 1 + 2) return $x +$x has type xs:double Sum up: Every expression is evaluated with respect to its sub-expressions let $x as xs:decimal :=1, $y as xs:integer :=$x + $x return $y + $y Why does it raise a static type error? let $x :=1, $y :=$x + $x return $y + $y What is the variable’s y and return value’s type?

Functions Every function has a signature fn:concat ($op1 as xs:string ?, $op2 as xs:string ?) as xs:string Every function must be well-typed: Required types: Derive from the signature declared types Are promoted to the signature declared types

Conditionals The condition must be a Boolean if ( $x<$y ) then 3 else 4 has type xs:integer If ( $x<$y ) then “three” else 4.00 has type (xs:string | xs:decimal) ( if ($x<$y) then 4.2e1 else 69) +0.5 has type (xs:double | xs:decimal) if( alwaysTrue() then 1 else “two”) +3 raises a static type error! Conclusion: Typing rules understand no infeasible paths

Path Expressions Examples: $auction/articles/article Meaning : all local elements article of local element articles of global element auction Has type :element (article) + $auction/(articles | users) Meaning: all articles and users elements of element auction Has type :((element(articles) | element(users)) + The previous : factored type Any re-ordering in a factored type sequence results in the same factored type What is the meaning of the following? $auction//(user|articles)/name Has type ( element(type(User)/name) | element(type(Article)/name) ) +

Predicates A predicate selects nodes in a path expression that satisfy a given expression: $auction/articles/article [start_date<=date()] has type element(article)* Why the following? $auction/articles/article has type element(article)* !!! exactly-one(),zero-or-one() functions More than one predicates can be used in an expression: $auction/articles/article[start_date<=current_date()][1]) has type element(article) ?

FLWOR Expressions FLWOR Expressions relies on factored types Examples: for $article in $articles return $article/end_date - $article/start_date has type xdt:dayTimeDuration + for $article in $articles where $article/start_date <= current_date() return $article/end_date - $article/start_date has type xdt:dayTimeDuration *

Validation Context Hierarchically defined context validation Tree-like definition of the validation context Global, … Explicitly defined context validation $first := validate context user/name { Mary } The latter is used if the context definition cannot be done lexically

Validation Mode Valid XML Data: Conform to an XML Schema or a DTD Well Formed XML Data: All open tags have matching end tags Validation modes: Strict : A declaration is available for the element and the element must validate with respect to that declaration Skip : Only well formatting constraints Lax : Validate strictly if a declaration is available Validation is lexically defined Any conflicts can be surpassed with “overriding”

Conclusions

To Conclude… Today we’ve learned about: The XQuery processing system The values and types in XQuery and their associations with XML Schema The way types and values are assigned to variables, functions,… The way an XQuery is validated and the different validation forms