Updated on 2022-06-01 GMT+08:00

Loading Data

Function Description

This section describes how to use HiveQL to load data to the existing employees_info table. You can learn how to load data from a cluster.

Sample Code

--Load the employee_info.txt file from the /opt/hive_examples_data/ directory of the local file system to the employees_info table.
LOAD DATA LOCAL INPATH '/opt/hive_examples_data/employee_info.txt' OVERWRITE INTO TABLE employees_info;

-- Load /user/hive_examples_data/employee_info.txt from HDFS to the employees_info table.
LOAD DATA INPATH '/user/hive_examples_data/employee_info.txt' OVERWRITE INTO TABLE employees_info;   

The essence of loading data is to copy the data to the specified table directory in HDFS.

The LOAD DATA LOCAL INPATH command can be used to load files from a local file system to Hive. If LOCAL is specified, the path refers to the path of the local file system of the currently connected HiveServer. However, HiveServers are deployed in a cluster, and the client is randomly connected to one of all HiveServers. Therefore, you need to check whether files to be loaded exist in the local file system of the connected HiveServer. If you cannot determine which HiveServer is connected, you are advised to save the corresponding files in all HiveServer paths, and check whether the file permissions are correct.