Spark数据抽取2

大数据阶段二的第二部分
抽取ds_db01库中product_info的全量数据进入Hive的ods库中表product_info,字段名称、类型不变。根据ods.product_info表中production_date,同时添加动态分区,分区字段为year、month(将production_date拆分为year和month),类型为int。使用 hive cli执行 show partitions ods.product_info命令;
首先将product_info这个表修改一下字段
将表明修改为对应的product_info
将`db_dbs`.`Untitled`修改为product_info |
- 将char修改为string
char修改为string
将smallint修改为int
将tinyint修改为int
将decimal修改为double
将enum修改为string
将datetime修改为timestamp
将text修改为string
- 在结尾添加分区
partitioned by (year int,month int) row format delimited fields terminated by ',' lines terminated by '\n';
剩下没有说到的就原封不动
CREATE TABLE product_info ( |
- 没有修改过的表
- 修改过的表
master工作
- 首先启动一下hadoop
start-all.sh
- 进入hive里面
hive
- 进到hive里面先use到ods你都库里面
use ods;
- 将你修改好product_info的表放进来运行一下
CREATE TABLE product_info (
product_id int,
product_core string,
product_name string,
bar_code string,
brand_id int,
one_category_id int,
two_category_id int,
three_category_id int,
supplier_id int,
price double,
average_cost double,
publish_status int,
audit_status int,
weight float,
length float,
height float,
width float,
color_type string,
production_date timestamp,
shelf_life int,
descript string,
indate timestamp,
modified_time timestamp
) partitioned by (year int,month int) row format delimited fields terminated by ',' lines terminated by '\n'; - 可以用desc product_info查看一下字段
看到有year和month就得了
代码部分
package org.jnds |
弄完这次构建一下,然后scp拷贝到master里面
在master运行一下
直接键入即可,注意看文件名,这个文件名每个人不一样
spark-submit --master yarn --class org.jnds.task02 /tmp/unnamed.jar |
然后进入到hive里面验证一下
- 直接键入
hive
- use到ods库里面
use ods;
- select * from 查看数据
select * from product_info
- 用这条 show partitions ods.product_info 命令然后截图即可
show partitions ods.product_info
最后你还可以通过图像界面来查看
- 你直接到你的浏览器输入你的ip地址后面加上9870即可
例如:172.16.1.1:9870
- 看到页面之后点击Utilities下面的(Browse the file system)
- 点击步骤:
- use
- hive
- warehouse
- ods.db
- product_info
- year=2022
- 最后就可以看到你的数据了
成功界面
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 MENGLAN!