Hive基础操作的示例代码

技术Hive基础操作的示例代码这篇文章将为大家详细讲解有关Hive基础操作的示例代码,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。1.在hive的服务端新建源数据[root@hadoo

这篇文章将为大家详细讲解有关储备基础操作的示例代码,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

1.在储备的服务端新建源数据

[root@hadoop5~]#cathivedata

北京:朝阳-上海:浦东

2、傈僳族,库克-游戏,重庆:永春-四川:宜宾

3、张三,店-吃,上海:xujiahui2 .创建内部表

createtabletest1

(idint,namestring,likesarraystring,addressmapstring,string)

行格式定界

fieldsterminatedby ','

集合被“-”终止

mapkeysterminatedby ' :3。将数据导入储备

将“根/配置单元数据”加载到表测试1中;0: JDBC :蜂巢2://Hadoop 5:10000从测试1中选择*;

- - - -

| test1。id | test1。名称| test1。喜欢|测试1。|地址

- - - -

| 1 |小明|['read ',' tv ',' code']|{'beijing': '朝阳,'上海' :浦东' }|

| 2 | Lisi |[“cook”,“game”]| {”渝' : '永春','川' : '冰夷' }|

| 3 |张三|['店','吃]n

bsp;      | {"shanghai":"xujiahui"}                      |
+-----------+-------------+-----------------------+----------------------------------------------+
3 rows selected (0.207 seconds)
0: jdbc:hive2://hadoop5:10000>

4.创建外部表(在hive中删除后,hdfs上数据不会删除)

create external table test2
(id int,name string,likes array<string>,address map<string,string>)
row format delimited
fields terminated by ','
collection items terminated by '-'
map keys terminated by ':'
location '/user/test2';

5.以test1的部分列为模板创建test3

create table test3 as select id, name from test1;
0: jdbc:hive2://hadoop5:10000> desc test3;
+-----------+------------+----------+
| col_name  | data_type  | comment  |
+-----------+------------+----------+
| id        | int        |          |
| name      | string     |          |
+-----------+------------+----------+
2 rows selected (0.406 seconds)
0: jdbc:hive2://hadoop5:10000>

6.参照test1创建test4

create table test4 like test1;

7.创建分区表

create table test5
(id int,name string,likes array<string>,address map<string,string>)
partitioned by (sex string)
row format delimited
fields terminated by ','
collection items terminated by '-'
map keys terminated by ':';
0: jdbc:hive2://hadoop5:10000> desc test5;
+--------------------------+-----------------------+-----------------------+
|         col_name         |       data_type       |        comment        |
+--------------------------+-----------------------+-----------------------+
| id                       | int                   |                       |
| name                     | string                |                       |
| likes                    | array<string>         |                       |
| address                  | map<string,string>    |                       |
| sex                      | string                |                       |
|                          | NULL                  | NULL                  |
| # Partition Information  | NULL                  | NULL                  |
| # col_name               | data_type             | comment               |
|                          | NULL                  | NULL                  |
| sex                      | string                |                       |
+--------------------------+-----------------------+-----------------------+
10 rows selected (0.382 seconds)
0: jdbc:hive2://hadoop5:10000>

8.为该分区添加加载数据

load data local inpath '/root/hivedata' into table test5 partition (sex='boy');
0: jdbc:hive2://hadoop5:10000> select * from test5;
+-----------+-------------+-----------------------+----------------------------------------------+------------+
| test5.id  | test5.name  |      test5.likes      |                test5.address                 | test5.sex  |
+-----------+-------------+-----------------------+----------------------------------------------+------------+
| 1         | xiaoming    | ["read","tv","code"]  | {"beijing":"chaoyang","shanghai":"pudong"}   | boy        |
| 2         | lisi        | ["cook","game"]       | {"chongqing":"yongchun","sichuan":"yibing"}  | boy        |
| 3         | zhangsan    | ["shop","eat"]        | {"shanghai":"xujiahui"}                      | boy        |
+-----------+-------------+-----------------------+----------------------------------------------+------------+
3 rows selected (0.784 seconds)
0: jdbc:hive2://hadoop5:10000>

9.为test5添加一个sex=girl的分区

alter table test5 add partition (sex='girl');

Hive基础操作的示例代码

10.删除一个分区

alter table test5 drop partition (sex='girl');

关于“Hive基础操作的示例代码”这篇文章就分享到这里了,希望

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/142067.html

(0)

相关推荐

  • drupal漏洞分析(drupal代码分析)

    技术如何进行Drupal核心远程代码执行漏洞的分析今天就跟大家聊聊有关如何进行Drupal核心远程代码执行漏洞的分析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

    攻略 2021年12月20日
  • 妥帖读音,熨帖的读音是什么

    技术妥帖读音,熨帖的读音是什么熨帖的读音:yù tiē意思是:1、(用字、用词)贴切;妥帖。2、心里平静3、舒服4、(事情)完全办妥引证解释:1、按压;按揉。沙汀 《困兽记》二四:“他就叹息着往后一靠妥帖读音,拿手掌往复

    生活 2021年10月20日
  • css的基本选择器有哪些

    技术css的基本选择器有哪些这篇文章主要介绍“css的基本选择器有哪些”,在日常操作中,相信很多人在css的基本选择器有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”css的基本选择器

    攻略 2021年11月3日
  • C++中怎么创建CryptoCurrency类

    技术C++中怎么创建CryptoCurrency类本篇内容主要讲解“C++中怎么创建CryptoCurrency类”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“C++中怎么创

    攻略 2021年11月30日
  • androidstudio怎么新建app(androidstudio签名失败)

    技术Android studio怎么导出APP测试包和构建正式签名包这篇文章主要讲解了“Android studio怎么导出APP测试包和构建正式签名包”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路

    攻略 2021年12月17日
  • 如何分析ASP.NET三层结构及三层架构的缺点

    技术如何分析ASP.NET三层结构及三层架构的缺点如何分析ASP.NET三层结构及三层架构的缺点,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。ASP.NET

    攻略 2021年11月26日