1 static type analysis of path expressions in xquery using rho-calculus wang zhen (selina) oct 26,...

33
1 Static Type Analysis of Path Expressions in XQuery Using Rho- Calculus Wang Zhen (Selina) Oct 26, 2006

Upload: clifton-mcdowell

Post on 27-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

1

Static Type Analysis of Path Expressions in XQuery Using Rho-CalculusWang Zhen (Selina)

Oct 26, 2006

Page 2: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

2

Outline

Background Related Work Typing XQuery Using Rho Calculus Conclusion and Future Work

Page 3: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

3

BackgroundXQuery: A query language for XML documents W3C Candidate Recommendation, 8 June 2006 Query processing (recommended for implementation):

Static analysis phase Parsing: parsed expression Static Context Processing: the static context (statEnv) Normalization: equivalent expression in Core Grammar

[Expr]=core:Expr Static type analysis

Dynamic evaluation phase Dynamic Context Processing: the dynamic context (dynEnv) Dynamic Evaluation (Dynamic type analysis)

Page 4: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

4

Background

Typing XQuery Static type analysis (STA):

Compile-time Allows early detection of type errors Can be used as the basis for certain classes of optimization.

Dynamic type analysis (DTA): Run-time Can be avoided when STA is enabled, since:

Any type error found during DTA can be found during STA

Page 5: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

5

BackgroundRho-Calculus A framework embedding Lambda calculus and Term Rewriting Explicitly handles the rules, since the syntax allows rule

definitions and rule applications

Judgment: expresses whether a property holds or not. E.g.: Type judgment: ( statEnv |- )? Expr: Type

Rule application, e.g.: [X+Y→Y+X](A+B) => B+A

Rule definition Application

Page 6: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

6

BackgroundRho-Calculus’s Typing System Subject reduction -- the type of a term does change

during its reduction Type uniqueness Decidability -- given a term A in a context Γ, the following

problems are decidable: Whether there is a type , such that Γ├ A: Given a type , whether it is true that Γ├ A:

Page 7: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

7

Related WorkXQuery 1.0 and XPath 2.0 Formal Semantics W3C Candidate Recommendation “…uses several kinds of formal notations to define the

relationships between [XPath/XQuery] expressions, XML values, and XML Schema types…”

Some Important notations/definitions: Judgment: expresses whether a property holds or not. E.g.:

Type judgment: statEnv |- Expr: Type Subtype judgment: Type1 <: Type2  

Typing rule:

conclusion

premisepremise n...1

(All premises and the conclusion are judgments.)

Page 8: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

8

Related Work

XQuery 1.0 and XPath 2.0 Formal Semantics STA

Provides the typing rules for each kind of XQuery/XPath expression

Static typing works by recursively applying the rules over a given expression

Other XML Query languages : XDuce/CDuce, µXQ, Tequyla-TX, …… STA: use rules

Page 9: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

9

Related WorkProblems1st Problem: Complicated, difficult to be fully implemented, E.g.: XQuery

W3C Formal Semantics About 40~50 kinds of judgments Even more rules for each XQuery/XPath expression Many XQuery implementations, however:

Some of them do not support STA Some support: encode the rules and judgments

The specification is still being updated Difficult to keep up with the changes.

2rd problem: difficult to prove the property of typing system, e.g.: soundness

Question: whether we can use a “reasonable” and “safe” typing system, where the rules can be maintained easily

Page 10: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

10

Typing XQuery Using Rho Calculus Some prefixes used later

Page 11: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

11

Typing XQuery Using Rho Calculus XQuery W3C Formal Semantics

STA

[xq:Expr]FS = core:Expr

Typed core:Expr

Our approach:

Rho-Normalization 『 fs:Definitions or core:Expr 』 Rho= mapped object

XML

Schemaimport fs:Definitions

core:Expr

fs:Definitions

Mapped to

Mapped to judgments

Rho term

Typing rules

Rho Calculus’s

typing system

Page 12: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

12

Typing XQuery Using Rho CalculusType: extend the type definition in Rho calculus to meet the

