One Star

[resolved] Checking my work with tAssert

I would like to have my TOS job check its aggregate results against the expected total. In other words, I have a tAggregateRow task that calculates the count of rows and the sum of one field, and would like to compare the calculated results with the data from another input source. If Talend's calculations match the expected results, then the job should succeed--otherwise it should fail or warn me somehow.
Is this possible to do with tAssert?
What I've figured out so far is: Since tAssert can only accept one input, I have to use some other component (tMap?) to make one set of results into variables. Then the tAssert expression should look something like this: "rowC.RecordCount==Var.calcRecordCount". But I can't find a way to make that work.
Any suggestions for me?
1 ACCEPTED SOLUTION

Accepted Solutions
Community Manager

Re: [resolved] Checking my work with tAssert

Hello
I have to use some other component (tMap?) to make one set of results into variables

Yes, you can use other component such as tJavaRow and set the results to context variables or global variables, and then use a tFixedFlowInput to generate a fixed value(expected value) and compare them with results on tAssert. eg:
tFileInputDelimited--tJavaRow--tMysqlOutput
|
tFixedFlowInput--row2-->tAssert
tAssertCatcher---tMysqlOutput
on tJavaRow:
context.RecordCount=context.RecordCount+1;
on expression of tAssert:
row2.RecordCount==context.RecordCount
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
3 REPLIES
Community Manager

Re: [resolved] Checking my work with tAssert

Hello
I have to use some other component (tMap?) to make one set of results into variables

Yes, you can use other component such as tJavaRow and set the results to context variables or global variables, and then use a tFixedFlowInput to generate a fixed value(expected value) and compare them with results on tAssert. eg:
tFileInputDelimited--tJavaRow--tMysqlOutput
|
tFixedFlowInput--row2-->tAssert
tAssertCatcher---tMysqlOutput
on tJavaRow:
context.RecordCount=context.RecordCount+1;
on expression of tAssert:
row2.RecordCount==context.RecordCount
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Checking my work with tAssert

Excellent. After some futzing with it, I've got it now. Thanks for the tips!
One Star

Re: [resolved] Checking my work with tAssert

Follow-up question: I have tried several ways to have the job fail/exit with an error code if the assertion fails, including the "Run if" trigger.
The only way I've found that works is to send the output of tAssertCatcher into a tFilterRow, and filter out all successes (where status field does not equal "Ok"), then send the filtered output into a tDie. Thus, nothing ever reaches the tDie unless an assertion fails.
But my method looks kind of funny... Is there a better way to trigger the tDie conditionally?