静态分区:

手动指定分区加载数据,就是常说的静态分区的使用。但是在日常工作中用的比较多的是动态分区。

创建:

hive> create table order_mulit_partition(
> order_number string,
> event_time string
> )
> PARTITIONED BY(event_month string, step string)
> row format delimited fields terminated by '\t';

加载数据:

hive> load data local inpath '/opt/data/order_created.txt' overwrite into table order_mulit_partition PARTITION(event_month='201405', step='1');

查看数据:

hive> select * from order_mulit_partition;
OK
10703007267488 2014-05-01 06:01:12.334+01 NULL 201405 1
10101043505096 2014-05-01 07:28:12.342+01 NULL 201405 1
10103043509747 2014-05-01 07:50:12.33+01 NULL 201405 1
10103043501575 2014-05-01 09:27:12.33+01 NULL 201405 1
10104043514061 2014-05-01 09:03:12.324+01 NULL 201405 1

动态分区:

需求:按照不同部门作为分区导数据到目标表

以上需求如果用静态分区的话,数据量大你是不是很懵逼??所以这个需求一般采用动态分区来实现。

1、emp表的创建及内容

创建:

hive> create table emp(
> empno int,
> ename string,
> job string,
> mgr int,
> hiredate string,
> sal double,
> comm double,
> deptno int
> )row format delimited fields terminated by '\t';

加载数据:

hive> load data local inpath '/home/hadoop/datas/emp.txt' overwrite into table emp;

字段内容:

hive> select * from emp;
OK
7369 SMITH CLERK 7902 1980-12-17 800.0 NULL 20
7499 ALLEN SALESMAN 7698 1981-2-20 1600.0 300.0 30
7521 WARD SALESMAN 7698 1981-2-22 1250.0 500.0 30
7566 JONES MANAGER 7839 1981-4-2 2975.0 NULL 20
7654 MARTIN SALESMAN 7698 1981-9-28 1250.0 1400.0 30
7698 BLAKE MANAGER 7839 1981-5-1 2850.0 NULL 30
7782 CLARK MANAGER 7839 1981-6-9 2450.0 NULL 10
7788 SCOTT ANALYST 7566 1987-4-19 3000.0 NULL 20
7839 KING PRESIDENT NULL 1981-11-17 5000.0 NULL 10
7844 TURNER SALESMAN 7698 1981-9-8 1500.0 0.0 30
7876 ADAMS CLERK 7788 1987-5-23 1100.0 NULL 20
7900 JAMES CLERK 7698 1981-12-3 950.0 NULL 30
7902 FORD ANALYST 7566 1981-12-3 3000.0 NULL 20
7934 MILLER CLERK 7782 1982-1-23 1300.0 NULL 10
8888 HIVE PROGRAM 7839 1988-1-23 10300.0 NULL NULL

显示分区:

hive> show partitions order_mulit_partition;
OK
event_month=201405/step=1

2、创建目标表

hive> create table emp_dynamic_partition(
> empno int,
> ename string,
> job string,
> mgr int,
> hiredate string,
> sal double,
> comm double)
> PARTITIONED BY(deptno int)
> row format delimited fields terminated by '\t';

3、 采用动态方式家在数据到目标表

加载之前先设置下面的参数(设置为非严格模式)

hive> set hive.exec.dynamic.partition.mode=nonstrict

开始加载数据

hive> insert into table emp_dynamic_partition partition(deptno)
select empno , ename , job , mgr , hiredate , sal , comm, deptno from emp;

注意: 上面加载数据方式并没有指定具体的分区,只是指出了分区字段。在select最后一个字段必须跟你的分区字段,这样就会自行根据deptno的value来分区。

4、验证

有值

