Transformations > Java transformation > Java transformation fields
  

Java transformation fields

A Java transformation has incoming fields and output fields. Use incoming and output fields as variables in the Java code snippets that you define on the Java tab.
Incoming fields appear on the Incoming Fields tab. By default, the Java transformation inherits all incoming fields from the upstream transformation. If you do not need to use all of the incoming fields, you can define field rules to include or exclude certain fields. For more information about field rules, see Field rules.
Add output fields on the Output Fields tab. Add output fields for the output data that you want to pass to the downstream transformation. To add a field, click Add Field, and then enter the field name, data type, precision, scale, and optional description. The description can contain up to 4000 characters. You can also create output fields on the Outputs tab of the Java editor by clicking Create New Field.
The Java transformation initializes output field values based on the following field data types:

Data type conversion

A Java transformation converts Data Integration transformation data types to Java data types, based on the Java transformation field type.
When a Java transformation reads input rows, it converts input field data types to Java data types. When a Java transformation writes output rows, it converts Java data types to output field data types.
For example, the following processing occurs for an input field with the integer data type in a Java transformation:
  1. 1The Java transformation converts the integer data type of the input field to the Java primitive int data type.
  2. 2In the transformation, the transformation treats the value of the input field as the Java primitive int data type.
  3. 3When the transformation generates the output row, it converts the Java primitive int data type to the integer data type.
The following table shows how the Java transformation maps the Data Integration transformation data types to Java primitive and complex data types:
Transformation data type
Java data type
bigint
long
binary
byte[]
date/time
BigDecimal
long (number of milliseconds since January 1, 1970 00:00:00.000 GMT)
decimal
double
BigDecimal
double
double
integer
int
string
String
text
String
In Java, the String, byte[], and BigDecimal data types are complex data types, and the double, int, and long data types are primitive data types.
The Java transformation sets null values in primitive data types to zero. You can use the isNull and the setNull API methods in the On Input Row section of the Java editor to set null values in the input field to null values in the output field. For an example, see setNull.
When you configure the Java transformation, you can convert the date/time data type to BigDecimal or to long. BigDecimal has nanosecond precision while long has millisecond precision. For more information, see Configuring Java transformation properties.
The decimal data type maps to BigDecimal when high precision is enabled. BigDecimal cannot be used with some operators, such as the + operator. If the Java code contains an expression that uses a decimal field and the field is used with one of the operators, the Java code fails to compile.

Sort conditions

In advanced mode, you can configure a sort condition to specify the sort fields and the sort order. The mapping task uses the sort condition to sort the data before the Java code runs.
The sort fields are one or more fields that you want to use as the sort criteria. Configure the sort order to sort data in ascending or descending order.
If you configure a sort condition for data that is grouped into partitions, the mapping task sorts the data in each partition.
When you specify multiple sort conditions, the mapping task sorts each condition sequentially. The mapping task treats each successive sort condition as a secondary sort of the previous sort condition. You can configure the order of sort conditions.
If you use a parameter for the sort condition, define the sort fields and the sort order when you run the mapping or when you configure the mapping task.

Group by fields

In advanced mode, you can use group by fields to define how to group data into partitions before the Java code runs.
When you configure a group by field, the mapping task groups rows with the same data into a partition. Then, the Java code runs for each partition in the transformation. For example, the input row behavior is processed for each partition and each row in the partition, and the end of data behavior is processed for each partition after processing all rows in the partition.
When you select more than one group by field, the task creates a partition for each unique combination of data in the group by fields.
If you do not configure a group by field, the Java code runs based on the data's default partitioning scheme.
If you use a parameter for the group by fields, define the group by fields when you run the mapping or when you configure the mapping task.