Breaking first-normal form with Hive
Upcoming SlideShare
Loading in...5
×
 

Breaking first-normal form with Hive

on

  • 1,859 views

Violating first normal form can be a good way to use hive.

Violating first normal form can be a good way to use hive.

Statistics

Views

Total Views
1,859
Views on SlideShare
1,858
Embed Views
1

Actions

Likes
0
Downloads
11
Comments
0

1 Embed 1

http://www.docseek.net 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 10/01/10

Breaking first-normal form with Hive Breaking first-normal form with Hive Presentation Transcript

  • Breaking first normal form Nov 2011
  • 1 st Normal Form
    • In a nutshell, to be 1NF do not:
      • userid firstname,lastname, nicknames
      • 1,ed,capriolo,killer;spike;iceman;tbone
      • (these are not my nicknames btw)
    • Why do this in typically relational databases?
      • Relational designs wants this in a one-to-many or many/many relationship across two or three tables
      • Easier to build ordered indexes
      • Most relational databases are design for narrow columns
  • But Hive ain't your grandmas datastore
    • Normalizing and 3nf is in not usually a good idea in map reduce and hive
    • Joins can be done map side and reduce side
    • There is now index support. Way to go sichi et all!
    • But STILL hive is not your grandmothers datastore, if you design thinking about joins and indexes your probably not modeling the design correctly
  • A quick note about m6d (media6degrees)
    • Online advertising
    • A prospect engine for brands
    • We have to use cookies in many places
    • Cookies have limited size
    • Cookies have binary values encoded
  • Hacking data to make it smaller
    • LastSeen: long (64 bits)
    • Segment: int (32 bits)
    • Literal ','
    • Segment: int (32 bits)
    • Zipcode (32bits)
    • 1 chose a relevant epoc and use byte
    • Use a byte for # of segments
    • Use a 4 byte radix encoded number
    • ... and so on
  • Nice its a smaller cookie. But now it looks like: abe34zfjtowsafsgsg34
    • So parsing this value could be PITA
    • We could make upstream log hive friendly
    • But I never go upstream, i work in my box
  • Solution 1: Lot's o UDFs: Rejected
    • Write N UDFS for each object like:
    • getLastSeenForCookie(String)
    • getZipcodeForCookie(String)
    • ...
    • But this would have made a huge toolkit
  • Solution 2: Structs
    • Hive has a struct like a c struct
    • Struct is list of name value pair
    • Structs can contain other structs!!!!
    • This gives us the serious ability to do object mapping!!!
    • UDFs can return structs!!!
  • Solution in action
    • Add jar myjar.jar;
    • Create temporary function parseCookie as 'com.md6.ParseCookieIntoStruct' ;
    • Select parseCookie(encodedColumn).lastSeen from mydata;
    • Sweet! now we have access to scalar members in side encoded object with hive
  • Hive lateral view and explode
    • In my mind the coolest feature since dynamic partitions
    • Lateral view and explode allows us to convert an embedded list into rows.
    • This is very powerful for our nested objects
  • Sample query
    • SELECT
    • client_id, entry.spendcreativeid
    • FROM datatable
    • LATERAL VIEW explode (AdHistoryAsStruct(ad_history).adEntrylist) entryList as entry
    • where hit_date=20110321 AND mid=001406;
    • 3214498023360851706 215286
    • 3214498023360851706 195785
    • 3214498023360851706 128640
  • Questions? Carl says no questions sorry.