Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Sunday, February 2, 2014

BRules Padding Routines Usage

This describes the usage of some pad() methods available to Talend Open Studio users who have added BRules to their installation

BRules is a collection of validation, formatting, and logic Routines for use in Talend Open Studio.  The 1.4.0 release (scheduled for Feb 2, 2014) introduces several pad() methods for padding strings and other datatypes.  The implementation delegates to the popular Commons Lang StringUtils class.

While the pad() methods of StringUtils can be used in a Talend Open Studio job by loading the Commons Lang JAR with a tLibraryLoad, BRules' pad() methods reduce the amount of variable setup you might need when making the call.

For example, take the following snippet of Java code that might appear in a tMap cell

  (row1.field1!=null)?StringUtils.leftPad(String.valueOf( row1.field1 ), 6, '0'):null

With BRules, this is reduced to

  BRules.pad(row1.field1, 6, '0')

This is possible because BRules overloads the pad, avoiding the need for beforehand conversions.   Java's Auto Boxing support also let's the same code handle primitive types.  The != null check would not be allowed for "int" or "long" calls.

This Talend Open Studio Job shows a tMap with three variations of the pad(string,int,char) method for three different data types: String, Integer, and Long.

Talend Open Studio Job Showing pad() Calls from BRules
While it might be a minor hassle to install a new component to save a few keystrokes in a job, code savings offered by BRules can be substantial over the course of a project, particularly if many fields need to be padded in a tMap schema.  In such a case, it's easier to visually scan the mapping column if the syntax is reduced.  You might find that there is so much null-checking and other setup that you have to drill into each and every cell during troubleshooting.

No comments:

Post a Comment