Hive Apachecon 2008

24,019
-1

Published on

Summary:
Presentation of Hive in the Hadoop Camp at ApacheCon 2008, New Oreleans, LA

Presented By:
Ashish Thusoo,
Facebook Data Infrastructure Team

Published in: Technology
0 Comments
17 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
24,019
On Slideshare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
600
Comments
0
Likes
17
Embeds 0
No embeds

No notes for slide
  • Hive Apachecon 2008

    1. 1. HIVE Data Warehousing & Analytics on Hadoop Ashish Thusoo, Facebook Data Team
    2. 2. Why Another Data Warehousing System? <ul><li>Problem: Data, data and more data </li></ul><ul><ul><li>200GB per day in March 2008 </li></ul></ul><ul><ul><li>2+TB(compressed) raw data per day today </li></ul></ul><ul><li>The Hadoop Experiment </li></ul><ul><ul><li>Superior to availability/scalability/manageability of commercial DBs </li></ul></ul><ul><ul><li>Efficiency not that great, but throw more hardware </li></ul></ul><ul><ul><li>Partial Availability/resilience/scale more important than ACID </li></ul></ul><ul><li>Problem: Programmability and Metadata </li></ul><ul><ul><li>Map-reduce hard to program (users know sql/bash/python) </li></ul></ul><ul><ul><li>Need to publish data in well known schemas </li></ul></ul><ul><li>Solution: HIVE </li></ul>
    3. 3. What is HIVE? <ul><li>A system for managing and querying structured data built on top of Hadoop </li></ul><ul><ul><li>Uses Map-Reduce for execution </li></ul></ul><ul><ul><li>HDFS for storage </li></ul></ul><ul><ul><li>Extensible to other Data Repositories </li></ul></ul><ul><li>Key Building Principles: </li></ul><ul><ul><li>SQL on structured data as a familiar data warehousing tool </li></ul></ul><ul><ul><li>Extensibility (Pluggable map/reduce scripts in the language of your choice, Rich and User Defined data types, User Defined Functions) </li></ul></ul><ul><ul><li>Interoperability (Extensible framework to support different file and data formats) </li></ul></ul><ul><ul><li>Performance </li></ul></ul>
    4. 4. Hive/Hadoop Usage @ Facebook <ul><li>Types of Applications: </li></ul><ul><ul><li>Summarization </li></ul></ul><ul><ul><ul><li>Eg: Daily/Weekly aggregations of impression/click counts </li></ul></ul></ul><ul><ul><ul><li>Complex measures of user engagement </li></ul></ul></ul><ul><ul><li>Ad hoc Analysis </li></ul></ul><ul><ul><ul><li>Eg: how many group admins broken down by state/country </li></ul></ul></ul><ul><ul><li>Data Mining (Assembling training data) </li></ul></ul><ul><ul><ul><li>Eg: User Engagement as a function of user attributes </li></ul></ul></ul><ul><ul><li>Spam Detection </li></ul></ul><ul><ul><ul><li>Anomalous patterns for Site Integrity </li></ul></ul></ul><ul><ul><ul><li>Application API usage patterns </li></ul></ul></ul><ul><ul><li>Ad Optimization </li></ul></ul><ul><ul><li>Too many to count .. </li></ul></ul>
    5. 5. Data Warehousing at Facebook Today Web Servers Scribe Servers Filers Hive on Hadoop Cluster Oracle RAC Federated MySQL
    6. 6. HIVE: Components HDFS Hive CLI DDL Queries Browsing Map Reduce MetaStore Thrift API SerDe Thrift Jute JSON.. Execution Hive QL Parser Planner Web UI
    7. 7. Data Model Logical Partitioning Hash Partitioning Schema Library clicks HDFS MetaStore / hive/clicks /hive/clicks/ds=2008-03-25 /hive/clicks/ds=2008-03-25/0 … Tables #Buckets=32 Bucketing Info Partitioning Cols
    8. 8. MetaStore <ul><li>Stores Table/Partition properties: </li></ul><ul><ul><li>Table schema and SerDe library </li></ul></ul><ul><ul><li>Table Location on HDFS </li></ul></ul><ul><ul><li>Logical Partitioning keys and types </li></ul></ul><ul><ul><li>Partition level metadata </li></ul></ul><ul><ul><li>Other information </li></ul></ul><ul><li>Thrift API </li></ul><ul><ul><li>Current clients in Php (Web Interface), Python interface to Hive, Java (Query Engine and CLI) </li></ul></ul><ul><li>Metadata stored in any SQL backend or an Embedded Derby Database </li></ul><ul><li>Future </li></ul><ul><ul><li>Statistics </li></ul></ul><ul><ul><li>Schema Evolution </li></ul></ul>
    9. 9. Hive Query Language <ul><li>Basic SQL </li></ul><ul><ul><li>From clause subquery </li></ul></ul><ul><ul><li>ANSI JOIN (equi-join only) </li></ul></ul><ul><ul><li>Multi-table Insert </li></ul></ul><ul><ul><li>Multi group-by </li></ul></ul><ul><ul><li>Sampling </li></ul></ul><ul><ul><li>Objects traversal </li></ul></ul><ul><li>Extensibility </li></ul><ul><ul><li>Pluggable Map-reduce scripts in the language of your choice using TRANSFORM (Syntax changing soon!!) </li></ul></ul><ul><ul><li>Pluggable User Defined Functions </li></ul></ul><ul><ul><li>Pluggable User Defined Types </li></ul></ul><ul><ul><li>Pluggable SerDes to read different kinds of Data Formats </li></ul></ul>
    10. 10. (Simplified) Map Reduce Review Machine 2 Machine 1 <k1, v1> <k2, v2> <k3, v3> <k4, v4> <k5, v5> <k6, v6> <nk1, nv1> <nk2, nv2> <nk3, nv3> <nk2, nv4> <nk2, nv5> <nk1, nv6> Local Map <nk2, nv4> <nk2, nv5> <nk2, nv2> <nk1, nv1> <nk3, nv3> <nk1, nv6> Global Shuffle <nk1, nv1> <nk1, nv6> <nk3, nv3> <nk2, nv4> <nk2, nv5> <nk2, nv2> Local Sort <nk2, 3> <nk1, 2> <nk3, 1> Local Reduce
    11. 11. Hive QL – Join <ul><li>SQL: </li></ul><ul><ul><li>INSERT INTO TABLE pv_users </li></ul></ul><ul><ul><li>SELECT pv.pageid, u.age </li></ul></ul><ul><ul><li>FROM page_view pv JOIN user u ON (pv.userid = u.userid); </li></ul></ul>X = page_view user pv_users pageid userid time 1 111 9:08:01 2 111 9:08:13 1 222 9:08:14 userid age gender 111 25 female 222 32 male pageid age 1 25 2 25 1 32
    12. 12. Hive QL – Join in Map Reduce page_view user pv_users Map Shuffle Sort Reduce key value 111 < 1, 1> 111 < 1, 2> 222 < 1, 1> pageid userid time 1 111 9:08:01 2 111 9:08:13 1 222 9:08:14 userid age gender 111 25 female 222 32 male key value 111 < 2, 25> 222 < 2, 32> key value 111 < 1, 1> 111 < 1, 2> 111 < 2, 25> key value 222 < 1, 1> 222 < 2, 32> Pageid age 1 25 2 25 pageid age 1 32
    13. 13. Joins <ul><li>Outer Joins </li></ul><ul><li>INSERT INTO TABLE pv_users </li></ul><ul><li>SELECT pv.*, u.gender, u.age </li></ul><ul><li>FROM page_view pv FULL OUTER JOIN user u ON (pv.userid = u.id) </li></ul><ul><li>WHERE pv.date = 2008-03-03; </li></ul>
    14. 14. Join To Map Reduce <ul><li>Only Equality Joins with conjunctions supported </li></ul><ul><li>Performance Improvements being Worked On </li></ul><ul><ul><li>Pruning of values send from map to reduce on the basis of projections </li></ul></ul><ul><ul><li>Make Cartesian product more memory efficient </li></ul></ul><ul><ul><li>Map side joins </li></ul></ul><ul><ul><ul><li>Hash Joins if one of the tables is very small </li></ul></ul></ul><ul><ul><ul><li>Use Semi Joins (proposed by Jun Rao et. al. @ IBM) </li></ul></ul></ul><ul><ul><ul><li>Exploit pre-sorted data by doing map-side merge join </li></ul></ul></ul><ul><li>Estimate number of reducers </li></ul><ul><ul><li>Hard to measure effect of filters </li></ul></ul><ul><ul><li>Run map side for small part of input to estimate #reducers </li></ul></ul>
    15. 15. Joining multiple tables in a single Map Reduce <ul><li>SQL: </li></ul><ul><ul><li>SELECT… </li></ul></ul><ul><ul><li>FROM a join b on (a.key = b.key) join c on (a.key = c.key) </li></ul></ul>A Map Reduce B C AB Map Reduce ABC key av bv 1 111 222 key av 1 111 key bv 1 222 key cv 1 333 key av bv cv 1 111 222 333
    16. 16. Hive QL – Group By <ul><ul><ul><ul><li>SELECT pageid, age, count(1) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>FROM pv_users </li></ul></ul></ul></ul><ul><ul><ul><ul><li>GROUP BY pageid, age; </li></ul></ul></ul></ul>pv_users pageid age 1 25 2 25 1 32 2 25 pageid age count 1 25 1 2 25 2 1 32 1
    17. 17. Hive QL – Group By in Map Reduce pv_users Map Shuffle Sort Reduce pageid age 1 25 2 25 pageid age count 1 25 1 1 32 1 pageid age 1 32 2 25 key value <1,25> 1 <2,25> 1 key value <1,32> 1 <2,25> 1 key value <1,25> 1 <1,32> 1 key value <2,25> 1 <2,25> 1 pageid age count 2 25 2
    18. 18. Hive QL – Group By with Distinct <ul><ul><li>SELECT pageid, COUNT(DISTINCT userid) </li></ul></ul><ul><ul><li>FROM page_view GROUP BY pageid </li></ul></ul>page_view pageid userid time 1 111 9:08:01 2 111 9:08:13 1 222 9:08:14 2 111 9:08:20 pageid count_distinct_userid 1 2 2 1
    19. 19. Hive QL – Group By with Distinct in Map Reduce page_view Shuffle and Sort Reduce Map Reduce pageid count 1 1 2 1 pageid count 1 1 pageid userid time 1 111 9:08:01 2 111 9:08:13 pageid userid time 1 222 9:08:14 2 111 9:08:20 key v <1,111> <2,111> <2,111> key v <1,222> pageid count 1 2 pageid count 2 1
    20. 20. Group by Optimizations <ul><li>Map side partial aggregations </li></ul><ul><ul><li>Hash Based aggregates </li></ul></ul><ul><ul><li>Serialized key/values in hash tables </li></ul></ul><ul><li>Optimizations being Worked On: </li></ul><ul><ul><li>Exploit pre-sorted data for distinct counts </li></ul></ul><ul><ul><li>Partial aggregations and Combiners </li></ul></ul><ul><ul><li>Be smarter about how to avoid multiple stage </li></ul></ul><ul><ul><li>Exploit table/column statistics for deciding strategy </li></ul></ul>
    21. 21. Inserts into Files, Tables and Local Files <ul><ul><ul><li>FROM pv_users </li></ul></ul></ul><ul><ul><ul><li>INSERT INTO TABLE pv_gender_sum </li></ul></ul></ul><ul><ul><ul><ul><li>SELECT pv_users.gender, count_distinct(pv_users.userid) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>GROUP BY(pv_users.gender) </li></ul></ul></ul></ul><ul><ul><ul><li>INSERT INTO DIRECTORY ‘/user/facebook/tmp/pv_age_sum.dir’ </li></ul></ul></ul><ul><ul><ul><ul><li>SELECT pv_users.age, count_distinct(pv_users.userid) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>GROUP BY(pv_users.age) </li></ul></ul></ul></ul><ul><ul><ul><li>INSERT INTO LOCAL DIRECTORY ‘/home/me/pv_age_sum.dir’ </li></ul></ul></ul><ul><ul><ul><li> FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY 13 </li></ul></ul></ul><ul><ul><ul><ul><li>SELECT pv_users.age, count_distinct(pv_users.userid) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>GROUP BY(pv_users.age); </li></ul></ul></ul></ul>
    22. 22. Extensibility - Custom Map/Reduce Scripts <ul><ul><ul><li>FROM ( </li></ul></ul></ul><ul><ul><ul><ul><li>FROM pv_users </li></ul></ul></ul></ul><ul><ul><ul><ul><li>SELECT TRANSFORM(pv_users.userid, pv_users.date) USING 'map_script' AS(dt, uid) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>CLUSTER BY(dt)) map </li></ul></ul></ul></ul><ul><ul><ul><li>INSERT INTO TABLE pv_users_reduced </li></ul></ul></ul><ul><ul><ul><ul><li>SELECT TRANSFORM(map.dt, map.uid) USING 'reduce_script' AS (date, count); </li></ul></ul></ul></ul>Custom ‘map_script’ in map side TRANSFORM Custom ‘reduce_script’ in reduce side TRANSFORM Key dt between map and reduce using CLUSTER BY
    23. 23. Extensibility – User Defined Functions interface UDF class com.example.myUDF implements UDF myUDF.jar hive.aux.jars CREATE TEMPORARY FUNCTION myudf AS ‘com.example.myUDF’; SELECT myudf(t.c1) FROM t; drop in the jar register udf use udf use udf
    24. 24. Extensibility- User Defined Data Formats <ul><li>interface serde2.Serialize </li></ul>101010…. interface serde2.DeSerialize class com.example.myDeSerializer extends serde2.DeSerialize class com.example.mySerializer extends serde2.Serialize RowObject hive.aux.jars plug & play myExtensions.jar ObjectInspector
    25. 25. Extensibility – User Defined Types <ul><li>hive.aux.jars </li></ul>struct { map<string, smallint> f11; struct { list<double> f21; int f22; } f12; } new StandardStructObjectInspector f11: f12: new StandardStructObjectInspector f21: f22: PrimitiveObjectInspector(int) new StandardMapObjectInspector key: PrimitiveObjectInspector(string) val: PrimitiveObjectInspector(smallint) new StandardListObjectInspector elem: PrimitiveObjectInspector(double) myExtensions.jar drop in the jar
    26. 26. Extensibility- Reading Rich Data <ul><li>Create the table: </li></ul><ul><li>CREATE TABLE tab </li></ul><ul><li>ROW FORMAT SERDE ‘com.example.mySerDe’ </li></ul><ul><li>WITH SERDEPROPERTIES(…); </li></ul><ul><li>Use the table: </li></ul><ul><li>SELECT tab.f11[‘abc’], tab.f12.f21[size(tab.f12.f21)] </li></ul><ul><li>FROM tab; </li></ul>
    27. 27. Extensibility- Reading Rich Data <ul><li>Easy to write a SerDe for old data stored in your own format </li></ul><ul><ul><li>You can write your own SerDe (XML, JSON …) </li></ul></ul><ul><li>Existing SerDe families </li></ul><ul><ul><li>Thrift DDL based SerDe </li></ul></ul><ul><ul><li>Delimited text based SerDe </li></ul></ul><ul><ul><li>Dynamic SerDe to read data with delimited maps, lists and primitive types </li></ul></ul>
    28. 28. Interoperability – External Tables <ul><li>Data already in hdfs </li></ul><ul><li>Use External Tables to associate metadata with existing hdfs data </li></ul><ul><li>CREATE EXTERNAL TABLE page_view_stg(viewTime INT, userid BIGINT, </li></ul><ul><ul><ul><ul><ul><li>page_url STRING, referrer_url STRING, </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>ip STRING COMMENT 'IP Address of the User', </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>country STRING) </li></ul></ul></ul></ul></ul><ul><ul><li>COMMENT 'This is the staging page view table' </li></ul></ul><ul><ul><li>ROW FORMAT DELIMITED FIELDS TERMINATED BY '54' LINES TERMINATED BY '12' </li></ul></ul><ul><ul><li>STORED AS TEXTFILE </li></ul></ul><ul><ul><li>LOCATION '/data/page_view'; </li></ul></ul>
    29. 29. Interoperability – JDBC driver <ul><li>A simple JDBC driver being worked on </li></ul><ul><li>Allows other applications to interoperate – primarily BI tools in facebook </li></ul>External Application (e.g. BI) Hive JDBC Driver MetaStore NameNode JobTracker Hadoop Cluster
    30. 30. Evolving Open Source Community <ul><li>Apart from Facebook some other contributions coming in from external developers: </li></ul><ul><ul><li>DDL for Session Level User Defined Functions (Tom White) </li></ul></ul><ul><ul><li>JDBC driver (Michi and Raghu @stanford) </li></ul></ul><ul><ul><li>Web UI (Edward Capriolo) </li></ul></ul><ul><ul><li>CLI bug fixes (Jeremy Huylebroeck) </li></ul></ul><ul><li>Still early days and still evolving </li></ul>
    31. 31. Future Work – Longer Term <ul><li>Cost-based optimization </li></ul><ul><li>Multiple interfaces (JDBC…)/Integration with BI </li></ul><ul><li>Performance Improvements and Smarter Plans </li></ul><ul><li>More SQL Constructs (order by, having clause…) </li></ul><ul><li>Data Compression </li></ul><ul><ul><li>Columnar storage schemes </li></ul></ul><ul><ul><li>Exploit lazy/functional Hive field retrieval interfaces </li></ul></ul><ul><li>Better data locality </li></ul><ul><ul><li>Co-locate hash partitions on same rack </li></ul></ul><ul><ul><li>Exploit high intra-rack bandwidth for merge joins </li></ul></ul><ul><li>Advanced operators </li></ul><ul><ul><li>Cubes/Frequent Item Sets/Window Functions </li></ul></ul>
    32. 32. Information <ul><li>Available as a contrib project in hadoop </li></ul><ul><ul><li>http://svn.apache.org/repos/asf/hadoop/core/ </li></ul></ul><ul><ul><li>Checkout src/contrib/hive from 0.19 onwards </li></ul></ul><ul><ul><li>Soon to be made a Sub Project so this will change!! </li></ul></ul><ul><li>Temporarily Latest distributions (including for hadoop-0.17) at: </li></ul><ul><li>http://mirror.facebook.com/facebook/hive/ </li></ul><ul><li>Mailing Lists: </li></ul><ul><ul><li>Temporarily: [email_address] </li></ul></ul><ul><ul><li>Moving to: hive-{user,dev,commits}@hadoop.apache.org </li></ul></ul>
    33. 33. Most Importantly – People @fb <ul><li>Contributors to Hive </li></ul><ul><ul><li>Suresh Anthony </li></ul></ul><ul><ul><li>Zheng Shao </li></ul></ul><ul><ul><li>Prasad Chakka </li></ul></ul><ul><ul><li>Pete Wyckoff </li></ul></ul><ul><ul><li>Namit Jain </li></ul></ul><ul><ul><li>Raghu Murthy </li></ul></ul><ul><ul><li>Joydeep Sen Sarma </li></ul></ul><ul><ul><li>Ashish Thusoo </li></ul></ul><ul><li>Contributors to HiPal(FBs Internal Web Interface to Hive) </li></ul><ul><ul><li>Hao Liu </li></ul></ul><ul><ul><li>Zheng Shao </li></ul></ul><ul><ul><li>David Wei </li></ul></ul><ul><li>Credits </li></ul><ul><ul><li>Dhruba Borthakur </li></ul></ul><ul><ul><li>Jeff Hammerbacher </li></ul></ul>
    34. 34. <ul><li>Questions? </li></ul>
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×