hadoop/hive:文件正在转换为目录
hadoop/hive :File is getting transforming into a directory
问题: 正如你所看到的,在输出中,input.txt已经从一个文件变成了一个目录。这怎么可能?在某些情况下,hive 中的 create table 行为是否不同?
我有以下简单的 shell 脚本到 运行 一个 hive/hadoop 脚本
#!/bin/bash
set -xv
hadoop fs -rmr /user/myloginname/input.txt
hadoop fs -put input.txt /user/myloginname/input.txt
hadoop fs -ls /user/myloginname/
hive -S -f hive_script.hql
hadoop fs -ls /user/myloginname/
hive 脚本本身只是创建一个外部 table
create table if not exists myitems (
item_id string)
LINES TERMINATED BY '\n'
STORED AS TEXTFILE LOCATION '/user/myloginname/input.txt';
select "Number of items in myitems table is ",count(*) from myitems;
input.txt文件本身很简单
cat input.txt
44910429
44657920
36129962
shell脚本的输出如下
hadoop fs -rmr /user/myloginname/input.txt
+ hadoop fs -rmr /user/myloginname/input.txt
Deleted maprfs:/user/myloginname/input.txt
hadoop fs -put input.txt /user/myloginname/input.txt
+ hadoop fs -put input.txt /user/myloginname/input.txt
hadoop fs -ls /user/myloginname/
+ hadoop fs -ls /user/myloginname/
Found 1 items
-rwxr-xr-x 3 myloginname myloginname 550 2015-08-29 00:06 /user/myloginname/input.txt
hive -S -f hive_script.hql
+ hive -S -f hive_script.hql
This is *bfd-main*.
Number of items in myitems table is 0
hadoop fs -ls /user/myloginname/
+ hadoop fs -ls /user/myloginname/
Found 1 items
drwxr-xr-x - myloginname myloginname 0 2015-08-29 00:06 /user/myloginname/input.txt
问题: 正如你所看到的,在输出中,input.txt已经从一个文件变成了一个目录。这怎么可能?在某些情况下,create table 的行为会有所不同吗?
每当您创建托管 table 时,hive 都会尝试以两种方式设置您的 table 路径:
a) 如果您在创建 table 时在 location 中指定路径,那么该路径将被视为源 目录 并且配置单元将获取下的所有文件该目录构建 table
b) 它将采用默认的 /user/hive/warehouse
目录并假设如果您的 table 名称是员工然后它创建 /user/hive/warehouse/employee 目录然后您使用 [= 构建您的 table 25=] 并且该文件名将位于 /user/hive/warehouse/emp/ 目录下。
因此,在您的情况下,您是在告诉配置单元构建 table 的所有源文件都在目录 /user/myloginname/input.txt
下可用。但是当它开始创建 table 时,它发现路径不是目录而是文件。因此它会覆盖并从中创建一个目录。由于您在配置单元创建的目录下没有源文件,因此您的计数 returns 0。
将您的位置指定为 LOCATION /user/myloginname
。
问题: 正如你所看到的,在输出中,input.txt已经从一个文件变成了一个目录。这怎么可能?在某些情况下,hive 中的 create table 行为是否不同?
我有以下简单的 shell 脚本到 运行 一个 hive/hadoop 脚本
#!/bin/bash
set -xv
hadoop fs -rmr /user/myloginname/input.txt
hadoop fs -put input.txt /user/myloginname/input.txt
hadoop fs -ls /user/myloginname/
hive -S -f hive_script.hql
hadoop fs -ls /user/myloginname/
hive 脚本本身只是创建一个外部 table
create table if not exists myitems (
item_id string)
LINES TERMINATED BY '\n'
STORED AS TEXTFILE LOCATION '/user/myloginname/input.txt';
select "Number of items in myitems table is ",count(*) from myitems;
input.txt文件本身很简单
cat input.txt
44910429
44657920
36129962
shell脚本的输出如下
hadoop fs -rmr /user/myloginname/input.txt
+ hadoop fs -rmr /user/myloginname/input.txt
Deleted maprfs:/user/myloginname/input.txt
hadoop fs -put input.txt /user/myloginname/input.txt
+ hadoop fs -put input.txt /user/myloginname/input.txt
hadoop fs -ls /user/myloginname/
+ hadoop fs -ls /user/myloginname/
Found 1 items
-rwxr-xr-x 3 myloginname myloginname 550 2015-08-29 00:06 /user/myloginname/input.txt
hive -S -f hive_script.hql
+ hive -S -f hive_script.hql
This is *bfd-main*.
Number of items in myitems table is 0
hadoop fs -ls /user/myloginname/
+ hadoop fs -ls /user/myloginname/
Found 1 items
drwxr-xr-x - myloginname myloginname 0 2015-08-29 00:06 /user/myloginname/input.txt
问题: 正如你所看到的,在输出中,input.txt已经从一个文件变成了一个目录。这怎么可能?在某些情况下,create table 的行为会有所不同吗?
每当您创建托管 table 时,hive 都会尝试以两种方式设置您的 table 路径:
a) 如果您在创建 table 时在 location 中指定路径,那么该路径将被视为源 目录 并且配置单元将获取下的所有文件该目录构建 table
b) 它将采用默认的 /user/hive/warehouse
目录并假设如果您的 table 名称是员工然后它创建 /user/hive/warehouse/employee 目录然后您使用 [= 构建您的 table 25=] 并且该文件名将位于 /user/hive/warehouse/emp/ 目录下。
因此,在您的情况下,您是在告诉配置单元构建 table 的所有源文件都在目录 /user/myloginname/input.txt
下可用。但是当它开始创建 table 时,它发现路径不是目录而是文件。因此它会覆盖并从中创建一个目录。由于您在配置单元创建的目录下没有源文件,因此您的计数 returns 0。
将您的位置指定为 LOCATION /user/myloginname
。