requirement of XQuery types fs:Type mapped rho:Type

The definition of fs:Type Based on the six node types in XML document: document, element, attribute, comment, processing-instruction, text

Page 13: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

13

Typing XQuery Using Rho CalculusTypes

Accordingly, we define

fs:Type mapped rho:Type

Page 14: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

14

Typing XQuery Using Rho Calculus

Page 15: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

15

Typing XQuery Using Rho CalculusWe extend the rho:Type definition as

Page 16: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

16

Typing XQuery Using Rho Calculus Our approach:

Element definition: define element elemName of type typeName

elemName: typeName Attribute definition:

define attribute attrName of type typeName {attrName: typeName}

Type definition: define type typeName {fs:Type}

『 fs:Type 』 → typeName

fs:Definitions

Mapped to

Mapped to judgments

Rho term

Rho Calculus’s

typing system [xq:Expr]FS = core:Expr

XML

Schemaimport

Page 17: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

17

Typing XQuery Using Rho CalculusExample: doc(“CTL.xml”)/catalogue

catalogue.xsd

Page 18: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

18

Typing XQuery Using Rho Calculus

fs:Definitions

Mapped to

Mapped to judgments

Rho term

Rho Calculus’s

typing system [xq:Expr]FS = core:Expr

XML

Schemaimport

import

Page 19: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

19

Typing XQuery Using Rho Calculus

fs:Definitions

Mapped to

Mapped to judgments

Rho term

Rho Calculus’s

typing system [xq:Expr]FS = core:Expr

XML

Schemaimport

Some variables used in the following slides:

Currently we focus on Path expressions: the key syntax in XQuery

Page 20: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

20

Typing XQuery Using Rho Calculus XQuery Grammar

XQuery Core GrammarFunction callsFLWOR Expr

(for-let-where-

order by-return Expr)StepExpr

Page 21: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

21

Typing XQuery Using Rho Calculus FLWOR Expr: for-let-where-order by-return In Core Grammar:

ForClause + Return

Page 22: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

22

Typing XQuery Using Rho Calculus FLWOR Expr: for-let-where-order by-return ForClause + Return

Page 23: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

23

Typing XQuery Using Rho Calculus XQuery Grammar

XQuery Core GrammarFunction callsFLWOR Expr StepExpr

Page 24: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

24

Typing XQuery Using Rho Calculus StepExpr in Core Grammar:

Page 25: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

25

Typing XQuery Using Rho CalculusStepExpr Example: Child::NameTest, Child::KindTest Mapped to some function calls:

Page 26: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

26

Typing XQuery Using Rho Calculus

Page 27: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

27

Typing XQuery Using Rho Calculus XQuery Grammar

XQuery Core GrammarFunction callsFLWOR Expr StepExpr

Page 28: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

28

Typing XQuery Using Rho CalculusExample: doc(“CTL.xml”)/catalogue

catalogue.xsd

Page 29: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

29

Typing XQuery Using Rho Calculus

fs:Definitions

Mapped to

Mapped to judgments

Rho term

Rho Calculus’s

typing system [xq:Expr]FS = core:Expr

XML

Schemaimport

import

Page 30: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

30

Typing XQuery Using Rho Calculus

fs:Definitions

Mapped to

Mapped to judgments

Rho term

Rho Calculus’s

typing system [xq:Expr]FS = core:Expr

XML

Schemaimport

[doc(“CTL.xml”)/catalogue]FS

=

Example: doc(“CTL.xml”)/catalogue

Page 31: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

31

Page 32: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

32

Conclusion and Future WorkWe analysis the current research work on STA for XML Query

languages, specially XQuery Problems

The typing system is too complicated to be fully implemented It’s not easy to maintain the implementation so that it can keep up

with the update of the rules Solution: use Rho Calculus to express XQuery expressions,

since the calculus is designed to define and maintain rules easily. provides “reasonable” and “safe” typing system

Future work: Analysis other syntax of XQuery using Rho Calculus Analysis the property of the typing system under our extension

Page 33: 1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006

33