更新时间:2024-08-05 GMT+08:00
加载数据到Hive表中
功能介绍
本小节介绍了如何使用HQL向已有的表employees_info中加载数据。从本节中可以掌握如何从本地文件系统、MRS集群中加载数据。以关键字LOCAL区分数据源是否来自本地。
样例代码
-- 从本地文件系统/opt/hive_examples_data/目录下将employee_info.txt加载进employees_info表中. ---- 用新数据覆盖原有数据 LOAD DATA LOCAL INPATH '/opt/hive_examples_data/employee_info.txt' OVERWRITE INTO TABLE employees_info; ---- 保留原有数据,将新数据追加到表中 LOAD DATA LOCAL INPATH '/opt/hive_examples_data/employee_info.txt' INTO TABLE employees_info; -- 从HDFS上/user/hive_examples_data/employee_info.txt加载进employees_info表中. ---- 用新数据覆盖原有数据 LOAD DATA INPATH '/user/hive_examples_data/employee_info.txt' OVERWRITE INTO TABLE employees_info; ---- 保留原有数据,将新数据追加到表中 LOAD DATA INPATH '/user/hive_examples_data/employee_info.txt' INTO TABLE employees_info;
加载数据的实质是将数据复制到HDFS上指定表的目录下。
样例数据
表employees_info的数据如下:
1,Wang,R,8000.01,person&personal^Btype&income^Btax&0.05,Country1:City1,2014 3,Tom,D,12000.02,person&personal^Btype&income^Btax&0.09,Country2:City2,2014 4,Jack,D,24000.03,person&personal^Btype&income^Btax&0.05,Country3:City3,2014 6,Linda,D,36000.04,person&personal^Btype&income^Btax&0.05,Country4:City4,2014 8,Zhang,R,9000.05,person&personal^Btype&income^Btax&0.05,Country5:City5,2014
表employees_contact的数据如下:
1,135 XXXX XXXX,xxxx@xx.com 3,159 XXXX XXXX,xxxxx@xx.com.cn 4,186 XXXX XXXX,xxxx@xx.org 6,189 XXXX XXXX,xxxx@xxx.cn 8,134 XXXX XXXX,xxxx@xxxx.cn
表employees_info_extended的数据如下:
1,Wang,135 XXXX XXXX,xxxx@xx.com,R,8000.01,person&personal^Btype&income^Btax&0.05,Country1:City1,2014 3,Tom,159 XXXX XXXX,xxxxx@xx.com.cn,D,12000.02,person&personal^Btype&income^Btax&0.09,Country2:City2,2014 4,Jack,186 XXXX XXXX,xxxx@xx.org,D,24000.03,person&personal^Btype&income^Btax&0.05,Country3:City3,2014 6,Linda,189 XXXX XXXX,xxxx@xxx.cn,D,36000.04,person&personal^Btype&income^Btax&0.05,Country4:City4,2014 8,Zhang,134 XXXX XXXX,xxxx@xxxx.cn,R,9000.05,person&personal^Btype&income^Btax&0.05,Country5:City5,2014
父主题: Hive JDBC访问样例程序