hive> select * from emp_dynamic_partition;
OK
7782 CLARK MANAGER 7839 1981-6-9 2450.0 NULL 10
7839 KING PRESIDENT NULL 1981-11-17 5000.0 NULL 10
7934 MILLER CLERK 7782 1982-1-23 1300.0 NULL 10
7369 SMITH CLERK 7902 1980-12-17 800.0 NULL 20
7566 JONES MANAGER 7839 1981-4-2 2975.0 NULL 20
7788 SCOTT ANALYST 7566 1987-4-19 3000.0 NULL 20
7876 ADAMS CLERK 7788 1987-5-23 1100.0 NULL 20
7902 FORD ANALYST 7566 1981-12-3 3000.0 NULL 20
7499 ALLEN SALESMAN 7698 1981-2-20 1600.0 300.0 30
7521 WARD SALESMAN 7698 1981-2-22 1250.0 500.0 30
7654 MARTIN SALESMAN 7698 1981-9-28 1250.0 1400.0 30
7698 BLAKE MANAGER 7839 1981-5-1 2850.0 NULL 30
7844 TURNER SALESMAN 7698 1981-9-8 1500.0 0.0 30
7900 JAMES CLERK 7698 1981-12-3 950.0 NULL 30
8888 HIVE PROGRAM 7839 1988-1-23 10300.0 NULL NULL

有分区(自动分区)

hive> show partitions emp_dynamic_partition;
OK
deptno=10
deptno=20
deptno=30
deptno=__HIVE_DEFAULT_PARTITION__
Time taken: 0.375 seconds, Fetched: 4 row(s)

5、各个分区中的内容

deptno=10

782 CLARK   MANAGER 7839    1981-6-9    2450.0  \N
7839 KING PRESIDENT \N 1981-11-17 5000.0 \N
7934 MILLER CLERK 7782 1982-1-23 1300.0 \N

deptno=20

7369    SMITH   CLERK   7902    1980-12-17  800.0   \N
7566 JONES MANAGER 7839 1981-4-2 2975.0 \N
7788 SCOTT ANALYST 7566 1987-4-19 3000.0 \N
7876 ADAMS CLERK 7788 1987-5-23 1100.0 \N
7902 FORD ANALYST 7566 1981-12-3 3000.0 \N

deptno=30

7499    ALLEN   SALESMAN    7698    1981-2-20   1600.0  300.0
7521 WARD SALESMAN 7698 1981-2-22 1250.0 500.0
7654 MARTIN SALESMAN 7698 1981-9-28 1250.0 1400.0
7698 BLAKE MANAGER 7839 1981-5-1 2850.0 \N
7844 TURNER SALESMAN 7698 1981-9-8 1500.0 0.0
7900 JAMES CLERK 7698 1981-12-3 950.0 \N

deptno=__HIVE_DEFAULT_PARTITION__

8888    HIVE    PROGRAM 7839    1988-1-23   10300.0 \N

6、对应mysql中元数据的信息:

