370 likes | 468 Views
Intermodeling , Queries and Kleisli categories. Zinovy Diskin , Tom Maibaum , Krzysztof Czarnecki McMaster University, University of Waterloo. NECSIS and MDE . N etwork for E ngineering of C omplex S oftware-Intensive S ystems for Automotive Systems
E N D
Intermodeling, Queries and Kleisli categories ZinovyDiskin, 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) Query languages are Cartesian monads
Intermodeling(termed coined by Guerra et al, at MoDELS’10): R12 M2 M1 R123 R23 M3 R13 What: Specification and maintenance of intermodel relations (techniques and tools) Why: Modeling is multimodeling Query languages are Cartesian monads
Why intermodeling, cont’d • Scenarios: • Consistency • Sync/change • propagation • Merge R12 M2 M1 R123 R23 R13 M3 There is much more to R’s than name correspondence! Query languages are Cartesian monads
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
Specifying intermodel relations is not easy The Domain: Ms. Ann Lee, 01/01/1990, a student and an actor = Model S Model A homonymy ? ? semantic relativism The indirect link problem ? “part of” Query languages are Cartesian monads
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
Indirect links via direct Q-links(Kleisli’s idea) Model S + Model A = ? = /age = 2012-1990 = 22 Replace indirect links by direct links into derived elements (computed by queries, Q-links) Query languages are Cartesian monads
But first relate metamodels f Metamodel, A MetamodelS+ f: f Model, A: A Model S+:S+ Query languages are Cartesian monads
Q-links vs. semantic relativism, 1 Metamodel S MetamodelA ? Common intermodeling jargon: 1-to-M(any) link We say indirect 1-M link Query languages are Cartesian monads
Q-links vs. semantic relativism, 2 Metamodel S MetamodelA+ /title = Q1(W-M typing) Query languages are Cartesian monads
Q-links vs. semantic relativism, 3 Metamodel S MetamodelA+ /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) Query languages are Cartesian monads
Q-links and asymmetry of mappings m Metamodel S MetamodelA+ /title = Q1 (W-M typing) /tname = Q2 (name, title) Sis a view of A S A m i A+ = Q(A) m is an ordinary total mapping consisting of pairs of elements. Query languages are Cartesian monads
Derived-derived case. Partial mappings. m Metamodel S+ MetamodelA+ x /title = Q2 (W-M typing) /title = Q1(name) x S A i1 i2 m2 S+ = Q1(S) A+ = Q2(S) m1 Query languages are Cartesian monads
From partial mappings to spans (Reifyingintermodel links) Metamodel S+ MetamodelA+ Metamodel R /title = Q1 (W-M typing) /title = Q1(name) S R A m1 m2 i1 i2 S+ = Q1(S) A+ = Q2(S) Query languages are Cartesian monads
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
General pattern for merge B R1 A ... … R2 C r1 r2 Colimit D . . . M+ Color Legend: Black -- given Green --- discovery/heuristics/AI Blue --- pure algebra! Intermodeling, Queries, and Kleisli categories
Merge via colimit: Example Metamodel R R2A Metamodel S+ MetamodelA+ R2S /title = Q2 (W-M typing) /title = Q1(name) R2M S2M Metamodel M+ A2M /title = Q1 (name) = Q2 (W-M typing) Intermodeling, Queries, and Kleisli categories
Merge via colimit cont’d Metamodel R R2A Metamodel S+ R2S MetamodelA+ /title = Q2 (W-M typing) /title = Q1(name) R2M **** **** **** S2M A2M Metamodel M Q1 (name) = Q2 (W-M typing) Intermodeling, Queries, and Kleisli categories
Another version of intermodel span R2A Metamodel R MetamodelA Metamodel S+ R2S /title = Q1(name) Q2(title) /MsPerson /MrPerson S2M A2M Metamodel M+ /title = Q1 (name) Q2(/title) /MsPerson /MrPerson FASE'12
Normalized merge R2A Metamodel R MetamodelA Metamodel S+ R2S /title = Q1(name) Q2(title) /MsPerson /MrPerson **** **** Metamodel M FASE'12 Intermodeling, Queries, and Kleisli categories
General pattern for merge B R1 A ... … R2 C r1 r2 Colimit D . . . M+ 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: WeavingGreenandBluein one algorithm/module often results in Red 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 Intermodeling, Queries, and Kleisli categories
Q-mappings as Kleisli mappings Thick (extensional) notation Thin (formula) notation A B A B f f Ordinary mappings iQ iQ Q(B) Q(B) m = (Q, f) m Q-mappings A B ******* B A Query languages are Cartesian monads
Problem of Q-mapping composition f g B A C Models and their maps CD AD BD fD gD Instances (data and query execs) Subindex D stands for “the Data part” Qf(AD) ? Qg(BD) Ct At qExe Qf(At) qExe Bt Qg(Bt) Typing mapping (t is “the typing part”) CS AS BS gS fS ? Qf(AS) Qg(BS) Schemas (data & query/view definitions) S stands for “the schema part” fS gS AS BS Metamodels (or schemas) CS Query languages are Cartesian monads
Solution: first, we manage syntax (the easy part) f g B A C AD BD CD fD gD Qf(AD) Qg(BD) Instances (data and query execs) Subindex D stands for “the Data part” ? typing CS AS BS gS fS subst Qf(AS) Qg(BS) Schemas (data & query/view definitions) S stands for “the schema part” fS# Qg#( Qf(AS)) Query languages are Cartesian monads
Solution: second, we manage semantics(the difficult part) f g Fortunately, many useful queries are monotonic (e.g., SPJ) B A C AD BD CD fD gD monot Qf(AD) Qg(BD) Instances (data and query execs) Subindex D stands for “the Data part” fD# Qg#(Qf(AD)) qExe typing CS AS BS gS fS subst Qf(AS) Qg(BS) Schemas (data & query/view definitions) S stands for “the schema part” fS# Qg#( Qf(AS)) Query languages are Cartesian monads
Some formal details • 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). • 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) • 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. • Theorem. Model translations determined by Q-mappings (= view mechanism) again form a fibration. That is, querying followed by retyping is compositional. Intermodeling, Queries, and Kleisli categories
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 operationover models and mappings • Weavinggreeninto blue often resultsinred Query languages are Cartesian monads
THE END Query languages are Cartesian monads
Solution 1: Annotate indirect links with correspondence rules (= expressions attached to links) Model S = Model A Conflict! If s = a, then ifs.name.title = Mr, thena.class = Man, elsea.class = Woman Query languages are Cartesian monads
Solution 1: another sample Model S = Model A Conflict! ifs = 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 Query languages are Cartesian monads
Problems of Solution 1 … R12 R23 … M1 M2 M3 … … … R13 ? • 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.) 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) Query languages are Cartesian monads
Grand indeed? What’s about M-M links, or the derived-derive case? Query languages are Cartesian monads