SlideShare a Scribd company logo
1 of 15
1
Part
Hive的分区方式
• 由于Hive实际是存储在HDFS上的抽象,Hive的一个分区名对应一
个目录名,子分区名就是子目录名,并不是一个实际字段。
• 所以可以这样理解,当我们在插入数据的时候指定分区,其实就
是新建一个目录或者子目录,或者在原有的目录上添加数据文件。
静态分区
load data local inpath '/opt/data/order_created.txt'
overwrite into table order_mulit_partition
PARTITION(event_month='201405', step='1');
这种手动指定分区加载数据,就是常说的静态分区的使用。
• 新建表的时候定义的分区顺序,决定了文件目录顺序(谁是父目
录谁是子目录)
例如:创建一张静态分区表par_tab_muilt,多个分区(性别+日期)
create table par_tab_muilt (name string, nation string) partitioned by
(sex string,dt string) row format delimited fields terminated by ',‘
• 正因为有了这个层级关系,当我们查询所有man的时候,man以
下的所有日期下的数据都会被查出来。如果只查询日期分区,但
父目录sex=man和sex=woman都有该日期的数据,那么Hive会对输
入路径进行修剪,从而只扫描日期分区,性别分区不作过滤(即
查询结果包含了所有性别)。
动态分区
• 插入的时候必须首先要知道有什么分区类型,而且每个分区写一
个load data,太烦人。使用动态分区可解决以上问题,其可以根
据查询得到的数据动态分配到分区里。
• 动态分区与静态分区区别就是不指定分区目录,由系统自己选择。
• 注意,动态分区不允许主分区采用动态列而副分区采用静态列,
这样将导致所有的主分区都要创建副分区静态列所定义的分区。
• 动态分区可以允许所有的分区列都是动态分区列,但是要首先设
置一个参数hive.exec.dynamic.partition.mode
• 它的默认值是strick,即不允许分区列全部是动态的,这是为了防
止用户有可能原意是只在子分区内进行动态建分区,但是由于疏
忽忘记为主分区列指定值了,这将导致一个dml语句在短时间内
创建大量的新的分区(对应大量新的文件夹),对系统性能带来
影响。
所以我们要设置:set hive.exec.dynamic.partition.mode=nostrick;
2
Part
Hive的锁有两个Lock方式
• Shared (S) 共享表
• Exclusive (X) 独享表、排他表
总结起来就是:
• 1)查询操作使用共享锁,共享锁是可以多重、并发使用的
• 2)修改表操作使用独占锁,它会阻止其他的查询、修改操作
• 3)可以对分区使用锁。
以下情况
会触发锁,
以及它的
类型和锁
定范围如
下:
• 问题:
1.hive某个sql查询一直被卡住不执行,或偶尔出现执行被 卡住情况
(一般出现读写频繁)
2.hive 中某个sql 跑任务偶尔出现申请一点资源,然后一直就停止
了申请(出现在此时服务器资源充足,sql 较复杂)
• 解决方式:
• 1. 排查锁被sql 占用显示的表级别和分区级别占用锁
SHOW LOCKS <TABLE_NAME>;
SHOW LOCKS <TABLE_NAME> EXTENDED;
SHOW LOCKS <TABLE_NAME> PARTITION (<PARTITION_DESC>);
SHOW LOCKS <TABLE_NAME> PARTITION (<PARTITION_DESC>) EXTENDED;
例如: hive 下 show locks dw.dw_user extended
• 2.如果发现 共享锁和排他锁 作用一张表时 对表进行解锁然后重跑数据
show locks 表名:可以查看表被锁的情况
解锁 一张表:unlock table your_table;
解锁 一张表的分区:unlock table your_table partition(dt=‘2014-04-01’);
• 表锁和分区锁是两个不同的锁,对表解锁,对分区是无效的,分区需
要单独解锁
总结
• 想要避免 Hive 锁造成的读、写失败问题,注意以下3点:
1、表建议设置分区,锁的粒度可以到分区,否则容易遭遇长时间
锁表。
2、建议脚本重跑一段时间范围数据时设置 sleep 间隔,避免长期
持有锁,造成依赖表的任务调度失败。
3、可以通过 set hive.support.concurrency=false 来关闭锁,优先保
证插入数据成功,但是此时读数据会有问题。
Hive的静态分区动态分区以及锁机制.pptx

More Related Content

Featured

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Featured (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Hive的静态分区动态分区以及锁机制.pptx