A local data file fails to be imported to a
Hive table by running the load data
local inpath Data file path into table Table name command.
As shown in Figure (a), after you run the load data local inpath ... command to import data, the import fails due to an error. The error is reported because the path /opt/liu/employee.txt is invalid. However, the file path exists on the tac3 node, as shown in Figure (b).
The local instruction specifies that the
path of the file to be imported must be on the local OMS active node. However,
the tac3 node where the data file is located is the standby node. As a result,
the data fails to be imported.
Upload the data file to a directory on the
active OMS node, and then run the load
data local inpath Data file path into table Table name command. However, the active/standby switchover occurs
on the OMS nodes in the big data cluster. Therefore, this method is not
recommended because it is unreliable. Some batch data importing methods are
described as follows:
Save the data file in an HDFS directory and
then import the file to prevent the local instruction from being used.
dfs -put Data
file path HDFS
data inpath HDFS
The Hive table is stored in the /user/hive/warehouse/ directory of the
HDFS. Therefore, you can directly import the data file to the corresponding
Hive table in the HDFS.
dfs -put Data
file path /user/hive/warehouse/ Table name
The following figure shows that the data is
successfully imported to the employee_huawei table.
[root@tac3 liu]# hdfs dfs -put employee.txt
Use the Loader component to establish an
SFTP connection and import data files to the Hive table in the HDFS.
Active/standby switchover is required for
OMS nodes in the big data cluster, therefore, you are not advised to use the load data local inpath Data file path into table Table name command to import data to the Hive table. You are advised to use the PUT method
described in method 2 to import data. This method is simple and effective, and
the local instruction does not need to be used.