|
|
|
|
Re: ETL models [message #1852915 is a reply to message #1852914] |
Fri, 10 June 2022 13:36 |
|
Hi Alireza,
Please find a minimal example below.
EtlModule m = new EtlModule();
m.parse("rule A2B transform a : In!A to b : Out!B { b.name = a.name; }");
// Get the first rule of the transformation
TransformationRule a2b = m.getTransformationRules().get(0);
// Print its name
System.out.println(a2b.getName());
// Get the body of the A2B rule
StatementBlock body = (StatementBlock) a2b.getBody().getBody();
// Print the number of statements it contains
System.out.println(body.getStatements().size());
Best,
Dimitris
[Updated on: Fri, 10 June 2022 13:36] Report message to a moderator
|
|
|
|
|
|
|
Re: ETL models [message #1852944 is a reply to message #1852943] |
Sun, 12 June 2022 08:47 |
|
Hi Alireza,
I note that several of the projects in your workspace are closed which could be related to the issue you are facing. In any case, debugging over screenshots is not ideal so could you please share with me a minimal example I can use to reproduce the issue you are encountering?
Best,
Dimitris
|
|
|
|
|
|
Re: ETL models [message #1853009 is a reply to message #1853005] |
Tue, 14 June 2022 15:27 |
|
To parse a file you need to pass a File object to the parse method. Something in the lines of
File eltFile = new File("/some/path/to/Sample.etl");
m.parse(etlFile);
Since you are executing from java, you ned to make sure that the etl file can be found. Using paths to load files is error prone, so I would suggest finding the file as a resource.
Assuming that Sample.etl is in the same package as your EtlMParser class (from yoor screenshot), then do:
URL url = getClass().getResource("Sample.etl");
File file = new File(url.getPath());
m.parse(etlFile);
Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
|
|
|
|
|
Re: ETL models [message #1853134 is a reply to message #1853120] |
Mon, 20 June 2022 05:48 |
|
Hi Alireza,
TransformationRule, StatementBlock etc. are mutable so e.g. to add a new statement at the end of the rule you could use the following snippet:
body.getStatements().add(new ExpressionStatement(
new OperationCallExpression(new StringLiteral("Executed rule A2B"),
new NameExpression("println"))));
// Optional - to see the ETL source of the modified transformation
System.out.println(new EtlUnparser().unparse(m));
Best,
Dimitris
|
|
|
|
|
Re: ETL models [message #1853137 is a reply to message #1853136] |
Mon, 20 June 2022 06:13 |
|
You could save the result of "new EtlUnparser().unparse(m)" to your ETL file. Any comments in your original transformation won't be preserved and indentation may be different, however, the generated source should be valid ETL (if not, please raise an issue in the Bugzilla).
Best,
Dimitris
|
|
|
|
Re: ETL models [message #1854343 is a reply to message #1853138] |
Mon, 15 August 2022 11:57 |
Alireza Rouhi Messages: 148 Registered: December 2015 |
Senior Member |
|
|
Hi All,
I would like to extract assignment expressions in rules/operations (AS Strings) of an ETL source file.
I want to count the number of tokens in the mentioned assignment expressions for refactoring purposes.
Is there any trick to do this? Thanks a million.
Alireza
[Updated on: Mon, 15 August 2022 11:58] Report message to a moderator
|
|
|
Re: ETL models [message #1854365 is a reply to message #1854343] |
Tue, 16 August 2022 10:01 |
|
Hi Alireza,
(EDITED: I did make the silly mistake of suggesting rule.visit(...) instead of rule.accept(...). Sorry!)
I would suggest these steps:
* Parse the ETL file into an EtlModule.
* Loop over the elements of module.getTransformationRules().
* For each rule, use rule.accept(visitor), where visitor should be an IEtlVisitor implementation of your
own. You will most likely want to do something in the visit(AssignmentStatement) method to
capture the assignment you are visiting.
Note that we do not store the ANTLR AST objects in the ETL DOM, so you won't have access to the
original tokens from the visitor. Still, you can just have all other visitor methods increment a counter
when you are inside an assignment, so you will have a measure of the size of the subtree of the
DOM rooted at that assignment (which would still give you a measure of complexity).
Best,
Antonio
[Updated on: Thu, 18 August 2022 15:12] Report message to a moderator
|
|
|
|
Re: ETL models [message #1854370 is a reply to message #1854367] |
Tue, 16 August 2022 12:04 |
Alireza Rouhi Messages: 148 Registered: December 2015 |
Senior Member |
|
|
Dear Antonio,
I tried to follow your suggested steps. My source code is as follows. I do not get my expected result. For example, I like to get 13 for the expression
(1 - s.risk) * (s.shares -> collect(x | x.price * x.quantity) -> sum())
while the code output is 2 instead!
EtlModule module = new EtlModule();
module.parse(EpsilonStandalone.class.getResource("Sample.etl").toURI());
module.getTransformationRules();
for (int i = 0; i < module.getTransformationRules().size(); i++)
{
TransformationRule rule = module.getTransformationRules().get(i);
.
.
.
StatementBlock body = (StatementBlock) rule.getBody().getBody();
for (int c = 0; c < body.getStatements().size(); c++)
{
if (body.getStatements().get(c).getClass().getName().contains("Assignment")) {
int MEL = IEtlVisitor.visit(body.getStatements().get(c));
System.out.println(", (MEL = " + MEL + ")");
}
}
}
and my visit method is as follows:
public interface IEtlVisitor extends IErlVisitor{
//public void visit(TransformationRule transformationRule);
public static int visit(Statement statement) {
return statement.getArguments().length;
}
public static int visit(org.eclipse.epsilon.eol.dom.Statement statement) {
return statement.getChildren().size();
}
}
Is there any trick to correct the above code?
Thanks a lot
Alireza
[Updated on: Thu, 18 August 2022 04:48] Report message to a moderator
|
|
|
Re: ETL models [message #1854433 is a reply to message #1854370] |
Thu, 18 August 2022 12:55 |
|
Hi Alireza,
getChildren() only gives you the direct children, not all the descendants. That's why I suggested incrementing a counter instead (e.g. ++size) whenever you visit any other DOM node from inside an assignment.
Best,
Antonio
|
|
|
|
Re: ETL models [message #1854438 is a reply to message #1854434] |
Thu, 18 August 2022 15:14 |
|
By the way, I just realised that I made the silly mistake of asking you to do rule.visit(visitor), when it should have been rule.accept(visitor). I was closing down things before the holidays and it slipped my mind!
I think you mentioned it in a previous version of one of your messages :-).
IEtlVisitor implements the Visitor design pattern, as described here: https://refactoring.guru/design-patterns/visitor
|
|
|
Re: ETL models [message #1854439 is a reply to message #1854438] |
Thu, 18 August 2022 15:15 |
|
The idea is that you ask the rule to "accept" the visitor (like accepting a visitor into your house), and then the rule will walk the visitor through its subtree of the DOM (repeatedly calling the various "visit" methods, like visiting the LivingRoom, the Kitchen, the Bedroom and so on).
[Updated on: Thu, 18 August 2022 15:16] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.05679 seconds