hive服务:
hive --service metastore --help
set hive.cli.print.header; // 查看状态
set hive.cli.print.header=true;
add jar /home/resources.jar;
list jar;
delete jar /home/resources.jar
!表示后面接linux命令
比如:!pwd;
!ls;
dfs表示后面接hadoop命令
比如:dfs -ls /
quit exit都可以退出
通过set命令设的参数只是当前会话有效。
hiveQL简称HQL,是一种类似sql的查询语言,绝大多数语法和sql类似。HQL支持基本类型和复杂类型两大数据类型。基本类型包括TINYINT(1byte), SMALLINT(2byte), INT(4byte), BIGINT(8byte), FLOAT(4byte), DOUBLE(8byte), BOOLEAN(-), STRING(2G)。复杂类型包括ARRAY(一组有序数组,类型必须一致),MAP(无序键值对,键值内部字段类型必须相同,而且要求key的类型为基本数据类型),STRUCT(一组字段,类型任意)。
show命令的主要作用是查看database, table, function等组件的名称信息,也就是通过show命令我们可以知道我们的hive中有那些database;当前database中有哪些table,等等。和mysql的show命令类似。
describe命令的主要作用是获取database, table, partition的具体描述信息,包括存储位置,字段类型等信息。
explain命令的主要作用是获取hql语句的执行计划,我们可以通过分析这些执行计划来优化hql语句。
hive提供database的定义,database的主要作用是提供数据分割的作用,方便数据管理。命令有create describe drop
create database if not exists bigdater comment 'this is test bigdater database';
show databases;
set hive.cli.print.current.db=true;
describe database bigdater;
//要想显示头部信息
set hive.cli.print.header=true;
describe database bigdater;
drop database bigdater;
//创建表命令
create table customers(id int, name string, phone string) comment 'this is customers table' location '/customers';
create table customers2 like customers;//创建表,并且不将数据copy进去
create table customers3 as select * from customers;//创建表,并且将数据copy进去
create table complex_table_text(id int, name string, flag boolean, score array<int>, tech map<string, string>, other struct<phone: string, email: string>)
row format delimited fields terminated by '\;' collection items terminated by ',' map keys terminated by ':' LOCATION 'hdfs://hh:8020/complex_table_test';