Impala with HDFS
Although Impala typically works well with many large files in an HDFS storage system, there are times when you might perform some file cleanup to reclaim space, or advise developers on techniques to minimize space consumption and file duplication.
- Use compact binary file formats where practical. Numeric and
time-based data in particular can be stored in more compact form in
binary data files. Depending on the file format, various compression and
encoding features can reduce file size even further. You can specify the
STORED AS
clause as part of theCREATE TABLE
statement, orALTER TABLE
with theSET FILEFORMAT
clause for an existing table or partition within a partitioned table. -
You manage underlying data files differently depending on whether the corresponding Impala table is defined as an internal or external table:
- Use the
DESCRIBE FORMATTED
statement to check if a particular table is internal (managed by Impala) or external, and to see the physical location of the data files in HDFS. - For Impala-managed (
internal
) tables, useDROP TABLE
statements to remove data files. - For tables not managed by Impala (
external
) tables, use appropriate HDFS-related commands such ashadoop fs
,hdfs dfs
, ordistcp
, to create, move, copy, or delete files within HDFS directories that are accessible by theimpala
user. Issue aREFRESH table_name
statement after adding or removing any files from the data directory of an external table. - Use external tables to reference HDFS data files in their original location. With this technique, you avoid copying the files, and you can map more than one Impala table to the same set of data files. When you drop the Impala table, the data files are left undisturbed.
- Use the
LOAD DATA
statement to move HDFS files into the data directory for an Impala table from inside Impala, without the need to specify the HDFS path of the destination directory. This technique works for both internal and external tables.
- Use the
- Make sure that the HDFS trashcan is configured correctly. When you remove files from HDFS, the space might not be reclaimed for use by other files until sometime later, when the trashcan is emptied.
- Drop all tables in a database before dropping the database itself.
- If an
INSERT
statement encounters an error, and you see a directory named .impala_insert_staging or _impala_insert_staging left behind in the data directory for the table, it might contain temporary data files taking up space in HDFS. You might be able to salvage these data files.For example, delete those files through commands such as
hadoop fs
orhdfs dfs
to reclaim space before re-trying theINSERT
. IssueDESCRIBE FORMATTED table_name
to see the HDFS path where you can check for temporary files.
Configuring Scratch Space for Spilling to Disk
Impala uses intermediate files during large sorts, joins, aggregations, or analytic function operations The files are removed when the operation finishes. By default, intermediate files are stored in the directory /tmp/impala-scratch.
- By starting the impalad daemon with the
‑‑scratch_dirs="path_to_directory"
configuration option. - By specifying a different location in the Cloudera Manager in the Impala Daemon Scratch Directories field.
- You can specify a single directory or a comma-separated list of directories.
- You can specify an optional a capacity quota per scratch
directory using the colon (:) as the delimiter.
The capacity quota of
-1
or0
is the same as no quota for the directory. - The scratch directories must be on the local filesystem, not in HDFS.
- You might specify different directory paths for different hosts, depending on the capacity and speed of the available storage devices.
If there is less than 1 GB free on the filesystem where that directory resides, Impala still runs, but writes a warning message to its log.
Impala successfully starts (with a warning written to the log) if it cannot create or read and write files in one of the scratch directories.
Config option | Description |
---|---|
--scratch_dirs=/dir1,/dir2
|
Use /dir1 and /dir2 as scratch directories with no capacity quota. |
--scratch_dirs=/dir1,/dir2:25G
|
Use /dir1 and /dir2 as scratch directories with no capacity quota on /dir1 and the 25GB quota on /dir2. |
--scratch_dirs=/dir1:5MB,/dir2
|
Use /dir1 and /dir2 as scratch directories with the capacity quota of 5MB on /dir1 and no quota on /dir2. |
--scratch_dirs=/dir1:-1,/dir2:0
|
Use /dir1 and /dir2 as scratch directories with no capacity quota. |
Allocation from a scratch directory will fail if the specified limit for the directory is exceeded.
If Impala encounters an error reading or writing files in a scratch directory during a query, Impala logs the error, and the query fails.