Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » I need some help in ATL transformation when use KDM
I need some help in ATL transformation when use KDM [message #1007295] Tue, 05 February 2013 12:20 Go to next message
Rafael Durelli is currently offline Rafael DurelliFriend
Messages: 72
Registered: September 2012
Member
I have two metamodel a SQL Model and a KDM Data package. The former contains three metaclasses DataBase, Table and Column. The latter represents the artifacts related to persistent data, such as indexed files, relational databases, and other kinds of data storage.

In this context, I would like to transform the first metamodel (SQL Model) to the KDM Data package. Thus, I have created the following atl code.

-- @path MM=/SQLMODEL/model/sqlmodel.ecore
-- @nsURI MM1=http://www.eclipse.org/MoDisco/kdm/data
-- @nsURI MM1=http://www.eclipse.org/MoDisco/kdm/code

module teste;
create OUT : MM1 from IN : MM;


rule dataBase2RelationalSchema {
	from
		t : MM!Database
	to 
		r : MM1!RelationalSchema (
			name <- t.name,
			dataElement <- t.tables
		)
}

rule table2RelationalTable {
	from
		t : MM!Table
	to 
		r : MM1!RelationalTable (
			name <- t.name,
		 	dataElement <- t.columns
		)
}


rule column2ColumnSet {
	from
		t : MM!Column
	to 
		r : MM1!ColumnSet (
			name <- t.name,
			itemUnit <- item
		),
		
		item : MM1!ItemUnit (
			type <- type
		),
		
		type : MM1!Datatype (
		
			name <- t.type
			
		)
}



However it is not complete. Could someone help on this? Someone has an example ?

thanks in advance.
Re: I need some help in ATL transformation when use KDM [message #1007314 is a reply to message #1007295] Tue, 05 February 2013 13:52 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
What do you mean by "it is not complete"?

Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: I need some help in ATL transformation when use KDM [message #1007344 is a reply to message #1007314] Tue, 05 February 2013 15:20 Go to previous messageGo to next message
Rafael Durelli is currently offline Rafael DurelliFriend
Messages: 72
Registered: September 2012
Member
Hello Hugo firstly thanks..


I would like to transform my column type, which is just a String, to IntegerType, StringType, BooleanType, etc. In addition my SQL model also has an meta attribute named isPrimaryKey, which describes if that columns is a primary Key. Thus, I would like also to transform the Columns (of the SQL Model) to IntegerType, StringType, etc and sign that such Colums is primaryKey using the UniqueKey...

Re: I need some help in ATL transformation when use KDM [message #1007352 is a reply to message #1007344] Tue, 05 February 2013 15:36 Go to previous messageGo to next message
Rafael Durelli is currently offline Rafael DurelliFriend
Messages: 72
Registered: September 2012
Member
In order to be more specific my SQL Model can be seen by using this link...


https://docs.google.com/file/d/0B8cyA2SHw8zPaU5HRXFjTlU0VzA/edit?usp=sharing

I'd like to transform this metamodel to the KDM Data package. Could someone helps me?


Thanks in advance.


[Updated on: Tue, 05 February 2013 15:38]

Report message to a moderator

Re: I need some help in ATL transformation when use KDM [message #1007371 is a reply to message #1007352] Tue, 05 February 2013 16:22 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
According to what you've explained, it seems that you also need to create IntegerType, StringType, etc elements in your rule in order to then be able to assign them to the attributes of the corresponding KDM elements.
You should also avoid to use the same name for different variables as this could produce conflicts: e.g. type : MM1!Datatype can be ambiguous with the type attribute of some KDM elements...

Concerning the isPrimaryKey boolean attribute, you have to write the required OCL expression on your input model elements (expression returning a boolean value) in order to set it.

Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: I need some help in ATL transformation when use KDM [message #1007387 is a reply to message #1007371] Tue, 05 February 2013 17:13 Go to previous messageGo to next message
Rafael Durelli is currently offline Rafael DurelliFriend
Messages: 72
Registered: September 2012
Member
Could you please give me a little example?

Thanks in advance.


Re: I need some help in ATL transformation when use KDM [message #1007398 is a reply to message #1007387] Tue, 05 February 2013 18:07 Go to previous messageGo to next message
Rafael Durelli is currently offline Rafael DurelliFriend
Messages: 72
Registered: September 2012
Member
I'm trying to do what you have told me, but I didn't it right yet. See how is the source code now.


-- @path MM=/SQLMODEL/model/sqlmodel.ecore
-- @nsURI MM1=http://www.eclipse.org/MoDisco/kdm/data
-- @nsURI MM1=http://www.eclipse.org/MoDisco/kdm/code
module teste2;
create OUT : MM1 from IN : MM;

rule dataBase2RelationalSchema {
	from
		t : MM!Database
	to 
		r : MM1!RelationalSchema (
			name <- t.name,
			dataElement <- t.tables
		)
}

rule table2RelationalTable {
	from
		t : MM!Table
	to 
		r : MM1!RelationalTable (
			name <- t.name,
		 	dataElement <- t.columns
		)
}


rule column2ColumnSet {
	from
		t : MM!Column
	to 
		r : MM1!ColumnSet (
			name <- t.name,
			itemUnit <- item
		),
		
		item : MM1!ItemUnit (
			type <- type
		),
		
		type : MM1!Datatype (
		
			name <- t.type
			
		)
	
	do{
		
		if (t.type = 'VARCHAR') {
			thisModule.addString(t.type);
		} else {
			type.name <- 'notVAR';
		}
		
		
		
	}
}


rule addString(n : String) {
	
	to
	
		out: MM1!StringType(
		
			name <- n
		
		)

}


The output of this code is as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:code="http://www.eclipse.org/MoDisco/kdm/code" xmlns:data="http://www.eclipse.org/MoDisco/kdm/data">
  <data:RelationalSchema name="projectValter">
    <dataElement xsi:type="data:RelationalTable" name="ALUNO">
      <dataElement xsi:type="data:ColumnSet" name="RA">
        <itemUnit type="/1"/>
      </dataElement>
      <dataElement xsi:type="data:ColumnSet" name="id">
        <itemUnit type="/2"/>
      </dataElement>
      <dataElement xsi:type="data:ColumnSet" name="lastName">
        <itemUnit type="/3"/>
      </dataElement>
      <dataElement xsi:type="data:ColumnSet" name="name">
        <itemUnit type="/4"/>
      </dataElement>
    </dataElement>
    <dataElement xsi:type="data:RelationalTable" name="CLIENTE">
      <dataElement xsi:type="data:ColumnSet" name="usuario">
        <itemUnit type="/5"/>
      </dataElement>
      <dataElement xsi:type="data:ColumnSet" name="usuario2">
        <itemUnit type="/6"/>
      </dataElement>
      <dataElement xsi:type="data:ColumnSet" name="usuario3">
        <itemUnit type="/7"/>
      </dataElement>
      <dataElement xsi:type="data:ColumnSet" name="usuario500">
        <itemUnit type="/8"/>
      </dataElement>
    </dataElement>
    <dataElement xsi:type="data:RelationalTable" name="PERSONS">
      <dataElement xsi:type="data:ColumnSet" name="usuario">
        <itemUnit type="/9"/>
      </dataElement>
      <dataElement xsi:type="data:ColumnSet" name="usuario2">
        <itemUnit type="/10"/>
      </dataElement>
      <dataElement xsi:type="data:ColumnSet" name="usuario3">
        <itemUnit type="/11"/>
      </dataElement>
    </dataElement>
    <dataElement xsi:type="data:RelationalTable" name="USUARIOS">
      <dataElement xsi:type="data:ColumnSet" name="email">
        <itemUnit type="/12"/>
      </dataElement>
      <dataElement xsi:type="data:ColumnSet" name="usuario">
        <itemUnit type="/13"/>
      </dataElement>
    </dataElement>
  </data:RelationalSchema>
  <code:Datatype name="VARCHAR"/>
  <code:Datatype name="notVAR"/>
  <code:Datatype name="VARCHAR"/>
  <code:Datatype name="VARCHAR"/>
  <code:Datatype name="notVAR"/>
  <code:Datatype name="notVAR"/>
  <code:Datatype name="notVAR"/>
  <code:Datatype name="notVAR"/>
  <code:Datatype name="notVAR"/>
  <code:Datatype name="notVAR"/>
  <code:Datatype name="notVAR"/>
  <code:Datatype name="notVAR"/>
  <code:Datatype name="notVAR"/>
  <code:StringType name="VARCHAR"/>
  <code:StringType name="VARCHAR"/>
  <code:StringType name="VARCHAR"/>
</xmi:XMI>


I have created a rule named addString to create StringType when 'varchar' are found. However, it didn't work very well. Could you help me?


thanks.

[Updated on: Tue, 05 February 2013 18:09]

Report message to a moderator

Re: I need some help in ATL transformation when use KDM [message #1007519 is a reply to message #1007398] Wed, 06 February 2013 10:18 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

It's not really clear to me what you want to do in your transformation: could you simply describe in a couple of sentences the conceptual mapping you're trying to implement between SQL and KDM?
Anyway, using such do imperative sections and imperative called rules is generally not recommended.
ATL is a declarative language so it is very often faster/clearer to use declarative match rules or lazy rules.

Best regards,

Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: I need some help in ATL transformation when use KDM [message #1007528 is a reply to message #1007519] Wed, 06 February 2013 10:34 Go to previous messageGo to next message
Rafael Durelli is currently offline Rafael DurelliFriend
Messages: 72
Registered: September 2012
Member
Hello Hugo, thank you..


In order to try to explain to you please see my simple SQL model in https://docs.google.com/file/d/0B8cyA2SHw8zPaU5HRXFjTlU0VzA/edit?usp=sharing

By using this model I would like to make the following transformation:

(i) to transform the metaclass Database to RelationalShema, which is a metaclass of KDM Data package -
(ii) to transform the metaclass Table to RelationalTable, that is a metaclass of KDM data package as well -
(iii) to transform the metaclass Column to ColumnSet of KDM data package.

I have done a good job in the first two transformation. The problem that I'am dealing it is that I don't know how to create a transformation in ATL to "say" when the metaattribute name primaryKey is true then create a instance of the metaclass UniqueKey.

Thanks Hugo in advance.

Best regards.

Re: I need some help in ATL transformation when use KDM [message #1007545 is a reply to message #1007528] Wed, 06 February 2013 11:39 Go to previous messageGo to next message
Rafael Durelli is currently offline Rafael DurelliFriend
Messages: 72
Registered: September 2012
Member
Someone?
Re: I need some help in ATL transformation when use KDM [message #1007710 is a reply to message #1007545] Thu, 07 February 2013 08:43 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

I see two options here.

Option 1: use of rule inheritance

abstract rule column2ColumnSet {
	from
		t : MM!Column
	to 
		r : MM1!ColumnSet (
			name <- t.name,
			itemUnit <- item
		),
		item : MM1!ItemUnit (
			type <- type
		),
		type : MM1!Datatype (
		
			name <- t.type
			
		)
}

rule column2ColumnSet_1 extends column2ColumnSet {
        from
		t : MM!Column (
                   not t.primarykey
                )
	to 
		r : MM1!ColumnSet
}

rule column2ColumnSet_2 extends column2ColumnSet {
        from
		t : MM!Column (
                   t.primarykey
                )
	to 
		r : MM1!ColumnSet (
                   -- TODO set the "u" element how it has to be
                ),
                u : MM1!UniqueKey (
                   -- TODO set values
                )
}


Option 2: use of a lazy rule

rule column2ColumnSet {
	from
		t : MM!Column
	to 
		r : MM1!ColumnSet (
			name <- t.name,
			itemUnit <- item
                        -- TODO set the required att using a call such as
                        -- if t.primarykey then
                        --     thisModule.createUniqueKey(t)
                        -- else
                        --     OclUndefined
                        -- endif
		),
		item : MM1!ItemUnit (
			type <- type
		),
		type : MM1!Datatype (
			name <- t.type	
		)
}

lazy rule createUniqueKey {
        from
		t : MM!Column
	to 
		u : MM1!UniqueKey (
                     -- TODO set values
                )
}


Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: I need some help in ATL transformation when use KDM [message #1007743 is a reply to message #1007710] Thu, 07 February 2013 11:37 Go to previous messageGo to next message
Rafael Durelli is currently offline Rafael DurelliFriend
Messages: 72
Registered: September 2012
Member
Thanks Hugo I have tried both option but I would rather use the second one. Nevertheless, it didn't work yet. In order to explain with more details the same source code is described as follows. It worth highlighting that the error is described with a comment in the below source code.

rule column2ColumnSet {
	from
		t : MM!Column
	to 
		r : MM1!ColumnSet (
			name <- t.name,
			itemUnit <- item

                        if t.primarykey then --PROBLEM variable "t" is not found in this scope. ATL don't let I use it just like that... Is something wrong? 
                            thisModule.createUniqueKey(t)
                        else
                            OclUndefined
                        endif
		),
		item : MM1!ItemUnit (
			type <- type
		),
		type : MM1!Datatype (
			name <- t.type	
		)
}

lazy rule createUniqueKey {
        from
		t : MM!Column
	to 
		u : MM1!UniqueKey (
                     name <- t.name
                )
}



Thank you again.
Re: I need some help in ATL transformation when use KDM [message #1007783 is a reply to message #1007743] Thu, 07 February 2013 13:50 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
The expression I've proposed you has to be used in an attribute value assignment, otherwise it cannot work (I don't know the name of the ColumnSet's reference to the UniqueKey element, you have to look to the KDM metamodel for this):
r : MM1!ColumnSet (
	name <- t.name,
	itemUnit <- item,
        attributeToBeSet <- if t.primarykey then  
                                  thisModule.createUniqueKey(t)
                            else
                                  OclUndefined
                            endif
),

Anyway, I encourage you to look to the ATL user guide to get more details on the base structure of the ATL language.

Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: I need some help in ATL transformation when use KDM [message #1008426 is a reply to message #1007783] Tue, 12 February 2013 12:49 Go to previous message
Rafael Durelli is currently offline Rafael DurelliFriend
Messages: 72
Registered: September 2012
Member
Thanks Hugo for all yours replies.
Previous Topic:ATL Refining Using the API
Next Topic:model merging
Goto Forum:
  


Current Time: Sat Apr 20 01:27:20 GMT 2024

Powered by FUDForum. Page generated in 0.04775 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top