-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ETL] Native support for 1:m..n rules #123
Comments
I thought the same off the top of my head but this doesn't seem to be the case. Calling |
Sadly in my case it seems I get non-deterministic results, as in, the results of the transformation change between runs. Might be caused by other rules and the complexity of my case . However I am unable to get a minimal example to highlight the issue. Although I state the equivalents as a motivation, I also think that the syntax provides a better description of the rule's intent, and simplifies part of the rule body. |
I think that the issue might be that in line 4 of your rule you are calling
I agree that adding some dedicated syntax would be useful (ATL provides the distinct keyword for this) however I would avoid introducing a new keyword and would favour
Also, we should support these
Thoughts? |
I like the use of the I'd change the semantics slightly, so the rule populates the
Another option could be something like this, which reuses the for loop syntax of EOL and exposes the collection element as a variable for use within the body and guard (assuming it runs once per
The above option would not allow for different counts for each target type, though. |
My idea is more like the second case in Antonio's post. If you look at my initial post, by moving the 'for' to the rule definition the idea is to remove the for loop from the rule's body. Additionally, there is no 'Sequence' type in the 'to' definition. One set of 'to' elements will be created for each iteration. This means that you always get the same number of elements of each 'to' (I would not allow a sperate collection for each 'to' element as it would complicate the semantics). Perhaps the coin example is too simple to demonstrate the idea. This is another one: https://eclipse.dev/epsilon/playground/?0c4cef86 The intention of the change is that the second rule can be changed from this:
to this:
In my head, the two main benefits is the ability to explicitly state what type of elements are created and to simplify the rule body. |
@arcanefoam: Wouldn't the following be a more sensible way to implement this transformation?
@agarciadom: The call to the
My thinking was that the A limitation with this solution is e.g. that we could not fill the
Initialiser expressions could also be useful for single-valued targets e.g.
Of course, users should avoid calling |
@kolovos I think you are focusing on getting the count of expected elements in the sequence, that would not work for my case... and I don't see the added value vs what is available atm. My grudge is with the Sequence as a 'to' type. It makes the rule specification unclear (i.e. you need to read the code to know what is going into the sequence - the coin example with a single 'to' is not a good example to drive the discussion) . At least from what I need and perceive as improved syntax/semantics just giving the number of instances beforehand is not much of an improvement. |
ETL's default execution algorithm, which is used when there are no lazy rules, works in two phases. In the first phase, it goes through all the rules and creates empty target model elements from source elmenents, and in the second phase it executes the bodies of rules to populate the contents of target elements.
At the moment, after the first phase, the
It'd be useful to come up with an example that cannot be expressed concisely enough using the current syntax of ETL so that we can use it to discuss different solutions. |
We had a chat about this today, and we agree that initalizers on However, these would necessarily help with this 1:m..n scenario. Horacio has agreed to produce a minimal working example that illustrates the problem, that we can use to draft proposals to revise ETL to make those scenarios easier to work with. |
ETL natively supports
1:n
transformation rules. However, in some cases we can need1:m..n
rules, which I call runtime multiplicity, in which the actual number of output elements can not be determined until runtime.An example is a
port -> implements
relation between Ports and Interfaces, where the interface needs to be transformedm
times, wherem
is the number of ports that use the interface.Dimitris has provided an alternative:
This workaround works, but using the equivalents operation is uselss unless you define the rule as lazy.
The execution time of the lazy algorithm is much worse than the base one.
My prosal is to support 1:m..n rules natively.
The porposed syntax change adds a
foreach
keyword in which you specify a sequence statement.The size of the returned sequence (m) will be be used to instantiate m Tuples, each containg on set of target parameters.
CST Addiiton
With this the previous example would be
Note that the use of the for each keyword would result in a stack variable called loopVar that can be used in the rule.
When using the
equivalent(s)
operation you would get aList<Tuple<>>
. The tuple will contain all the targetPrams + the loopVar.In the ETL implementation
Since ETL already creates the output elements in a first pass, I think implementing this shuold not be to complex.
We would execute the foreach statement and create the list of tuples. When we get to the body we repeat it m times, replacing the stack variables as needed.
For more complex scenarios, the foreach could be a block, instead of a keyword:
This would allow to breakdown the sequence statement or collect elements from various places.
If something of interest, we can discuss more details and I can work on this (if @agarciadom is not too eager to jump and do it :) ).
The text was updated successfully, but these errors were encountered: