Mappers provide a mechanism to specify the layout of mapped datasets on disk. This is needed when Swift must access files to transfer them to remote sites for execution or to pass to applications.
Swift provides a number of mappers that are useful in common cases. This section details those mappers. For more complex cases, it is possible to write application-specific mappers in Java and use them within a Swift script.
The Single File Mapper
The single_file_mapper maps a single physical file to a dataset.
|file||The location of the physical file including path and file name.|
There is a simplified syntax for this mapper:
The Simple Mapper
The simple_mapper maps a file or a list of files into an array by prefix, suffix, and pattern. If more than one file is matched, each of the file names will be mapped as a subelement of the dataset.
|location||A directory that the files are located.|
|prefix||The prefix of the files|
|suffix||The suffix of the files, for instance: ".txt"|
|padding||The number of digits used to uniquely identify the mapped file. This is an optional parameter which defaults to 4.|
|pattern||A UNIX glob style pattern, for instance: "*foo*" would match all file names that contain foo. When this mapper is used to specify output filenames, pattern is ignored.|
The above maps all filenames that start with foo and have an extension .txt into file f.
This will output the string hi to the file foo.txt.
The simple_mapper can be used to map arrays. It will map the array index into the filename between the prefix and suffix.
|Swift variable||File name|
simple_mapper can be used to map structures. It will map the name of the structure member into the filename, between the prefix and the suffix.
This will output the string "hello" into the file qux.left.txt and the string "goodbye" into the file qux.right.txt.