For the complete documentation index, see llms.txt. This page is also available as Markdown.

Text File Output

Output text files ..

Workshop - Text File Output


Workshop files

Download the following files.

Keep the filenames unchanged.

Save them in your workshop folder.

Open

Survey - Text File Output

Create a new transformation

Use any of these options to open a new transformation tab:

  • Select File > New > Transformation

  • Use Ctrl+N (Windows/Linux) or Cmd+N (macOS)


Get System Info

Use Get System Info to read a runtime argument. We will treat the argument as the customer name.

Get System Info
  1. Start Pentaho Data Integration (Spoon).

  1. Drag Get System Info onto the canvas.

  2. Double-click the step. Configure it like this:

Get system info
  1. Select OK.

User Defined Java Expression

Use User Defined Java Expression to format the header line. It will combine a label with the customer name.

  1. Drag User Defined Java Expression onto the canvas.

  2. Create a hop from Get System Info.

  3. Double-click the step. Configure it like this:

UDJE
  1. Select OK.

This replaces the original argument value with formatted text. The output field is still named text.

Link to Operators

Data Grid

Use Data Grid to add static survey header lines. This keeps the top-of-file content inside the transformation.

Configure the field metadata on Meta. Enter the rows on Data.

  1. Drag Data Grid onto the canvas.

  2. Double-click the step. Configure it like this:

Data grid - text
Data grid - data
  1. Select OK.

Append streams

Use Append streams when order matters. It outputs all rows from the first hop. It then outputs all rows from the second hop.

Both input streams must have the same field names and types.

  1. Drag Append streams onto the canvas.

  2. Create hops from User Defined Java Expression and Data Grid.

  3. Double-click the step. Configure it like this:

Append
  1. Select OK.

To append streams, keep the layout consistent. In this workshop, every stream uses a single text field.

If order does not matter, use a step that performs a union of streams instead.

Text file input

Use Text file input to read the question list from a file. Each question becomes one row.

  1. Drag Text file input onto the canvas.

  2. Double-click the step. Configure it like this:

Text file input

File: ${Internal.Transformation.Filename.Directory}/questions.txt

Text file input - Content

Use a Tab delimiter. Enable row numbers to generate question numbers.

  1. On Fields, rename the output field to text:

Text file input - Fields
  1. Select OK.

Each row now contains a question in text. The row number field (for example question_num) identifies the question number.

User Defined Java Expression

Use a second User Defined Java Expression to prefix each question line with its question number.

  1. Drag User Defined Java Expression onto the canvas.

  2. Create a hop from Text file input (questions).

  3. Double-click the step. Configure it like this:

UDJE - concat question numbers
  1. Select OK.

This overwrites text with a numbered question like 1. How did we do?.

Select values

The Select Values step is useful for selecting, removing, renaming, changing data types and configuring the length and precision of the fields on the stream.

These operations are organized into different categories:

  • Select and Alter — Specify the exact order and name in which the fields should be placed in the output rows

  • Remove — Specify the fields that should be removed from the output rows

  • Meta-data — Change the name, type, length, and precision (the metadata) of one or more fields

  1. Drag Select values onto the canvas.

  2. Create a hop from User Defined Java Expression (number questions).

  3. Double-click the step. Configure it like this:

Select values - remove question_num
  1. Select OK.

Remove the question number field so both streams have the same layout. You need a single text field before you append.

Append streams

Append the survey header stream to the numbered question stream.

  1. Drag Append streams onto the canvas.

  2. Create hops from Append streams (head) and Select values.

  3. Double-click the step. Configure it like this:

Append
  1. Select OK.

You now have one stream. It contains one field named text.

Text file output

Use Text file output to write the survey file to disk.

  1. Drag Text file output onto the canvas.

  2. Create a hop from Append streams (body).

  3. Double-click the step. Set the file name:

Filename: ${Internal.Transformation.Filename.Directory}/survey

Set Extension to txt if your output should be survey.txt.

Text file output - Content
  1. On Fields, select Get Fields.

Text file output - Fields
  1. Select OK.

Run the transformation

Run the transformation locally. Pass a customer name as an argument.

  1. Select Run in the canvas toolbar.

  2. Open Arguments (legacy). Enter a customer name.

Enter argument
  1. Select Run.

  2. Open the Preview data tab.

Preview data
  1. Open the generated survey file in your transformation folder.

This workshop reinforces the rule for merging streams:

  • Keep the same field layout (names and order).

  • Keep matching data types.

Last updated

Was this helpful?