将数据从HDFS复制到Hive中的外部表时出错

时间:2018-07-03 05:44:55

标签: hadoop hive

我正在尝试将数据从hdfs插入到Hive中的外部表中。但出现错误。

错误:

Usage: java FsShell [-put <localsrc> ... <dst>]
Command failed with exit code = 255

命令

hive> !hadoop fs -put /myfolder/logs/pv_ext/2013/08/11/log/data/Sacramentorealestatetransactions.csv
    > ;

编辑:

file location : /yapstone/logs/pv_ext/somedatafor_7_11/Sacramentorealestatetransactions.csv

table location : hdfs://sandbox:8020/yapstone/logs/pv_ext/2013/08/11/log/data
我在蜂巢中 执行命令

!hadoop fs -put /yapstone/logs/pv_ext/somedatafor_7_11/Sacramentorealestatetransactions.csv hdfs://sandbox:8020/yapstone/logs/pv_ext/2013/08/11/log/data

获取错误:

put: File /yapstone/logs/pv_ext/somedatafor_7_11/Sacramentorealestatetransactions.csv does not exist.
Command failed with exit code = 255

请分享您的建议。

谢谢

3 个答案:

答案 0 :(得分:0)

有两种方法可以将数据加载到外部Hive表中。

方法1:

a)获取HDFS外部表的Hive文件夹的位置。

hive> desc formatted mytable;

b)注意输出中Location属性的值。说是hdfs:///hive-data/mydata

c)然后,将文件从本地磁盘放入HDFS

$ hadoop fs -put /location/of/data/file.csv hdfs:///hive-data/mydata

方法2:

a)通过此Hive命令加载数据

hive > LOAD DATA LOCAL INPATH '/location/of/data/file.csv' INTO TABLE mytable;

答案 1 :(得分:0)

另一种方法。更改配置单元表位置:

alter table table_name set location='hdfs://your_data/folder';

答案 2 :(得分:0)

此方法可以帮助您更好。

  1. 需要在HIVE中创建表。

    hive> CREATE EXTERNAL TABLE IF NOT EXISTS mytable(myid INT, a1 STRING, a2 STRING....) row format delimited fields terminated by '\t' stored as textfile LOCATION hdfs://sandbox:8020/yapstone/logs/pv_ext/2013/08/11/log/data;

  2. 将数据从HDFS加载到配置单元表中。

    hive> LOAD DATA INPATH /yapstone/logs/pv_ext/somedatafor_7_11/Sacramentorealestatetransactions.csv INTO TABLE mytable;

    注意:如果将数据从HDFS加载到HIVE(INPATH),则数据将从HDFS中移出 HIVE的位置。因此,下次数据将不会在HDFS位置上显示。

  3. 检查数据是否成功加载。

    hive> SELECT * FROM mytable;

相关问题