美文网首页
Hive基本使用

Hive基本使用

作者: _羊羽_ | 来源:发表于2019-08-27 19:42 被阅读0次

Hive有三种复杂数据类型ARRAY、MAP 和 STRUCT。ARRAY和MAP与Java中的Array和Map类似,而STRUCT与C语言中的Struct类似,它封装了一个命名字段集合,复杂数据类型允许任意层次的嵌套。
创建数据表

create table test(
name string,
friends array<string>,
children map<string, int>,
address struct<street:string, city:string>
)
row format delimited fields terminated by ','
collection items terminated by '_'
map keys terminated by ':'
lines terminated by '\n';

查看数据结构

hive (default)> desc test;
OK
col_name    data_type   comment
name                    string                                      
friends                 array<string>                               
children                map<string,int>                             
address                 struct<street:string,city:string>                       
Time taken: 0.053 seconds, Fetched: 4 row(s)

测试数据

liming,zhangsan_lisi,xiao ming:12_xiaoxiao ming:3,haidian_beijing
wangwu,zhaoliu_sunba_qianer,xiao wang:18_xiaoxiao wang:9,chao yang_beijing

加载测试数据

hive (default)> load data local inpath '/opt/module/data/people.txt' into table test;
Loading data to table default.test
Table default.test stats: [numFiles=1, numRows=0, totalSize=141, rawDataSize=0]
OK
Time taken: 0.354 seconds

查看数据内容

hive (default)> select *from test;
OK
test.name   test.friends    test.children   test.address
liming  ["zhangsan","lisi"] {"xiao ming":12,"xiaoxiao ming":3}  {"street":"haidian","city":"beijing"}
wangwu  ["zhaoliu","sunba","qianer"]    {"xiao wang":18,"xiaoxiao wang":9}  {"street":"chao yang","city":"beijing"}
Time taken: 0.069 seconds, Fetched: 2 row(s)

Mysql 查看hive表结构

mysql root@localhost:(none)> use hive;
You are now connected to database "hive" as user "root"
Time: 0.001s
mysql root@localhost:hive> select *from `TBLS`;
+--------+-------------+-------+------------------+-------+-----------+-------+------------+---------------+--------------------+--------------------+
| TBL_ID | CREATE_TIME | DB_ID | LAST_ACCESS_TIME | OWNER | RETENTION | SD_ID | TBL_NAME   | TBL_TYPE      | VIEW_EXPANDED_TEXT | VIEW_ORIGINAL_TEXT |
+--------+-------------+-------+------------------+-------+-----------+-------+------------+---------------+--------------------+--------------------+
| 1      | 1566392699  | 6     | 0                | root  | 0         | 1     | docs       | MANAGED_TABLE | <null>             | <null>             |
| 2      | 1566392821  | 6     | 0                | root  | 0         | 2     | word_count | MANAGED_TABLE | <null>             | <null>             |
+--------+-------------+-------+------------------+-------+-----------+-------+------------+---------------+--------------------+--------------------+

2 rows in set
Time: 0.012s

查看表的字段

mysql root@localhost:hive> select *from `COLUMNS_V2`
+-------+---------+-------------+-----------+-------------+
| CD_ID | COMMENT | COLUMN_NAME | TYPE_NAME | INTEGER_IDX |
+-------+---------+-------------+-----------+-------------+
| 1     | <null>  | line        | string    | 0           |
| 2     | <null>  | count       | bigint    | 1           |
| 2     | <null>  | word        | string    | 0           |
+-------+---------+-------------+-----------+-------------+

3 rows in set
Time: 0.012s

加载数据到hive中

LOAD DATA LOCAL(本地文件需要添加LOCAL) INPATH '文件路径' OVERWRITE INTO TABLE 表名称;

相关文章

  • Hive基本使用

    Hive基本使用 https://www.52pojie.cn/thread-919235-1-1.html

  • Hive基本使用

    Hive有三种复杂数据类型ARRAY、MAP 和 STRUCT。ARRAY和MAP与Java中的Array和Map...

  • hive数据库

    一、基本使用 1、进入hive 使用xshell远程登陆,进入linux系统。任意位置输入hive即可。 2、进入...

  • Hive的条件函数与日期函数全面汇总解析

    在Hive的开窗函数实战的文章中,主要介绍了Hive的分析函数的基本使用。本文是这篇文章的延续,涵盖了Hive所有...

  • Hive查询HBase调用MapReduce性能优化

    折腾了很久,被领导天天督促&指点,算是有个最基本的性能优化。 1. 背景介绍: Hive使用hive-hbase-...

  • hive学习(一):基本使用

    前言: 针对有sql基础,刚熟悉linux界面,在此进行hive的入门学习分享,文章结合网络资料并加以细化步骤。本...

  • [译]Hive学习指南(二)

    Hive SQL的能力 Hive's SQL提供了基本SQL操作。这些操作作用于表和分区,具有以下能力: 可使用W...

  • HIVE

    基本操作 hive进入hive模式 exit; 退出hive模式 展示正则匹配表名hive> use ad_s...

  • Hive之同比环比的计算

    Hive系列文章 Hive表的基本操作[http://www.ikeguang.com/?p=1657] Hive...

  • 2020-04-13

    大数据之Hive 一.Hive基本概念 1.什么是Hive Hive是Facebook开源用于处理 海量 结构化 ...

网友评论

      本文标题:Hive基本使用

      本文链接:https://www.haomeiwen.com/subject/syjdectx.html