Hive执行load data [local] inpath 'path' [overwrite ] into table table_name报Invalid path问题

今天使用Hive客户端 beeline 执行数据导入,怪异的报错:

beeline>load data local inpath '/home/hhuang/2018-05-01_14.txt' overwrite into table data_idea_id_hourly  partition ( dt = '2018-05-27',hour = '14' );

Error: Error while compiling statement: FAILED: SemanticException Line 1:23 Invalid path ''/home/hhuang/2018-05-01_14.txt'': No files matching path file:/home/hhuang/2018-05-01_14.txt (state=42000,code=40000)

报错找不到文件,确定的诗当前机器确实存在这个文件。


分析原因:

When using the JDBC driver, the command executes on the HiveServer2 side. The file is evaluated to locally exist on the server, which is not true in your case (it exists on the local client program machine).

Try instead to load the file to HDFS first, and use a HDFS URI in the LOAD DATA statement to make the server find it.

从上面的解释可知, hive导入数据语句  load data [local] inpath ,是一个服务器端的指令,它是在服务器端执行。因此指定local时表明加载的文件为本地文件,但是这里的local,在hive中指的是 hiveserver 服务所在的机器,而不是hivecli 或 beeline客户端所在的机器(生产环境大都是 hiveserver 和 hivecli不在同一个机器)。

总结:

    解决方法一:把要加载的文件上传到 hiveserver所在的服务器(这一般是不可能的事情),然后执行  load data local inpath [path] [overwrite] into table table_name.

    解决方法二:先将本地文件上传至hdfs,然后使用 load data inpath [hdfspath] [overwrite] into table table_name.

方法二为推荐做法。

  • 15
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值