File I/O Operations

1 document

Apache Hive : HPL/SQL - UTL_FILE Package

UTL_FILE package allows you to read and write HDFS files:

Example:

DECLARE
  f UTL_FILE.FILE_TYPE;
BEGIN
  f := UTL_FILE.FOPEN('/user/dm', 'hello.txt', 'w');
  UTL_FILE.PUT_LINE(f, 'Hello, world!');
  UTL_FILE.FCLOSE(f);
END;

In this example we create /user/dm/hello.txt in HDFS, write a single line and close the file.

UTL_FILE.FILE_TYPE Type

Before you can work with a file using UTL_FILE package you have to declare a variable of UTL_FILE.FILE_TYPE. You assign a value to this variable using UTL_FILE.FOPEN function and then use it in all other functions as an argument.