大数据全系列 教程
1869个小节阅读:467k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
Table 8. Hive arguments:
Argument | Description |
---|---|
--hive-home <dir> | Override $HIVE_HOME |
--hive-import | Import tables into Hive (Uses Hive’s default delimiters if none are set.) |
--hive-overwrite | Overwrite existing data in the Hive table. |
--create-hive-table | If set, then the job will fail if the target hive table exists. By default this property is false. |
--hive-table <table-name> | Sets the table name to use when importing to Hive. |
--hive-drop-import-delims | Drops \n, \r, and \01 from string fields when importing to Hive. |
--hive-delims-replacement | Replace \n, \r, and \01 from string fields with user defined string when importing to Hive. |
--hive-partition-key | Name of a hive field to partition are sharded on |
--hive-partition-value <v> | String-value that serves as partition key for this imported into hive in this job. |
--map-column-hive <map> | Override default mapping from SQL type to Hive type for configured columns. If specify commas in this argument, use URL encoded keys and values, for example, use DECIMAL(1%2C%201) instead of DECIMAL(1, 1). |
默认字段的分隔符就是^A,也就是\001,可以指定为逗号。
sqoop5.txt
xxxxxxxxxx
import
--connect
jdbc:mysql://node1/result_db
--username
root
--password
123456
--as-textfile
-m
1
-e
select id, browser_name, browser_version from dimension_browser where $CONDITIONS and id>20
--delete-target-dir
--target-dir
/sqoop/hive/hive_browser_dim
--fields-terminated-by
,
--hive-import
--create-hive-table
--hive-table
hive_browser_dim
node3启动hive server执行:
xxxxxxxxxx
[root@node3 ~]# nohup hive --service metastore &
node3命令行:
xxxxxxxxxx
[root@node3 ~]# sqoop --options-file sqoop5.txt
执行后抛出以下异常信息:
ClassNotFoundException: org.apache.hadoop.hive.conf.HiveConf
解决办法:
xxxxxxxxxx
[root@node3 ~]# cp /opt/hive-3.1.2/lib/hive-common-3.1.2.jar /opt/sqoop-1.4.7/lib/
[root@node3 ~]# sqoop --options-file sqoop5.txt
将数据从mysql的表中取出后,放到hdfs上由--target-dir的指定目录/sqoop/hive/hive_browser_dim下,所有数据转移完成后,将hdfs上数据load到hive的表对应的目录下,将该目录删除。
node4上启动hive进行查看数据是否导入
xxxxxxxxxx
hive> show tables;
OK
tab_name
......
hive_browser_dim
Time taken: 0.09 seconds, Fetched: 27 row(s)
hive> select * from hive_browser_dim;
OK
hive_browser_dim.id hive_browser_dim.browser_name hive_browser_dim.browser_version
21 FireFox 0
22 FireFox 1
23 FireFox 2
......
39 aoyou 8
40 aoyou all
Time taken: 3.44 seconds, Fetched: 20 row(s)
注意:如果写成命令行的行,其中sql语句要使用单引号。
sqoop import --connect jdbc:mysql://node1/result_db --username root --password 123456 --as-textfile -m 1 -e 'select id, browser_name, browser_version from dimension_browser where $CONDITIONS and id<=20' --hive-import --create-hive-table --hive-table hive_browser_dim --target-dir /my/tmp --delete-target-dir --fields-terminated-by '\t'