大数据hive的基本操作以及建立数据库,单词的统计
创建数据库
① 创建数据库hive
hive> create database hive;
② 创建数据库hive,因为hive已经存在,所以会抛出异常,加上if not exists关
键字,则不会抛出异常
hive> create database if not exists hive;
• 创建表
① 在hive数据库中,创建表usr,含三个属性id,name,age
hive> use hive;
hive>create table if not exists usr(id bigint,name string,age int);
② 在hive数据库中,创建表usr,含三个属性id,name,age,存储路径为
“/usr/local/hive/warehouse/hive/usr”
hive>create table if not exists hive.usr(id bigint,name string,age int)
>location ‘/usr/local/hive/warehouse/hive/usr’;
创建表
③ 在hive数据库中,创建外部表usr,含三个属性id,name,age,可以读取路径
“/usr/local/data”下以“,”分隔的数据。
hive>create external table if not exists hive.usr(id bigint,name string,age int)
>row format delimited fields terminated by ','
location ‘/usr/local/data’;
④ 在hive数据库中,创建分区表usr,含三个属性id,name,age,还存在分区字
段sex。
hive>create table hive.usr(id bigint,name string,age int) partition by(sex boolean);
⑤ 在hive数据库中,创建分区表usr1,它通过复制表usr得到。
hive> use hive;
hive>create table if not exists usr1 like usr;
• 创建视图
① 创建视图little_usr,只包含usr表中id,age属性
hive>create view little_usr as select id,age from usr;
(3)进入hive命令行界面,编写HiveQL语句实现WordCount算
法,命令如下:
$ hive
hive> create table docs(line string);
hive> load data inpath 'input' overwrite into table docs;
hive>create table word_count as
select word, count(1) as count from
(select explode(split(line,' '))as word from docs) w
group by word
order by word;
执行完成后,用select语句查看运行结果如下:
本周学习时长17小时
下周开学,已经完成9周的学习时间。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!