配置单元理解 table 创建
hive understanding table creation
我正在参加mooc。
它告诉我们使用以下命令将一些文件从我们的 PC 上传到 hdfs
azure storage blob upload local_path container data/logs/2008-01.txt.gz
我也是这样做的。
后来当我在 PUTTY secure 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
终端,首先创建了一个 table,然后使用
将数据插入 table
load data inpath '/data/logs' into TABLE rawlog;
然后我们使用下面的命令
创建了一个外部table
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';
我们使用
将数据插入table
INSERT INTO TABLE cleanlog
SELECT *
FROM rawlog
WHERE SUBSTR(log_date, 1, 1) <> '#';
我退出配置单元并输入以下命令
hdfs dfs -ls /data/logs
- 我在该文件夹中没有看到任何内容,为什么?上传日志在哪里
档案去哪里?
- rawlog table 在哪里?它是否存在于同一个文件夹中?为什么我看不到?
为什么我在 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
?会不会自动拉取数据
来自新文件?
您使用了 LOAD
命令,该命令将文件从其原始位置移动到 rawlog table 的文件夹(默认情况下为 /hive/warehouse/rawlog
)。
如果您不想丢失源文件夹中的数据,请使用外部 table。看看这个 SE 问题:
Difference between `load data inpath ` and `location` in hive?
- I dont see anything in that folder, why? where did uploaded log files go?
它们已被删除,因为数据加载到 table 并且您在路径中使用加载数据而不是外部 table
- Where is the rawlog table? does it exist in the same folder? Why dont i see it?
Table定义在数据所在的文件夹中不存在。在您的 create table 语句中,您已经引用了要存储的 table 数据的位置 /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?
这不是新的 table。在配置单元 shell.
中执行此命令
describe formatted <table_name>;
编辑: 关于 table 的增量更新,请按照 article and this question : Delta/Incremental Load in Hive
中的步骤操作
我正在参加mooc。
它告诉我们使用以下命令将一些文件从我们的 PC 上传到 hdfs
azure storage blob upload local_path container data/logs/2008-01.txt.gz
我也是这样做的。 后来当我在 PUTTY secure 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
终端,首先创建了一个 table,然后使用
load data inpath '/data/logs' into TABLE rawlog;
然后我们使用下面的命令
创建了一个外部tableCREATE 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';
我们使用
将数据插入tableINSERT INTO TABLE cleanlog
SELECT *
FROM rawlog
WHERE SUBSTR(log_date, 1, 1) <> '#';
我退出配置单元并输入以下命令
hdfs dfs -ls /data/logs
- 我在该文件夹中没有看到任何内容,为什么?上传日志在哪里 档案去哪里?
- rawlog table 在哪里?它是否存在于同一个文件夹中?为什么我看不到?
为什么我在 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
?会不会自动拉取数据 来自新文件?
您使用了 LOAD
命令,该命令将文件从其原始位置移动到 rawlog table 的文件夹(默认情况下为 /hive/warehouse/rawlog
)。
如果您不想丢失源文件夹中的数据,请使用外部 table。看看这个 SE 问题:
Difference between `load data inpath ` and `location` in hive?
- I dont see anything in that folder, why? where did uploaded log files go?
它们已被删除,因为数据加载到 table 并且您在路径中使用加载数据而不是外部 table
- Where is the rawlog table? does it exist in the same folder? Why dont i see it?
Table定义在数据所在的文件夹中不存在。在您的 create table 语句中,您已经引用了要存储的 table 数据的位置 /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?
这不是新的 table。在配置单元 shell.
中执行此命令describe formatted <table_name>;
编辑: 关于 table 的增量更新,请按照 article and this question : Delta/Incremental Load in Hive
中的步骤操作