Python全系列 教程
3567个小节阅读:5929.7k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
node1上启动hadoop集群:startha.sh
启动Hive服务器端
[root@node3 ~]# nohup hive --service metastore &
node3上开启hive的客户端
xxxxxxxxxx
[root@node3 ~]# hive --hiveconf hive.cli.print.header=true
创建库和表。
创建库taobao
xxxxxxxxxx
hive> create database if not exists taobao;
OK
Time taken: 1.009 seconds
切换数据库
xxxxxxxxxx
hive> use taobao;
OK
Time taken: 0.035 seconds
hive> show tables;
OK
tab_name
Time taken: 0.094 seconds
用户表建表脚本:
xxxxxxxxxx
create table if not exists to_user_info(
id int comment "唯一表示id",
age_range int comment "年龄范围",
gender int comment "性别 0女 1男 2保密"
)
row format delimited
fields terminated by ","
lines terminated by "\n";
用户购买日志表:
xxxxxxxxxx
create table if not exists to_user_log(
user_id int comment "买家id",
item_id int comment "产品id",
cat_id int comment "分类id",
seller_id int comment "卖家id",
brand_id int comment "品牌id",
time_stamp bigint comment "时间戳",
action_type int
)
row format delimited
fields terminated by ","
lines terminated by "\n";
查看taobao库下所有的表
xxxxxxxxxx
hive> show tables;
OK
tab_name
to_user_info
to_user_log
Time taken: 0.022 seconds, Fetched: 2 row(s)
使用xftp上传数据文件user_info_format1.csv和user_log_format1.csv到node3的/root目录下。
将user_info_format1.csv文件中的数据load到hive的表user_info表中
xxxxxxxxxx
hive> load data local inpath '/root/user_info_format1.csv' into table to_user_info;
Loading data to table taobao.to_user_info
OK
Time taken: 0.736 seconds
将user_log_format1.csv文件中的数据load到hive的表user_log表中
xxxxxxxxxx
hive> load data local inpath '/root/user_log_format1.csv' into table to_user_log;
Loading data to table taobao.to_user_log
OK
Time taken: 68.371 seconds
查询用户的总个数
xxxxxxxxxx
hive> select count(id) from to_user_info;
OK
424171 #如果没有删除对应数据文件的首行,如果删除结果为424170
Time taken: 62.043 seconds, Fetched: 1 row(s)
hive> select count(id) from to_user_info where id is not null;
OK
424170 #无论是否删除对应数据文件的首行,结果都是该值
Time taken: 62.043 seconds, Fetched: 1 row(s)
Hive客户端中执行编写SQL语句,很不方便,接下来分享给大家一个Hive的可视化SQL编写与执行的工具DataGrip。