If statement in trasformation of ExtMergeJoin

Like a few other developers on this forum, I’m struggling to successfully use an if statement within the transformation of my ExtMergeJoin.

Presently I have the following:

if (isnull($in.1.Amt)) {
return 0;
} else {
return ($in.0.Percent * $in.1.Amt);
}

I’ve tried writing to the output. I’ve tried shortening the statement. I’ve tried using iff().

Regardless of what I try, I always receive an error on the if with a note to “delete the token.”

Can someone shed some light on what it is I’m doing wrong? Any help/feedback would be greatly appreciated.

Hi,

First of all you should keep in mind that mapping cannot be done in return statement, which is used for output port selection. Your example might look like this (of course I don’t know your metadata on output port):


function integer transform() {
	// If $in.1.Amt is null then put NULL into output field SomeOutputField
	// Otherwise set $in.1.Amt = ($in.0.Percent * $in.1.Amt)
	$out.0.SomeOutputField = isnull($in.1.Amt) ? null : ($in.0.Percent * $in.1.Amt);
	return ALL;
}

Also you should keep in mind, the transform() is supposed to return integer. This integer value is actually always the port number (0, 1, 2, … , 2147483647) with one exception - that is number 2147483647, which stands for all ports. Let me give you an example:


function integer transform() {
	$out.0.yourOutputField= $in.0.yourInputField;
	$out.1.yourOutputField= $in.0.yourInputField;
	return 1;
}

The first two row of the transform function map data to both output ports (0, 1). However, on the third line, there is “return 1”, which means data will actually be sent only to the output port number 1 (which is the second output port). That means although you have defined some mapping for the first output port (output port number 0), data is not send to this port since using the return statement you decided to use only the second output port. If you would like to send data to both ports, you would have use one of these values: 2147483647, ALL.
For more information on this topic please refer to Return Values of Transformations chapter of this article in our documentation.

Hope it helps.