Standard Transformation Library

This section provides a list standard transformations provided out of the box.

Transformer Description
Aggregator Will summarize and aggregate data based on key fields you provide. Additionally, functions such as Count and Average are provided as these are commonly needed (see Aggregator -- Summarizing Data).
Sorter Will sort data based on key fields you provide (see Sorter -- Ordering Data).
Screener Will screen data based on filters you provide (see Screener -- Ordering Data).

Next section.

Aggregator -- Summarizing Data

Aggregator operates like a SQL "Group by" clause; it will consolidate records with like-valued keys. For example, if you aggregate the key "State" using an address input with United States addresses in it, the output will contain at most 50 values (one for the 50 states).

Aggregator supports deriving additional data during the aggregation process by supporting transformation functions. You can choose from the library of transformation functions we provide or write your own by implementing the Function interface. See Transformation Functions.

An example of usage is as follows:

Aggregator aggregator =new Aggregator();
aggregator.setTransformerDataSource( mySource );
aggregator.setTransformerDataTarget( myTarget );

aggregator.setAggregationKeys(new String[]{"lastName", "firstName", "middleInitial"});

aggregator.addFunction("totalCount", new Count());
aggregator.addFunction("minAge", new Minimum("age"));
aggregator.addFunction("maxAge", new Maximum("age"));
aggregator.addFunction("averageAge", new Average("age"));

Transform4j.runTransformation(aggregator);
				

See Aggregator javadoc.

Sorter -- Ordering Data

Sorter operates like a SQL "Order by" clause; it will order records according to the keys provided. There is no limit to the number of columns that can be provided.

Nulls are supposed to not have a value by definition. For the purposes of this sort, null values are sorted first for ascending sorts, and last for descending sorts.

An example of usage is as follows: This example will sort first by lastName in ascending order. For records with the same last name, will then use firstName in ascending order. For records with the same first and last names, will sort be age in descending order.

Sorter sorter =new Sorter();
sorter.setTransformerDataSource( mySource );
sorter.setTransformerDataTarget( myTarget );

sorter.setSortFields(new String[]{"lastName", "firstName", "age"});
sorter.setSortFieldDescending(new String[]{"age"});
Transform4j.runTransformation(sorter);
				

See Sorter javadoc.

Screener -- Filtering Data

Screener will copy to output only those records that satisfy the Filter you provide. Filters must implement Filter<DataRecord>. You can use the FilterCondition implementation provided by Transform4J or write your own.

FilterCondition supports the following operators and can be used to construct quite complex conditions:

  • Logical Operators -- AND, OR, NOT
  • Comparative Operators -- EQUALS, GREATER_THAN, GREATER_OR_EQUAL, LESS_THAN, LESS_OR_EQUAL
  • CONTAINS operator -- operator meant for Strings that will ensure a string field "contains" a specific value
  • Screener screener =new Sorter();
    screener.setTransformerDataSource( mySource );
    screener.setTransformerDataTarget( myTarget );
    
    Filter<DataRecord> filter = new FilterCondition("age", FilterCondition.Operator.GREATER_THAN, 14)
    	.and(new FilterCondition("middleInitial", FilterCondition.Operator.EQUALS, "C"));
    screener.setFilter(filter);
    Transform4j.runTransformation(screener);
    				

    See Screener javadoc.