Example scenario for using a functional map

An example of a functional map is shown below.

A data file contains statistics for different kinds of cars. Each record in the file represents a car. For each car, there are fields for mileage, head room, rear seat, trunk room, and weight. Each field is padded to a specific length. The record is fixed. For example:

Marlin         22   2   27   11   2930
Pacer ZSX      17   3   26   11   3350
Wildcat        22   3   18   12   2640
Fantasia DX    17   3   27   15   2830
La Vella       23   2   28   11   2070
Blue Baron     25   2   26   12   2650
Cavalino       20   4   29   16   3250

The objective is to map this data to a file containing delimited records. The delimited record has only the car name and the weight. In the delimited record, the weight is in decimal format. The desired output data result is:

Marlin,29.30
Pacer ZSX,33.50
Wildcat,26.40
Fantasia DX,28.30
La Vella,20.70
Blue Baron,26.50
Cavalino,32.50

You want to generate one delimited record for each fixed record in the input file.

Input data Output data
Marlin         22   2   27   11   2930
Marlin,29.30
Pacer ZSX      17   3   26   11   3350
Pacer ZSX,33.50
Wildcat        22   3   18   12   2640
Wildcat,26.40
Fantasia DX    17   3   27   15   2830
Fantasia DX,28.30
La Vella       23   2   28   11   2070
La Vella,20.70
Blue Baron     25   2   26   12   2650
Blue Baron,26.50
Cavalino       20   4   29   16   3250
Cavalino,32.50

Define the map rule for the output CarRecord(s), with a range of (s).There is an indefinite number of CarRecord(s).

Ask yourself "How many CarRecord(s) do I want to generate?" If you want a specific number, the answer would be that number. To generate two CarRecord(s), index two occurrences of CarRecord, expand each occurrence, and map to its components. For more information on indexing, see "Indexing an Output".

If the number of CarRecord(s) is based on the number of FixedRecord(s) in the input, generate one CarRecord for each FixedRecord. So, the answer to your question of how many CarRecord(s) to generate is, "As many as there are FixedRecord(s) in the input."

Note: When you see an output group with a range, it is always a good idea to stop and ask yourself, "How many of these do I want to generate?" The answer will either be:

You need a mechanism that takes a single FixedRecord and creates a single CarRecord. To do this, create a functional map, which is similar to a user-defined function. This functional map maps a single FixedRecord to a single CarRecord. The map is called for every occurrence of a FixedRecord in the input. This generates exactly one CarRecord for each FixedRecord.

For example, if there are 23 FixedRecord(s), 23 CarRecord(s) are generated. The first CarRecord corresponds to the first FixedRecord. The second CarRecord corresponds to the second FixedRecord, and so on.