1 Static Type Analysis of Path Expressions in XQuery Using Rho- Calculus Wang Zhen (Selina) Oct 26, 2006
Dec 27, 2015
1
Static Type Analysis of Path Expressions in XQuery Using Rho-CalculusWang Zhen (Selina)
Oct 26, 2006
2
Outline
Background Related Work Typing XQuery Using Rho Calculus Conclusion and Future Work
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)
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
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
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:
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.)
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
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
10
Typing XQuery Using Rho Calculus Some prefixes used later
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
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
13
Typing XQuery Using Rho CalculusTypes
Accordingly, we define
fs:Type mapped rho:Type
14
Typing XQuery Using Rho Calculus
15
Typing XQuery Using Rho CalculusWe extend the rho:Type definition as
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
17
Typing XQuery Using Rho CalculusExample: doc(“CTL.xml”)/catalogue
catalogue.xsd
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
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
20
Typing XQuery Using Rho Calculus XQuery Grammar
XQuery Core GrammarFunction callsFLWOR Expr
(for-let-where-
order by-return Expr)StepExpr
21
Typing XQuery Using Rho Calculus FLWOR Expr: for-let-where-order by-return In Core Grammar:
ForClause + Return
22
Typing XQuery Using Rho Calculus FLWOR Expr: for-let-where-order by-return ForClause + Return
23
Typing XQuery Using Rho Calculus XQuery Grammar
XQuery Core GrammarFunction callsFLWOR Expr StepExpr
24
Typing XQuery Using Rho Calculus StepExpr in Core Grammar:
25
Typing XQuery Using Rho CalculusStepExpr Example: Child::NameTest, Child::KindTest Mapped to some function calls:
26
Typing XQuery Using Rho Calculus
27
Typing XQuery Using Rho Calculus XQuery Grammar
XQuery Core GrammarFunction callsFLWOR Expr StepExpr
28
Typing XQuery Using Rho CalculusExample: doc(“CTL.xml”)/catalogue
catalogue.xsd
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
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
31
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
33