Upload
peregrine-fisher
View
213
Download
0
Embed Size (px)
Citation preview
Intermodeling, Queries and Kleisli categories
Zinovy Diskin, Tom Maibaum, Krzysztof Czarnecki
McMaster University,University of Waterloo
NECSIS and MDE
• Network for Engineering of Complex Software-Intensive Systems for Automotive Systems – Eight Canadian research institutions– Three industrial partners (GM Canada, IBM
Canada, and Malina Software)
WADT'12 Query languages are Cartesian monads 2
Intermodeling (termed coined by Guerra et al, at MoDELS’10):
• What: Specification and maintenance of intermodel relations (techniques and tools)
• Why: Modeling is multimodeling
3Query languages are Cartesian monads
M2
M3
M1
R23
R12
R13
R123
WADT'12
Why intermodeling, cont’d
4Query languages are Cartesian monads
M2
M3
M1
R23
R12
R13
R123
WADT'12
Scenarios:• Consistency• Sync/change propagation • Merge
There is much more to R’s than name correspondence!
Contents
• Specifying intermodel relations is difficult• Main features of our framework by examples• Q-mappings at work: Model merge• Formalization via Cartesian monads • Summary: model management via algebra
(or, colors of model management)
Query languages are Cartesian monads 5WADT'12
Specifying intermodel relations is not easy
s:Student name=Mr. Lee
bdate=01/01/1990
a: Woman -Actor name=Ann
age = 21
Model S Model A=
?
semanticrelativism
homonymy
?
?
WADT'12 6
The indirect link problem
The Domain: Ms. Ann Lee, 01/01/1990, a student and an
actor
Query languages are Cartesian monads
“part of”
Contents
• Specifying intermodel relations is difficult• Main features of our framework by examples• Q-mappings at work: Model merge• Formalization via Cartesian monads • Summary: model management via algebra
(or, colors of model management)
Query languages are Cartesian monads 7WADT'12
Query languages are Cartesian monads /30
Indirect links via direct Q-links(Kleisli’s idea)
• Replace indirect links by direct links into derived elements (computed by queries, Q-links)
s: Student name = Ms.Lee bdate = 01/01/90
a: Actor name = Ann age = 22
Model AModel S +
WADT'12
=
=?
/age = 2012-1990 = 22
But first relate metamodels
Query languages are Cartesian monads 13
f Metamodel, AMetamodel S+
Student name: {Ms,Mr} x Str bdate: Int3
/age = Q(bdate) : Int
WADT'12
Actor name = Str age = Int
f: f Model, A: AModel S+: S+
S: Student name = Ms.Lee bdate = 01/01/90 /age = exec Q(01/01/90) = 22: Int
a: Actor name = Ann age = 22
Query languages are Cartesian monads /30
Q-links vs. semantic relativism, 1
Student name: {Mr, Ms} x Str
Metamodel S Actor
name: Str
Metamodel A
Woman Man
?
WADT'12
Common intermodeling jargon: 1-to-M(any) linkWe say indirect 1-M link
/30
Q-links vs. semantic relativism, 2
Student name: {Mr, Ms} x Str
Metamodel S Actor name: Str
Metamodel A+
Woman Man
WADT'12
/title = Q1(W-M typing)
Query languages are Cartesian monads
/30
Student name: {Mr, Ms} x Str
Metamodel S Actor name: Str
Metamodel A+
Woman Man
WADT'12
/title = Q1 (W-M typing) /tname = Q2 (name, /title)
An indirect 1-M link x <---> {y1,…, ym } is replaced by a direct 1-1 q-link x <---> Q(y1,…, ym)
Q-links vs. semantic relativism, 3
Query languages are Cartesian monads
13
Student name: {Mr, Ms} x Str
Metamodel S Actor name: Str
Metamodel A+
Woman Man
WADT'12
/title = Q1 (W-M typing) /tname = Q2 (name, title)
m
S A
A+ = Q(A)
mi
Q-links and asymmetry of mappings
m is an ordinary total mapping consisting of pairs of elements.
S is a view of A
Query languages are Cartesian monads
14/36
ActorMetamodel A+
Woman Man
WADT'12
/title = Q2 (W-M typing)
m
Derived-derived case. Partial mappings.
Student name: {Mr, Ms} x Str
Metamodel S+
/title = Q1(name)
S A
S+ = Q1(S)
i1 m2
m1
A+ = Q2(S)
i2
Query languages are Cartesian monads
x
x
15/36
ActorMetamodel A+
Woman Man
WADT'12
/title = Q1 (W-M typing)
From partial mappings to spans(Reifying intermodel links)
Student name: {Mr, Ms} x Str
Metamodel S+
/title = Q1(name)
S A
S+ = Q1(S)
i1
m2
A+ = Q2(S)
i2
Query languages are Cartesian monads
Metamodel R Person title: {Mr, Ms}
Rm1
Contents
• Specifying intermodel relations is difficult• Main features of our framework by examples• Q-mappings at work: Model merge • Towards formalization via Cartesian monads • Summary: model management via algebra
(or, colors of model management)
Query languages are Cartesian monads 16WADT'12
General pattern for merge
FASE'12 28/36
M+
A
r1
B
C
D
R1
R2...
r2Colimit
. .
. Color Legend: Black -- given Green --- discovery/heuristics/AI Blue --- pure algebra!
Intermodeling, Queries, and Kleisli categories
…
Intermodeling, Queries, and Kleisli categories
Merge via colimit: Example
FASE'12 23/36
ActorMetamodel A+
Woman Man
/title = Q2 (W-M typing)
Student name: {Mr, Ms} x Str
Metamodel S+
/title = Q1(name)
Metamodel R
? (Person) name: {Mr, Ms} x Str
Metamodel M+
Woman Man
/title = Q1 (name) = Q2 (W-M typing)
R2M
Person title: {Mr, Ms}
S2MA2M
R2S R2A
Intermodeling, Queries, and Kleisli categories
Merge via colimit cont’d
FASE'12 23/36
ActorMetamodel A+
Woman Man
/title = Q2 (W-M typing)
Student name: {Mr, Ms} x Str
Metamodel S+
/title = Q1(name)
Metamodel R
********
**** R2M
Person title: {Mr, Ms}
S2MA2M
R2S R2A
? (Person) name: {Mr, Ms} x Str
Metamodel M
Woman Man
Q1 (name) = Q2 (W-M typing)
/30
Another version of intermodel span
Person title: {Mr, Ms} x Str
Metamodel R Actor
Metamodel A
Woman Man
R2A
/MsPerson/MrPerson
FASE'12FASE'12
Student name: {Mr, Ms} x Str
Metamodel S+
/title = Q1(name)
R2S
? (Person) name: {Mr, Ms} x Str
Metamodel M+
/title = Q1 (name)
/MsPerson /MrPerson
Q2(/title)
S2M
A2M
Q2(title)
Normalized merge
21/36
Person title: {Mr, Ms} x Str
Metamodel R Actor
Metamodel A
Woman Man
R2A
/MsPerson/MrPerson
FASE'12FASE'12
Student name: {Mr, Ms} x Str
Metamodel S+
/title = Q1(name)
R2S
? (Person) name: {Mr, Ms} x Str
Metamodel M
********
Q2(title)
Intermodeling, Queries, and Kleisli categories
General pattern for merge
FASE'12 28/36
M+
A
r1
B
C
D
R1
R2...
r2Colimit
. .
. Color Legend: Black -- given Green --- discovery/heuristics/AI Blue --- pure algebra!
Intermodeling, Queries, and Kleisli categories
…
Three colors of model management
Discovering (heuristics + AI): Model diff/matching/alignment
Execution (pure algebra): Model merge/update propagation
Mixture: Weaving Green and Blue in one algorithm/module often results in Red
FASE'12 Intermodeling, Queries, and Kleisli categories
Intermodeling, Queries, and Kleisli categories
But…
• Algebraic techniques work well if the universe of models and Q-mappings between them is a category
• We need to define composition of Q-mappings• It is not trivial
24/36FASE'12
Query languages are Cartesian monads
Q-mappings as Kleisli mappings
WADT'12 27/36
A B
Q(B)
fiQ
A B*******
m = (Q, f)A B
m
A B
Q(B)
fiQ
Thick (extensional) notation
Thin (formula) notation
Ordinary mappings
Q-mappings
Query languages are Cartesian monads
Problem of Q-mapping composition
26/36
BD
Qf(AD) Qg(BD)
CDfD gD
gSfS
AS BS
Qf(AS )
CSfS
gS
Qg(BS )
CBAf g
qExeSchemas (data & query/view definitions) S stands for “the schema part”
Instances (data and query execs) Subindex D stands for “the Data part”
Typing mapping (t is “the typing part”)
?
?At
Bt
CtqExe
AD
AS BS CSMetamodels (or schemas)WADT'12
Models and their maps
Qf(At)Qg(Bt)
Query languages are Cartesian monads
Solution: first, we manage syntax (the easy part)
AD BD
Qf(AD) Qg(BD)
CDfD gD
AS BS
Qf (AS)
CSfS
gS
Qg#( Qf (AS))
fS#
subst Qg (BS)
typing
CBAf g
WADT'12
Schemas (data & query/view definitions) S stands for “the schema part”
Instances (data and query execs) Subindex D stands for “the Data part”
?
Query languages are Cartesian monads
Solution: second, we manage semantics(the difficult part)
AD BD
Qf(AD) Qg(BD)
CDfD gD
AS BS
Qf (AS)
CSfS
gS
Qg#( Qf (AS))
fS#
subst Qg (BS)
typing
CBAf g
WADT'12
Schemas (data & query/view definitions) S stands for “the schema part”
Instances (data and query execs) Subindex D stands for “the Data part” Qg
#(Qf(AD))
qExe
fD#
monot
Fortunately, many useful queries are monotonic (e.g., SPJ)
Intermodeling, Queries, and Kleisli categories
Some formal details1) Simple (no-queries) model translation from one metamodel to
another (retyping) can be specified by a categorical construct called fibration, p: Mod -->MMod (by def).
2) A monotonic query language is specified by a monad over the fibration 1), Q: Mod-->Mod, Qdef: MMod-->MMod, p:Q-->Qdef. This monad is Cartesian! (by def)
3) Models and Q-mappings form the Kleisli category of the monad in 2)• Corollary. If the cat of models and simple mappings is closed
wrt. merge, then the cat of models and Q-mappings is closed wrt. merge as well.
4) Theorem. Model translations determined by Q-mappings (= view mechanism) again form a fibration. That is, querying followed by retyping is compositional. 33/36 FASE'12
Query languages are Cartesian monads
Summary• A (vast?) majority of intermodel relationships
can be specified by Q-mappings• With Kleisli construction, models and Q-
mappings between them form a category, i.e., a universe of well-defined algebraic operations
• Model management scenarios include two basic stages:– Discovery of Q-mappings between models;– Execution of an algebraic operation over models and
mappings• Weaving green into blue often results in red
WADT'12
Query languages are Cartesian monads
THE END
WADT'12 /30
Query languages are Cartesian monads
s:Student name=Mr. Lee a: Woman -Actor
name=Ann
Model S Model A
WADT'12 9
Solution 1: Annotate indirect links with correspondence rules
(= expressions attached to links)
If s = a, then if s.name.title = Mr, then a.class = Man, else a.class = Woman
=
Conflict!
Query languages are Cartesian monads
Solution 1: another sample
s:Student name=Mr. Lee bdate=01/01/1990
a: Woman -Actor name=Ann age = 21
Model S Model A=
WADT'12 10
if s = a, then if s.bdate.month&day current.month&day then a.age = 2012 s.bdate.year - 1, else a.age = 2012 – p.bdate.year
Conflict!
Query languages are Cartesian monads /30
Problems of Solution 1
M1 M2
• Partially ad hoc• Or, use something universal, say, OCL or FOL, but• Network structure is collapsed into one big model • Mapping composition problem (well recognized
in the DB literature, Bernstein et al.)WADT'12
M3 …R12 R23 …
… … …R13 ?
Query languages are Cartesian monads
Grand statement
• Many (all?) 1-M indirect links are nothing but hidden 1-1 Q-links:
A basic element of one model can be derived in another model and vv.
• Semantic relativism = Basic-Derived correspondence (= Q-links)
WADT'12 /30
Query languages are Cartesian monads
Grand indeed?
• What’s about M-M links, or the derived-derive case?
WADT'12 /30