Working with files
Applications and operators can read and write to files in several ways. If
relative paths are used, the data directory is used as the root of relative
paths. To enable logic to access the runtime application or toolkit directory
hierarchies, language-specific functions can be used.
If your application reads or writes data to relative paths, the data directory is used as the root of relative paths. For example, relative path files that are specified in the file parameter of FileSource or FileSink operators will use the data directory. You must define a data directory either at compile time, with the --data-directory option, or submission time with the -C data-directory option; otherwise, compilation or submission may fail.
Warning: There is no default data directory and the
compiler will not create one. Additionally, the data directory must exist before running
the application.
Accessing files from within an application
Applications and operators can retrieve the location of the runtime application
directory hierarchy using the following functions:
- SPL - getApplicationDir()
- C++ and Python primitive operators - getApplicationDirectory()
- Java primitive operators - getApplicationDirectory()
If operators need to access files at runtime relative to their toolkit directory
instead of the application directory, the following functions can be used:
- SPL - getThisToolkitDir()
- C++ and Python primitive operators - getToolkitDirectory()
- Java primitive operators - getToolkitDirectory()
The paths returned by these functions can vary from host to host depending on where the SAB is unbundled.