A tutorial on EMF-IncQuery

  • View
    947

  • Download
    5

Embed Size (px)

DESCRIPTION

Tutorial at EC-MFA 2011.

Transcript

  • 1. A TUTORIAL ON EMF-INCQUERYIncremental evalua;on of model queries over EMF modelsGbor Bergmann, kos Horvth, bel Hegeds, Zoltn Ujhelyi, Balzs Polgr, Istvn Rth, Dniel Varr Budapest University of Technology and Economics Fault Tolerant Systems Research GroupBudapest University of Technology and EconomicsDepartment of Measurement and Informa

2. Contents Mo;va;on o Model queries? o State of the art of EMF model queries o Goals Technology overview Hands-on part 1 o Basics (UML model sta;s;cs) Break Hands-on part 2 o Advanced well-formedness valida;on for UML o Integra;on with Papyrus UML Conclusion o Performance benchmarks o Q&A Feel free to ask ques4ons along the way! 3. Downloads h_p://viatra.inf.mit.bme.hu/incquery/events/ecmfa2011#Files What youll need o Eclipse Helios (Modeling) Make sure to allocate enough heap by passing -Xmx1024m through eclipse.ini o Op;onally: Papyrus UML h_p://www.eclipse.org/modeling/mdt/papyrus/updates/index.php o Everything from the update site h_p://viatra.inf.mit.bme.hu/update/ecmfa11/ o In your workspace: Sample IncQuery project h_p://viatra.inf.mit.bme.hu/downloads/demo/ecmfa11/ecmfa-incquery-project.zip Sample Papyrus UML models h_p://viatra.inf.mit.bme.hu/downloads/demo/ecmfa11/ecmfa-umlsamples-project.zip 4. MOTIVATIONWhile youre downloading J 5. First of all What is a model query? o A piece of code that looks for certain parts of the model. Mathema;cally o Query = set of constraints that have to be sa;sed by (parts of) the model. o Result = set of model elements (element congura;ons) that sa;sfy the constraints of the query. A query engine? o Supports the deni;on/execu;on of model queries. 6. Hi Jane, what do you do at work?Jane 7. Hi Jane, what do you do at work?Jane 8. Hi Jane, what do you do at work?JaneBoss 9. Hi Jane, what do you do at work?JaneDetectBoss Constraint 10. Hi Jane, what do you do at work?Jane Detect ReportBossConstraint 11. Hi Jane, what do you do at work?Jane Detect ReportViewBossConstraint 12. Hi Jane, what do you do at work?Jane Detect Gen ReportViewBossConstraint 13. Model queries Queries are at the heart of MDD.o Viewso Reportso Generatorso Validatorso Development issueso Complex queries are hard to write 14. Issues with query development Hard to write? Your op;ons o Java (or C/C++, C#, ) o Declara;ve languages (OCL, EMF Query 1-2, ) Impera;ve query languagesDeclara;ve query languages Expressive power L (you write lots of code) J (very concise) SafetyJJ (precise control over JL what happens at execu;on) (unintended side-eects) Learning curve J (you already know it)L (may be dicult to learn) Reusability J (standard OO prac;ces)LL(???) Performance LJ (considerable manual JL (depends on various op;miza;on necessary) factors) 15. Issues with query execu;on Query performanceo = Execu;on ;me, as a func;on of Query complexity Model size / contents Result set size Incrementalityo Dont forget previously computed results!o Models changes are usually small, yet up-to-date query results are needed all the ;me.o Incremental evalua;on is an essen;al, but not a very well supported feature. 16. Model query engine wish list Declara;ve query language o Easy to learn o Good bindings to the impera;ve world (Java) o Safe yet powerful o Reusable High performance o Fast execu;on for complex queries over large models o First-class support for incremental execu;on Technology o Works with EMF out-of-the-box 17. STATE OF THE ART 18. Problem 1: Expressiveness EMF Query (declara;ve) o Low expressiveness o Limited navigability no cycles OCL (declara;ve) o Verbose o Lack of reusability support o Local constraints of a model element o Poor handling of recursion Challenging to use 19. Problem 2: Incrementality Goal: Incremental evala;on of model querieso Incremental maintenance of result seto Avoid unnecessary re-computa;on Related work: o Constraint evalua;on (by A. Egyed) Arbitrary constraint descrip;on Can be a bo_leneck for complex constraints Always local to a model element Listen to model no;ca;ons Calculate which constraints need to be reevaluatedo No other related technology directly over EMFo Research MT tools: with varying degrees of support 20. Problem 3: Performance Na;ve EMF queries (Java program code): Lack of o Reverse naviga;on along references o Enumera;on of all instances by type o Smart Caching Scalability of (academic) MT tools o Queries over >100K model elements (several proofs): FUJABA, VIATRA2 (Java), GrGEN, VMTS (.NET), Egyeds tools 21. EMF-IncQuery Expressive declara;ve query language by graph pa_erns Incremental cache of matches (materialized view) High performance for large models 22. INCQUERY TECHNOLOGY OVERVIEW 23. Technology Overview What is EMF-INCQuery?o Query language + incremental pa_ern matcher + development tools for EMF models Works with any (pure) EMF applica;on Reusability by pa_ern composi;on Arbitrary recursion, nega;on Generic and parameterized model queries Bidirec;onal navigability Immediate access to all instances of a type Complex change detec;on Benetso Fully declara;ve + Scalable performance 24. Contribu;ons Expressive declara;ve query language by graph pa_ernso Capture local + global querieso Composi;onality + Reusabilility o Arbitrary Recursion, Nega;on Incremental cache of matches (materialized view) High performance for large models 25. Origins of the idea Model transforma;ons by VIATRA2o Transforma;on language Declara;ve pa_erns for model queries Graph transforma;on rules for elementary mapping specica;ons ASM rules for control structureo Matching strategy Local search-based (op;mized search plans) Incremental pa@ern matching (based on RETE) Hybrid pa_ern matching (adap;ve combina;on of INC and LS) Developed by BUTE and OptXware Ltd. More infoo h_p://eclipse.org/gmt/VIATRA2o h_p://wiki.eclipse.org/VIATRA2 26. ECore models as graphs Ecore VIATRA2 o EClass o En;ty (Node) o EReference o Rela;on (Edge) o EA_ributeo Node+Edge Car: EClassCar parts: EReferencepartsweight+weight: EIntPart: EClass Integer Part MyCar: Car :parts MyCar: Car:weight MyWheel: Partweight = 1500parts = [MyWheel:Part] : Integer value = 1500 27. Pa_ern deni;onGraphical nota;onimplementspa_ern siblingClass(C1,C2) UI Model superClassS: ClassS GComp CmdIfaceS1:superClass S2:superClass Class C1Bu_on ImageBu_on C2C1: ClassC2: Classmatching s1:implement Graph Pa_ern: o Structural condi;on that have to be GComp:Class Cmd:Ifacefullled by a part of the model space s2:included Graph pa_ern matching:s1:superClassi2:implement: Ifaceo A model (i.e. part of the model space) cBu_on:Class ImageBu_on:Classsa;sfy a graph pa_ern, o if the pa_ern can be matched to a subgraph of the model Instance Model 28. Graph pa_erns (VTCL)// B is a sibling class of AsiblingClass(A,B) pattern siblingClass(A, B) =P: Class{Class(A);s1:superClass s2:superClassClass.superClass(S1, A, P); A: ClassB: Class Class(P);Class.superClass(S2, B, P);Class(B); 29. Graph pa_erns (VTCL)// B is a sibling class of AsiblingClass(A,B) pattern siblingClass(A, B) =P: Class{Class(A);s1:superClasss2:superClassClass.superClass(S1, A, P); A: Class B: ClassClass(P);Class.superClass(S2, B, P);Class(B); // S is locally substitutable by AlocallySubs (A, S, X) pattern localSubs(A, S, X) = {Class(A); X: IfaceIface(X);I1:implementsI2:implementsClass.implements(I1, A, X);Class(S);A: Class S:ClassClass.implements(I2, S, X); OR } or { X: Class OR pa_ern Class(A);Class(X); s1:superClass s2: superClass Class.superClass(P1, X, X);A: Class S:Class Class(S); 30. Contribu;ons Expressive declara;ve query language by graph pa_ernso Capture local + global querieso Composi;onality + Reusabilility o Arbitrary Recursion, Nega;on Incremental cache of matches (materialized view)o Cheap maintenance of cache (only memory overhead)o No;fy about relevant changes (new match lost match)o Enable reac;ons to complex structural events High performance for large models 31. RETE nets RETE networko node: (par;al) matches of a (sub)pa_erno edge: update propaga;onPATTERN INPUTINPUTINPUTC: ClassTE: TypedElement C : ClassC : ClassUnusedClass(C) T : typeTE: TypedElement NEG T: typeTE: TypedElementJOIN ANTI-JOINC : Class C : Class T : type T : type Demonstra;on TE: TypedElemento input: UML model TE: TypedElementNEGo pa_ern: UnusedClass UnusedClass(C)o change: delete/retarget type reference 32. RETE nets RETE networko node: (par;al) matches of a (sub)pa_erno edge: update propaga;onPATTERN INPUT INPUTINPUTC: ClassTE: TypedElementC : ClassC : ClassUnusedClass(C) T : typeUnusedClass(C)TE: TypedElement NEGA class to which no type reference points T: typeAssocia;onTE: TypedElement JOINPropertyANTI-JOINParameterC : Class C : Class T : type Variable T : type Demonstra;on TE: TypedElemento input: UML modelTE: TypedElementNEGo pa_ern: UnusedClassUnusedClass(C)o change: delete/retarget type reference 33. RETE nets RETE networko node: (par;al) matches In-memory modelof a (sub)pa_erno edge: update (EMF ResourceSet)propaga;onPATTERNINPUT INPUTINPUTC: Class TE: TypedElementC : ClassC : ClassUnusedClass(C) Input nodes T : typeTE: TypedElement NEG T: typeTE: TypedElement JOINANTI-JOINIntermediate Produc;on C : ClassC : Class T : type nodes T : type Demonstra;ono input: UML modelTE: TypedElementnode NEG TE: TypedElemento pa_ern: UnusedClass UnusedClass(C)o change: delete/retarget type reference 34. RETE nets RETE networko node: (par;al) matches of a (sub)pa_erno edge: update propaga;onPATTERN INPUTINPUTINPUTC: ClassTE: TypedElement C : ClassC : ClassUnusedClass(C) T : typeTE: TypedElement NEG T: typeTE: TypedElementJOIN ANTI-JOINC : Class C : Class T : type T : type Demonstra;on TE: TypedElemento input: UML model TE: TypedElementNEGo pa_ern: UnusedClass UnusedClass(C)o change: delete/retarget type reference 35. RETE nets Class objects RETE networka b co node: (par;al) matches p sTypedElement.type edgesof a (sub)pa_ern xz w TypedElement objectso edge: up