mysql> select * from TBLS \G;
*************************** 1. row ***************************
TBL_ID: 1
CREATE_TIME: 1561364642
DB_ID: 6
LAST_ACCESS_TIME: 0
OWNER: hadoop
RETENTION: 0
SD_ID: 1
TBL_NAME: order_mulit_partition
TBL_TYPE: MANAGED_TABLE
VIEW_EXPANDED_TEXT: NULL
VIEW_ORIGINAL_TEXT: NULL
*************************** 2. row ***************************
TBL_ID: 2
CREATE_TIME: 1561365034
DB_ID: 6
LAST_ACCESS_TIME: 0
OWNER: hadoop
RETENTION: 0
SD_ID: 3
TBL_NAME: emp_dynamic_partition
TBL_TYPE: MANAGED_TABLE
VIEW_EXPANDED_TEXT: NULL
VIEW_ORIGINAL_TEXT: NULL
*************************** 3. row ***************************
TBL_ID: 6
CREATE_TIME: 1561366290
DB_ID: 6
LAST_ACCESS_TIME: 0
OWNER: hadoop
RETENTION: 0
SD_ID: 6
TBL_NAME: emp
TBL_TYPE: MANAGED_TABLE
VIEW_EXPANDED_TEXT: NULL
VIEW_ORIGINAL_TEXT: NULL
3 rows in set (0.00 sec) ERROR:
No query specified mysql> select * from PARTITIONS;
+---------+-------------+------------------+-----------------------------------+-------+--------+
| PART_ID | CREATE_TIME | LAST_ACCESS_TIME | PART_NAME | SD_ID | TBL_ID |
+---------+-------------+------------------+-----------------------------------+-------+--------+
| 1 | 1561364780 | 0 | event_month=201405/step=1 | 2 | 1 |
| 6 | 1561371156 | 0 | deptno=10 | 11 | 2 |
| 7 | 1561371157 | 0 | deptno=__HIVE_DEFAULT_PARTITION__ | 12 | 2 |
| 8 | 1561371158 | 0 | deptno=30 | 13 | 2 |
| 9 | 1561371158 | 0 | deptno=20 | 14 | 2 |
+---------+-------------+------------------+-----------------------------------+-------+--------+
5 rows in set (0.00 sec) mysql> select * from PARTITION_KEYS;
+--------+--------------+-------------+-----------+-------------+
| TBL_ID | PKEY_COMMENT | PKEY_NAME | PKEY_TYPE | INTEGER_IDX |
+--------+--------------+-------------+-----------+-------------+
| 1 | NULL | event_month | string | 0 |
| 1 | NULL | step | string | 1 |
| 2 | NULL | deptno | int | 0 |
+--------+--------------+-------------+-----------+-------------+
3 rows in set (0.00 sec) mysql> select * from PARTITION_KEY_VALS;
+---------+----------------------------+-------------+
| PART_ID | PART_KEY_VAL | INTEGER_IDX |
+---------+----------------------------+-------------+
| 1 | 201405 | 0 |
| 1 | 1 | 1 |
| 6 | 10 | 0 |
| 7 | __HIVE_DEFAULT_PARTITION__ | 0 |
| 8 | 30 | 0 |
| 9 | 20 | 0 |
+---------+----------------------------+-------------+
6 rows in set (0.00 sec) mysql> select * from DBS;
+-------+-----------------------+-------------------------------------------------+---------+------------+------------+
| DB_ID | DESC | DB_LOCATION_URI | NAME | OWNER_NAME | OWNER_TYPE |
+-------+-----------------------+-------------------------------------------------+---------+------------+------------+
| 1 | Default Hive database | file:/hive/warehouse | default | public | ROLE |
| 6 | | hdfs://hadoop000:8020/hive/warehouse/g6_hive.db | g6_hive | NULL | USER |
+-------+-----------------------+-------------------------------------------------+---------+------------+------------+
2 rows in set (0.00 sec) mysql> select * from COLUMNS_V2;
+-------+---------+--------------+-----------+-------------+
| CD_ID | COMMENT | COLUMN_NAME | TYPE_NAME | INTEGER_IDX |
+-------+---------+--------------+-----------+-------------+
| 1 | NULL | event_time | string | 1 |
| 1 | NULL | order_number | string | 0 |
| 2 | NULL | comm | double | 6 |
| 2 | NULL | empno | int | 0 |
| 2 | NULL | ename | string | 1 |
| 2 | NULL | hiredate | string | 4 |
| 2 | NULL | job | string | 2 |
| 2 | NULL | mgr | int | 3 |
| 2 | NULL | sal | double | 5 |
| 6 | NULL | comm | double | 6 |
| 6 | NULL | deptno | int | 7 |
| 6 | NULL | empno | int | 0 |
| 6 | NULL | ename | string | 1 |
| 6 | NULL | hiredate | string | 4 |
| 6 | NULL | job | string | 2 |
| 6 | NULL | mgr | int | 3 |
| 6 | NULL | sal | double | 5 |
+-------+---------+--------------+-----------+-------------+
17 rows in set (0.00 sec) mysql> select * from VERSION;
+--------+----------------+-------------------------------------+
| VER_ID | SCHEMA_VERSION | VERSION_COMMENT |
+--------+----------------+-------------------------------------+
| 1 | 1.1.0 | Set by MetaStore hadoop@192.168.0.3 |
+--------+----------------+-------------------------------------+
1 row in set (0.00 sec)

