Hadoop生态圈(七)Hive之HQL操作讲解

今天来初步学习一下hive的操作

  • 主要内容包括:
    -hive的访问方法;
    HQL创建数据库、表和视图的方法

4.3 Hive的数据类型介绍

Hive的基本数据类型
在这里插入图片描述
Hive的集合数据类型
在这里插入图片描述
应用HiveQL完成以下操作
创建数据库
①创建数据库hive
hive> create database hive;
查看hive下已有的数据库:
hive>Show databases;
② 创建数据库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>drop table usr;
查看所有表:
Hive>show tables;
② 在hive数据库中,创建表usr,含三个属性id,name,age,指定表在HDFS文件系统下的存储路径为“/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’;

创建视图
① 创建视图little_usr,只包含usr表中id,age属性
hive>create view little_usr as select id,age from usr;
查看数据库
① 查看Hive中包含的所有数据库
hive> show databases;
② 查看Hive中以h开头的所有数据库
hive>show databases like ‘h.*’;

查看表和视图
① 查看数据库hive中所有表和视图
hive> use hive;
hive> show tables;
② 查看数据库hive中以u开头的所有表和视图
hive> show tables in hive like ‘u*’;

猜你喜欢

转载自blog.csdn.net/qq_41831288/article/details/88966929