我正在服用 mooc .
它告诉我们使用以下命令将一些文件从 PC 上传到 hdfs
azure storage blob upload local_path container data/logs/2008-01.txt.gz
我也做了同样的事情。 稍后,当我在 PUTTY 安全 shell 中输入以下命令时,我能够看到该文件
hdfs dfs -ls /data/logs
Found 6 items
-rwxrwxrwx 1 331941 2016-03-03 15:56 /data/logs/2008-01.txt.gz
-rwxrwxrwx 1 331941 2016-03-03 15:58 /data/logs/2008-02.txt.gz
-rwxrwxrwx 1 331941 2016-03-03 15:58 /data/logs/2008-03.txt.gz
-rwxrwxrwx 1 331941 2016-03-03 15:58 /data/logs/2008-04.txt.gz
-rwxrwxrwx 1 331941 2016-03-03 15:58 /data/logs/2008-05.txt.gz
-rwxrwxrwx 1 331941 2016-03-03 15:58 /data/logs/2008-06.txt.gz
然后我们启动一个 hive
终端并首先创建一个表,然后使用
load data inpath '/data/logs' into TABLE rawlog;
然后我们使用以下命令创建了一个外部表
CREATE EXTERNAL TABLE cleanlog
(log_date DATE,
log_time STRING,
c_ip STRING,
cs_username STRING,
s_ip STRING,
s_port STRING,
cs_method STRING,
cs_uri_stem STRING,
cs_uri_query STRING,
sc_status STRING,
sc_bytes INT,
cs_bytes INT,
time_taken INT,
cs_user_agent STRING,
cs_referrer STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ' '
STORED AS TEXTFILE LOCATION '/data/cleanlog';
我们使用以下方法将数据插入表中
INSERT INTO TABLE cleanlog
SELECT *
FROM rawlog
WHERE SUBSTR(log_date, 1, 1) <> '#';
我退出配置单元并输入以下命令
hdfs dfs -ls /data/logs
- 我在该文件夹中没有看到任何内容,为什么?上传的日志在哪里 文件去哪了?
- 原始日志表在哪里?它是否存在于同一文件夹中?为什么我没看到?
为什么我在 cleanlog 文件夹中看到文件 00000_0?这是新的吗 table ?如果我输入命令
hdfs dfs -ls/data/cleanlog
我得到的输出是
Found 1 items
-rwxr-xr-x 1 sshuser supergroup 71323206 2016-03-03 16:11 /data/cleanlog/000000_0
################----------------------------------更新1
- 如果在
/data/logs/
处再加载一个数据文件会发生什么情况 然后运行select * from rawlog
?会自动拉取数据吗 从新文件中?
最佳答案
如果您不想丢失源文件夹中的数据,请使用外部表。看看这个 SE 问题:
Difference between `load data inpath ` and `location` in hive?
- I dont see anything in that folder, why? where did uploaded log files go?
当数据加载到表中并且您在路径而不是外部表中使用加载数据时,它们已被删除
- Where is the rawlog table? does it exist in the same folder? Why dont i see it?
数据所在的文件夹中不存在表定义。在创建表语句中,您已经引用了要存储的表数据的位置为/data/cleanlog
看看下面关于 hive 在 hdfs 中存储文件的位置的查询。
Where does Hive store files in HDFS?
I have created a table in hive, I would like to know which directory my table is created in?
- Why do i see file 00000_0 in my cleanlog folder? is it the new table?
这不是新表。在 hive shell 中执行此命令。
describe formatted <table_name>;
编辑:关于表的增量更新,请按照此 article 中的步骤操作。这个问题:Delta/Incremental Load in Hive
关于hadoop - Hive 理解表创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35777666/