欢迎投稿

今日深度:

hive 基本命令,

hive 基本命令,


hive 启动 hive>quit; --退出hive hive> exit; --exit会影响之前的使用,所以需要下一句kill掉hadoop的进程 >hadoop job -kill jobid
hive>create database database_name; 创建数据库 如果数据库已经存在就会抛出一个错误信息,使用如下语句可以避免抛出错误信息: hive>creat database if not exists database_name
hive> show databases; 查看数据库

如果数据库比较多的话,也可以用正则表达式来查看:

hive> show databases like ‘h.*’;

hive> use default; --使用哪个数据库

hive>show tables; --查看该数据库中的所有表

hive>show tables ‘t’; --支持模糊查询

hive> describe tab_name; --查看表的结构及表的路径

hive> describe database database_name; --查看数据库的描述及路径

可以用下面的命令来修改数据库的路径:

hive> creat database database_name location ‘路径’;

hive> drop database if exists database_name; --删除空的数据库

hive> drop database if exists database_name cascade; --先删除数据库中的表再删除数据库

hive>show partitions t1; --查看表有哪些分区

修改表:

hive>alter table table_name rename to another_name; --修改表名

hive>drop table t1 ; --删除表t1 或者: hive> drop table if exists t1;
hive不支持修改表中数据,但是可以修改表结构,而不影响数据

有local的速度明显比没有local慢:

hive>load data inpath ‘/root/inner_table.dat’ into table t1; 移动hdfs中数据到t1表中

hive>load data local inpath ‘/root/inner_table.dat’ into table t1; 上传本地数据到hdfs中 hive> !ls; 查询当前linux文件夹下的文件
hive> dfs -ls /; 查询当前hdfs文件系统下 '/'目录下的文件

hive笔记: 1、从文件中执行hive查询:$ hive -f .sql文件的路径; e.g $hive -f /path/to/file/xxxx.hql; 在hive shell中可以用source命令来执行一个脚本文件: hive>source .sql文件的路径 e.g. hive> source /path/to/file/test.sql; hive中一次使用命令: $ hive -e “SQL语句”; e.g. $ hive -e “select * from mytable limit 3”;
2、没有一个命令可以让用户查看当前所在的是哪个数据库库
3、在hive内执行一些bash shell命令(在命令前加。并且以;结尾即可) HIVE 基本命令 4、在hive内执行Hadoop的dfs命令:(去掉hadoop,以;结尾)
5、 Hive脚本如何注释: 使用–开头的字符串来表示注释
6、Hive与MySQL相比,它不支持行级插入操作、更新操作和删除操作。Hive也不支持事务。 Hive增加了在Hadoop背景下的可以提高更高性能的扩展。
7、 向管理表中加载数据: Hive没有行级别的插入、删除、更新的操作,那么往表里面装数据的唯一的途径就是使用一种“大量”的数据装载操作,或者仅仅将文件写入到正确的目录下面。 overwrite关键字: load data local inpath 'env:HOME/overwriteintotabletablenamepartition()8hadoopfscpsourcepathtargetpath使insertdirectoryinsertoverwritelocaldirectory/tmp/URL9hive使1hive>selectprice.fromtablename;price2LikeRLike10hive.map.aggrtruehive>hive.map.aggr=true;11hivemapreduce?mrjobhive.execmode.local.autotruehivesethive.execmode.local.auto=true;sethive.execmode.local.auto=true;{env:HOME}/目录' overwrite into table table_name partition (分区); 8、从表中导出数据: hadoop fs -cp source_path target_path 或者:用户可以使用 insert……directory…… insert overwrite local directory '/tmp/目录' 这里指定的路径也可以是全URL路径 9、hive中使用正则表达式 (1) hive> select 'price.*' from table_name; 选出所有列名以price作为前缀的列 (2) 用Like或者RLike 10、聚合函数 可以通过设置属性hive.map.aggr值为true来提高聚合的性能: hive>hive.map.aggr=true; 11、什么情况下hive可以避免进行mapreduce? 在本地模式的时候可以避免触发一个mr的job,此外,如果属性hive.execmode.local.auto的值为true的话,hive还户尝试本地模式进行其他的操作。 set hive.execmode.local.auto=true; 说明:最好将 set hive.execmode.local.auto=true;这个设置增加到你的HOME/.hiverc配置文件中去。
12、JOIN语句 hive支持通常的SQL JOIN语句,但是只支持等值连接。hive也不支持在on子句中用谓词OR
13、union all 将两个表或者多个表进行合并,每一个union all子查询都必须具有相同的列,而且对应每个字段的每个类型都必须一致。

www.htsjk.Com true http://www.htsjk.com/hive/40021.html NewsArticle hive 基本命令, hive 启动 hivequit; --退出hive hive exit; --exit会影响之前的使用,所以需要下一句kill掉hadoop的进程 hadoop job -kill jobid hivecreate database database_name; 创建数据库 如果数据库已经存...
相关文章
    暂无相关文章
评论暂时关闭