File translator

The file translator, known by the type name file, exposes stored procedures to leverage file resources. The translator is typically used with the TEXTTABLE or XMLTABLE functions to consume CSV or XML formatted data.

Table 1. Execution properties
Name Description Default

Encoding

The encoding that should be used for CLOBs returned by the getTextFiles procedure. The value should match an encoding known to Teiid. For more information, see TO_CHARS and TO_BYTES in String functions.

The system default encoding.

ExceptionIfFileNotFound

Throw an exception in getFiles or getTextFiles if the specified file/directory does not exist.

true

Tip
For information about how to set properties, see the following example, and Override execution properties in Translators.
Example: Virtual datbase DDL override
CREATE SERVER "file-override"
    FOREIGN DATA WRAPPER file
    OPTIONS(
        Encoding 'ISO-8859-1', "ExceptionIfFileNotFound" false
    );

CREATE SCHEMA file SERVER "file-override";

VDB XML Override Example

<model name="file">
    <source name="file" translator-name="file-override" connection-jndi-name="java:/file"/>
</model>

<translator name="file-override" type="file">
    <property name="Encoding" value="ISO-8859-1"/>
    <property name="ExceptionIfFileNotFound" value="false"/>
</translator>
getFiles
getFiles(String pathAndPattern) returns
TABLE(file blob, filePath string, lastModified timestamp, created timestamp, size long)

Retrieve all files as BLOBs matching the given path and pattern. The allowable path and pattern is a simplified glob syntax.

call getFiles('path/*.ext')

If the path is a directory, then all files in the directory are returned. If the path matches a single file, the file is returned.

The character is treated as a wildcard to match any number of characters in the path name. Multiple characters may be used in the path/pattern. To escape a character, use an additional - **. Note that "globstar" recursive directory searching is not supported as double star means a literal match instead.

If no files exist at the given path/pattern and ExceptionIfFileNotFound is true, then an exception is raised.

getTextFiles
getTextFiles(String pathAndPattern) returns
TABLE(file clob, filePath string, lastModified timestamp, created timestamp, size long)
Note
The size reports the number of bytes.

Retrieve all files as CLOBs matching the given path and pattern.

call getTextFiles('path/*.ext')

Retrieves the same files getFiles, but with the difference that the results are CLOB values that use the encoding execution property as the character set.

saveFile

Save the CLOB, BLOB, or XML value to given path

call saveFile('path', value)
deleteFile

Delete the file at the given path

call deleteFile('path')

The path should reference an existing file. If the file does not exist and ExceptionIfFileNotFound is true, then an exception will be thrown. An exception is also thrown if the file cannot be deleted.

JCA resource adapter

For configuration information, see File Data Source, the FTP Data Source, the HDFS Data Source, the S3 Data Source, and the Administrator’s Guide in general.

Note
Native queries
This feature is not applicable for the File translator.
Note
Direct query procedure
This feature is not applicable for the File translator.

results matching ""

    No results matching ""