using Joblets in talend with tMemorize and tJavaFlex

僤鯓⒐⒋嵵緔 提交于 2019-12-13 04:54:45

问题


I am trying to create some joblets in Talend that will speed up some processes. I have an input from a MSSQLInput, the results are then sorted and filtered a little. Then I have a tMemorizeRows and a tJavaFlex, the purpose of this is to memorize the rows in a column to preform a count. The count is based on a customer ID, once the the id changes the count starts back to 1 and the proccess begine again and continues to the end. I have refactored this as a joblet but it does not work, the error is:

ID_tMemorizeRows_1 cannot be resolved to a variable

I have a tJavaFlex which starts with

int counte = 1;

The Main code is

if(ID_tMemorizeRows_1[0].equals(ID_tMemorizeRows_1[1]))
{
counte = counte + 1; 
} 
else 
{ 
counte = 1; 
} 
context.Enqnum = counte;

The Enqnum variable and is created correctly and added into a tMaps component.

Does anyone know why this is happening, one person told me it is because when you move something to a joblet it gets a new/different name so it has to be specifically called in the Java, if this is the case how do I find the name out?

Thank you Rich


回答1:


I do have a resolution. I have tried to add images however my reputation is not high enough.

When using joblets we know that Talend essentially recycles the code used in the joblet by inserting it into the code for the main job.

This is the joblet I have created, i know it works because I have refactored it to a joblet instead of building it from sctatch. What its doing is simply memorises row 0 and row 1 in an ordered data set, the java performs a count and the tMap appends the result to the job (as Mentioned above).

(I will try it inser image in my question, I do not have enough reputation point to insert it into a question).

When the job is run it runs fine. But problems occur when I want to reuse the same joblet in another part of the job. What Talend does is it assigns names within the source code to each component depending on the name of the joblet. For example, if the Joblet was called ThisJob, then tMemorizeRows_1 would be called ThisJob_1_tMemorizeRows_1. The row within the component (in this example ReferenceID) would renamed as: ReferenceID_ThisJob_1_tMemorizeRows_1.

But when you add a second joblet to your job it gives it a new name, eg ThisJob_2. This name will be different depending on how much you have been altering your job before you add the second joblet. Therefore the number within the name will depend on this activity.

If you add the joblet into your job immediately then the joblet would be called ThisJob_2, if you have added 5 other components before you add it in then the joblet is likely to be called ThisJob_6 etc. (I'm not 100% sure how talend renames components)

When you add a joblet, You can see the name of the joblet on the joblet component, this then reverts back the the original joblet name when you create any links/joins to other components.

Its also important that each component within the code is assigned to a variable called currentComponent.

Resolution

What I did was used the Java code to split the name using the code below. This way I can get the current name of the of the joblet and use this name in my Java.

String string = currentComponent;
String[] parts = string.split("_");
String part1 = parts[0];
String part2 = parts[1];
String joblet = part1+'_'+part2;
String newrow = "ReferenceID_"+joblet+"_tMemorizeRows_1";

I hope this makes sense. Thanks



来源:https://stackoverflow.com/questions/29651501/using-joblets-in-talend-with-tmemorize-and-tjavaflex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!