Table of Contents

Search

  1. Preface
  2. Transformations
  3. Source transformation
  4. Target transformation
  5. Access Policy transformation
  6. Aggregator transformation
  7. B2B transformation
  8. Cleanse transformation
  9. Data Masking transformation
  10. Data Services transformation
  11. Deduplicate transformation
  12. Expression transformation
  13. Filter transformation
  14. Hierarchy Builder transformation
  15. Hierarchy Parser transformation
  16. Hierarchy Processor transformation
  17. Input transformation
  18. Java transformation
  19. Java transformation API reference
  20. Joiner transformation
  21. Labeler transformation
  22. Lookup transformation
  23. Machine Learning transformation
  24. Mapplet transformation
  25. Normalizer transformation
  26. Output transformation
  27. Parse transformation
  28. Python transformation
  29. Rank transformation
  30. Router transformation
  31. Rule Specification transformation
  32. Sequence transformation
  33. Sorter transformation
  34. SQL transformation
  35. Structure Parser transformation
  36. Transaction Control transformation
  37. Union transformation
  38. Velocity transformation
  39. Verifier transformation
  40. Web Services transformation

Transformations

Transformations

Using Java code to parse a flat file

Using Java code to parse a flat file

You can develop Java code to parse a flat file. Use Java code to extract specific columns of data from a flat file of varying schema or from a JMS message.
For example, you want to read the first two columns of data from a delimited flat file. Create a mapping that reads data from a delimited flat file and passes data to one or more output fields.
The mapping contains the following components:
Source transformation
The source is a delimited flat file. Configure the source to pass each row as a single string to the Java transformation. The source file contains the following data:
1a,2a,3a,4a,5a,6a,7a,8a,9a,10a 1b,2b,3b,4b,5b,6b,7b,8b,9b 1c,2c,3c,4c,5c,6c,7c 1d,2d,3d,4d,5d,6d,7d,8d,9d,10d
Java transformation
Define the Java transformation functionality in the Java editor.
Use the On Input Row section of the Java editor to read each input row and pass the first two fields to the output field, outputRow. Enter the following code in the On Input Row section:
// Collect the first two fields of the row and output them into outputRow. String[] rowsSplit = row.split(",", 3); if (rowsSplit.length >= 2) { outputRow = rowsSplit[0] + "," + rowsSplit[1]; } generateRow();
Target transformation
Configure the target to receive the output field, outputRow, from the Java transformation. After you run the mapping, the target file has the following data:
1a,2a 1b,2b 1c,2c 1d,2d

0 COMMENTS

We’d like to hear from you!