Handle error in reformat component

Hi every body !

I use the “reformat” component to process transformations on DataRecord thanks to a java class. These transformations could fail, so I would send failing record in a second output port, something like that (pseudo code, output port 0 = transformation OK, output port 1 = error encountered) :

try {
(outputRecords[0].getField(0)).setValue( transformation(inputRecords[0].getField(0).toString() ));
etc.
} catch (transformationException te) {
outputRecords[1].copyFrom(inputRecords[0]);
}

My problem is that I don’t want to send anything to outpu port 0 if I find an error, and conversely I don’t want to send anything to outpu port 0 if the process goes fine. outputRecords[0].setToNull() is not a solution, some field are required (nullable=false).

Is their a solution to do that with the standard reformat component, or should a develop my one ?

Thanks for your help (and sorry for my english).

Yes, this is a simple work around for my secific problem. I posted it just as an information, to say that my work goes on, and the way it goes.
In fact I encounter the problem you discribe : I needed to remove the “not nullable” attribute of metadata to have this solution works. The nullity check of source data is made before, in a “normalizer” component.

Well, it’s just a (perfectible) tips for my problem, and it is cool that it rises some response. Of course, I eventually search a better solution :slight_smile:

Francois

What if the interface definition of RecordTransform would change to return not false-true but number.
That could be used like this:

-1 (or negative number) - error
0 - O.K. send the out records
>0 (positive number) indicates the one output port through which data will be sent (all others receives nothing)

Anyway, this is more a development discussion - we should move it to different forum.

David

Ok, I find a solution replacing this code in Reformat :
---------
if (transformation.transform(inRecord, outRecord)) {
for(outPort=0;outPort<numOutputPorts;outPort++){ writeRecord(outPort, outRecord[outPort]);
}
}
}// skip record if transformation returned false
---------
By this one :
----------
if (transformation.transform(inRecord, outRecord)) {
for(outPort=0;outPort<numOutputPorts;outPort++){
if(!outRecord[outPort].isNull()) {
writeRecord(outPort, outRecord[outPort]);
}
}
}// skip record if transformation returned false
----------
And in the java transformation class, if a transformation fails, I set the standard (0) output to null thanks to outputRecord[0].setToNull() and copy input to the error output (1).

If it may help others…

Hello,
this solution could be suitable for your proprietary issue, but isn’t generally recommended, for DataRecord.setToNull() could throw NullPointerException if some field is not nullable and simultaneously has not default value defined. In short, this way is not possible for some type of metadata.

Martin