Hive静态分区和动态分区,对应Mysql中的元数据信息的更多相关文章

  1. Hive的静态分区和动态分区

    作者:Syn良子 出处:http://www.cnblogs.com/cssdongl/p/6831884.html 转载请注明出处 虽然之前已经用过很多次hive的分区表,但是还是找时间快速回顾总结 ...

  2. Hive中静态分区和动态分区总结

    目录 背景 第一部分 静态分区 第二部分 动态分区 第三部分 两者的比较 第四部分 动态分区使用的问题 参考文献及资料 背景 在Hive中有两种类型的分区:静态分区(Static Partitioni ...

  3. 什么是hive的静态分区和动态分区,它们又有什么区别呢?hive动态分区详解

    面试官问我,什么是hive的静态分区和动态分区,这题我会呀. 简述 分区是hive存放数据的一种方式,将列值作为目录来存放数据,就是一个分区,可以有多列. 这样查询时使用分区列进行过滤,只需根据列值直 ...

  4. 【HIVE】(2)分区表、二级分区、动态分区、分桶、抽样

    分区表: 建表语句中添加:partitioned by (col1 string, col2 string) create table emp_pt(id int, name string, job ...

  5. sqoop进行将Hive 词频统计的结果数据传输到Mysql中

    使用sqoop进行将Hive 词频统计的结果数据传输到Mysql中. mysql准备接受数据的数据库与表 hive准备待传输的数据 sqoop进行数据传输  mysql查看传输结果     二:电子书 ...

  6. sql点滴—mysql中查询表的信息

    mysql中查询表的信息 查询mysql表字段信息的sql语句 SHOW DATABASES //列出 MySQL Server 数据库. SHOW TABLES [FROM db_name] //列 ...

  7. hive SQL 静态分区和 动态分区

    Hive 分区介绍: hive中简单介绍分区表(partition table),含动态分区(dynamic partition)与静态分区(static partition) hive中创建分区表没 ...

  8. Hive静态分区和动态分区

    一.静态分区 1.创建分区表 hive (default)> create table order_mulit_partition( > order_number string, > ...

  9. 第4节 hive调优:动态分区调整问题

    执行如下截图中的语句时卡住了: 原因:yarn未启动,hive底层是要提交mapreduce到yarn上才能计算结果的. 之前启动yarn时,未执行jps查看是否已经启动.其实未启动成功: [root ...

随机推荐

  1. windows 安装xps查看器; windows 10 安装 xps viewer

    最近发现windows 默认是没有xps 查看器的,需要自己手动添加: 安装完成后,即可使用: 参考链接:https://www.windowscentral.com/how-get-xps-view ...

  2. C语言笔记 02_基本语法&数据类型&变量

    基本语法 令牌 C 程序由各种令牌组成,令牌可以是关键字.标识符.常量.字符串值,或者是一个符号.例如,下面的 C 语句包括五个令牌: printf("Hello, World! \n&qu ...

  3. 大部分人都会忽略的Python易错点总结

    python中复数实现(-2) 0.5和开根号sqrt(-2)的区别** (-2)**0.5和sqrt(-2)是不同的,前者是复数后者是会报错的. print((-2)**0.5) #输出:(8.65 ...

  4. Provide Several View Variants for End-Users 为最终用户提供多个视图变体

    In this lesson, you will learn how to provide several customized variants of the same View, and allo ...

  5. Navicat远程连接MySQL8,必知防坑策略

    项目上线是每一个开发工程师面临收获前面抓紧时间开发的成果,但有时我们上线项目首先需要做一些相关的业务测试.通过Xshell远程连接后使用命令行的方式连接操作Mysql这个没什么太大的你问题.但每次通过 ...

  6. QGIS练手 - 数据

    又熬夜了... 这篇博客可能会将QGIS数据管理部分和ArcGIS数据管理进行对比学习. 1. 本地数据文件与数据库(矢量) 1.1 文件 QGIS用的是shp文件.kml文件.geojson文件较多 ...

  7. 腾讯云大学 x CODING | 当 DevOps 邂逅云原生

    2019 年经济减速的阴云笼罩了所有行业,势如破竹的发展势头被打破,小微创新型企业生存艰难.越来越多的企业更加关注客户和业务之间的交付价值,精益化公司运营,降低成本,驱动业务发展.是否要拥抱云原生?开 ...

  8. ORA-27468: ""."" is locked by another process

    You have a scheduler job that generated an error. When the error occurred, you attempted to disable ...

  9. 如何使用终端默认情况下阻止Mac应用保存到iCloud

    当您保存要在Mac上的Pages,Numbers,TextEdit或其他基于云的应用程序中处理的文档时,该保存的默认位置是iCloud.尽管这对某些人或某些文档来说可能是一件好事,但您可能会厌倦每次更 ...

  10. java之List接口(单列集合)

    List接口概述 查询API我们可知:java.util.List 接口继承自 Collection 接口,是单列集合的一个重要分支,习惯性地会将实现了 List 接口的对 象称为List集合.在Li ...