Database and MapReduce

Slides:



Advertisements
Similar presentations
Chapter 13: Query Processing
Advertisements

The Organisation As A System An information management framework The Performance Organiser Data Warehousing.
Information Systems Today: Managing in the Digital World
CHAPTER OBJECTIVE: NORMALIZATION THE SNOWFLAKE SCHEMA.
Supervisor : Prof . Abbdolahzadeh
1 Use or disclosure of data contained on this sheet is subject to the restriction on the title page of this proposal or quotation. An Introduction to Data.
IS 4420 Database Fundamentals Chapter 11: Data Warehousing Leon Chen
Chapter 13 The Data Warehouse
MapReduce.
OLAP Tuning. Outline OLAP 101 – Data warehouse architecture – ROLAP, MOLAP and HOLAP Data Cube – Star Schema and operations – The CUBE operator – Tuning.
MapReduce Online Created by: Rajesh Gadipuuri Modified by: Ying Lu.
Outline What is a data warehouse? A multi-dimensional data model Data warehouse architecture Data warehouse implementation Further development of data.
Data Warehousing CPS216 Notes 13 Shivnath Babu. 2 Warehousing l Growing industry: $8 billion way back in 1998 l Range from desktop to huge: u Walmart:
OLAP Services Business Intelligence Solutions. Agenda Definition of OLAP Types of OLAP Definition of Cube Definition of DMR Differences between Cube and.
Data Warehousing M R BRAHMAM.
MapReduce and databases Data-Intensive Information Processing Applications ― Session #7 Jimmy Lin University of Maryland Tuesday, March 23, 2010 This work.
Chapter 3 Database Management
Data Warehousing - 3 ISYS 650. Snowflake Schema one or more dimension tables do not join directly to the fact table but must join through other dimension.
1 Lecture 10: More OLAP - Dimensional modeling
Chapter 14 The Second Component: The Database.
CSE6011 Warehouse Models & Operators  Data Models  relations  stars & snowflakes  cubes  Operators  slice & dice  roll-up, drill down  pivoting.
Chapter 13 The Data Warehouse
CS346: Advanced Databases
Agenda Common terms used in the software of data warehousing and what they mean. Difference between a database and a data warehouse - the difference in.
HADOOP ADMIN: Session -2
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Decision Support Chapter 23.
Week 6 Lecture The Data Warehouse Samuel Conn, Asst. Professor
SQL Analysis Services Microsoft® SQL Server 2005 Analysis Services provides unified, fully integrated views of your business data to support online.
©Silberschatz, Korth and Sudarshan18.1Database System Concepts - 5 th Edition, Aug 26, 2005 Buzzword List OLTP – OnLine Transaction Processing (normalized,
Introduction to Hadoop and HDFS
OnLine Analytical Processing (OLAP)
An Introduction to HDInsight June 27 th,
ICOM 5016 – Introduction to Database Systems Lecture 5b Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
OLAP & DSS SUPPORT IN DATA WAREHOUSE By - Pooja Sinha Kaushalya Bakde.
Data Warehousing.
BI Terminologies.
Data Warehousing and OLAP. Warehousing ► Growing industry: $8 billion in 1998 ► Range from desktop to huge:  Walmart: 900-CPU, 2,700 disk, 23TB Teradata.
Ayyat IT Group Murad Faridi Roll NO#2492 Muhammad Waqas Roll NO#2803 Salman Raza Roll NO#2473 Junaid Pervaiz Roll NO#2468 Instructor :- “ Madam Sana Saeed”
Computing & Information Sciences Kansas State University Friday, 26 Jan 2008CIS 560: Database System Concepts Lecture 2 of 42 Friday, 29 August 2008 William.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
1 On-Line Analytic Processing Warehousing Data Cubes.
MapReduce Algorithm Design Based on Jimmy Lin’s slides
MapReduce and Data Management Based on slides from Jimmy Lin’s lecture slides ( (licensed.
CMPE 226 Database Systems October 21 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Advanced Database Concepts
Copyright© 2014, Sira Yongchareon Department of Computing, Faculty of Creative Industries and Business Lecturer : Dr. Sira Yongchareon ISCG 6425 Data Warehousing.
Big Data Infrastructure Week 6: Analyzing Relational Data (1/3) This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Data Warehousing and Decision Support.
Tallahassee, Florida, 2016 COP5725 Advanced Database Systems MapReduce Spring 2016.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Data Warehousing and Decision Support Chapter 25.
Introduction to OLAP and Data Warehouse Assoc. Professor Bela Stantic September 2014 Database Systems.
An Overview of Data Warehousing and OLAP Technology
Data Warehouses and OLAP 1.  Review Questions ◦ Question 1: OLAP ◦ Question 2: Data Warehouses ◦ Question 3: Various Terms and Definitions ◦ Question.
Or How I Learned to Love the Cube…. Alexander P. Nykolaiszyn BLOG:
Data Warehousing and OLAP Outline u Models & operations u Implementing a warehouse u Future directions.
Data Analysis Decision Support Systems Data Analysis and OLAP Data Warehousing.
Supervisor : Prof . Abbdolahzadeh
Data Warehousing CIS 4301 Lecture Notes 4/20/2006.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Data warehouse and OLAP
Chapter 13 The Data Warehouse
Introduction to PIG, HIVE, HBASE & ZOOKEEPER
Data Warehousing and OLAP
Charles Tappert Seidenberg School of CSIS, Pace University
Data Warehousing Concepts
Data-Intensive Distributed Computing
Copyright © JanBask Training. All rights reserved Get Started with Hadoop Hive HiveQL Languages.
Data Warehousing.
Presentation transcript:

Database and MapReduce Based on slides from Jimmy Lin’s lecture slides (http://www.umiacs.umd.edu/~jimmylin/cloud-2010-Spring/index.html) (licensed under Creation Commons Attribution 3.0 License)

RoadMap Role of relational databases in today’s organizations Where does MapReduce fit in? MapReduce algorithms for processing relational data How do I perform a join, etc.? Evolving roles of relational databases and MapReduce What’s in store for the future?

Relational Database Basics

Basic Structure Formally, given sets D1, D2, …. Dn a relation r is a subset of D1 x D2 x … x Dn Thus, a relation is a set of n-tuples (a1, a2, …, an) where each ai  Di Example: customer_name = {Jones, Smith, Curry, Lindsay} customer_street = {Main, North, Park} customer_city = {Harrison, Rye, Pittsfield} Then r = { (Jones, Main, Harrison), (Smith, North, Rye), (Curry, North, Rye), (Lindsay, Park, Pittsfield) } is a relation over customer_name , customer_street, customer_city

Relation Schema A1, A2, …, An are attributes R = (A1, A2, …, An ) is a relation schema Example: Customer_schema = (customer_name, customer_street, customer_city) r(R) is a relation on the relation schema R customer (Customer_schema)

Relation Instance The current values (relation instance) of a relation are specified by a table An element t of r is a tuple, represented by a row in a table attributes (or columns) customer_name customer_street customer_city Jones Smith Curry Lindsay Main North Park Harrison Rye Pittsfield tuples (or rows) customer

Database A database consists of multiple relations Information about an enterprise is broken up into parts, with each relation storing one part of the information account : stores information about accounts depositor : stores information about which customer owns which account customer : stores information about customers Storing all information as a single relation such as bank(account_number, balance, customer_name, ..) results in repetition of information (e.g., two customers own an account) and the need for null values (e.g., represent a customer without an account)

Banking Example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-city) account (account-number, branch-name, balance) loan (loan-number, branch-name, amount) depositor (customer-name, account-number) borrower (customer-name, loan-number)

Relational Algebra Primitives Other operations Projection () Selection () Cartesian product () Set union () Set difference () Rename () Other operations Join (⋈) Group by… aggregation …

Big Data Analysis Peta-scale datasets are everywhere: Facebook has 2.5 PB of user data + 15 TB/day (4/2009) eBay has 6.5 PB of user data + 50 TB/day (5/2009) … A lot of these datasets are (mostly) structured Query logs Point-of-sale records User data (e.g., demographics) How do we perform data analysis at scale? Relational databases and SQL MapReduce (Hadoop)

Relational Databases vs. MapReduce Multipurpose: analysis and transactions; batch and interactive Data integrity via ACID transactions Lots of tools in software ecosystem (for ingesting, reporting, etc.) Supports SQL (and SQL integration, e.g., JDBC) Automatic SQL query optimization MapReduce (Hadoop): Designed for large clusters, fault tolerant Data is accessed in “native format” Supports many query languages Programmers retain control over performance Open source Source: O’Reilly Blog post by Joseph Hellerstein (11/19/2008)

Database Workloads OLTP (online transaction processing) Typical applications: e-commerce, banking, airline reservations User facing: real-time, low latency, highly-concurrent Tasks: relatively small set of “standard” transactional queries Data access pattern: random reads, updates, writes (involving relatively small amounts of data) OLAP (online analytical processing) Typical applications: business intelligence, data mining Back-end processing: batch workloads, less concurrency Tasks: complex analytical queries, often ad hoc Data access pattern: table scans, large amounts of data involved per query

One Database or Two? Downsides of co-existing OLTP and OLAP workloads Poor memory management Conflicting data access patterns Variable latency Solution: separate databases User-facing OLTP database for high-volume transactions Data warehouse for OLAP workloads How do we connect the two?

OLTP/OLAP Architecture ETL (Extract, Transform, and Load)

OLTP/OLAP Integration OLTP database for user-facing transactions Retain records of all activity Periodic ETL (e.g., nightly) Extract-Transform-Load (ETL) Extract records from source Transform: clean data, check integrity, aggregate, etc. Load into OLAP database OLAP database for data warehousing Business intelligence: reporting, ad hoc queries, data mining, etc. Feedback to improve OLTP services

Warehouse Models & Operators Data Models relations stars & snowflakes cubes Operators slice & dice roll-up, drill down pivoting other

Star

Star Schema

Terms Fact table Dimension tables Measures

Dimension Hierarchies sType store city region è snowflake schema è constellations

Cube Fact table view: Multi-dimensional cube: dimensions = 2

3-D Cube dimensions = 3 Fact table view: Multi-dimensional cube: day 2

ROLAP vs. MOLAP ROLAP: Relational On-Line Analytical Processing MOLAP: Multi-Dimensional On-Line Analytical Processing

Typical OLAP Queries The typical OLAP query will: Start with a star join. Select for interesting tuples, based on dimension data. Group by one or more dimensions. Aggregate certain attributes of the result.

Aggregates Add up amounts for day 1 In SQL: SELECT sum(amt) FROM SALE WHERE date = 1 81

Aggregates Add up amounts by day In SQL: SELECT date, sum(amt) FROM SALE GROUP BY date

Another Example Add up amounts by day, product In SQL: SELECT date, sum(amt) FROM SALE GROUP BY date, prodId rollup drill-down

Aggregates Operators: sum, count, max, min, median, ave “Having” clause Using dimension hierarchy average by region (within store) maximum by month (within date)

Cube Aggregation Example: computing sums day 2 . . . day 1 129 rollup drill-down rollup

Cube Operators day 2 . . . day 1 sale(c1,*,*) 129 sale(c2,p2,*)

Extended Cube * day 2 sale(*,p2,*) day 1

Aggregation Using Hierarchies day 2 day 1 customer region country (customer c1 in Region A; customers c2, c3 in Region B)

Pivoting Fact table view: Multi-dimensional cube: day 2 day 1

Business Intelligence Premise: more data leads to better business decisions Periodic reporting as well as ad hoc queries Analysts, not programmers (importance of tools and dashboards) Examples: Slicing-and-dicing activity by different dimensions to better understand the marketplace Analyzing log data to improve OLTP experience Analyzing log data to better optimize ad placement Analyzing purchasing trends for better supply-chain management Mining for correlations between otherwise unrelated activities

OLTP/OLAP Architecture: Hadoop? What about here? ETL (Extract, Transform, and Load) Hadoop here?

OLTP/OLAP/Hadoop Architecture ETL (Extract, Transform, and Load) Why does this make sense?

ETL Bottleneck Reporting is often a nightly task: Hadoop is perfect: ETL is often slow: why? What happens if processing 24 hours of data takes longer than 24 hours? Hadoop is perfect: Most likely, you already have some data warehousing solution Ingest is limited by speed of HDFS Scales out with more nodes Massively parallel Ability to use any processing tool Much cheaper than parallel databases ETL is a batch process anyway!

MapReduce algorithms for processing relational data

Design Pattern: Secondary Sorting MapReduce sorts input to reducers by key Values are arbitrarily ordered What if want to sort value also? E.g., k → (v1, r), (v3, r), (v4, r), (v8, r)…

Secondary Sorting: Solutions Buffer values in memory, then sort Why is this a bad idea? Solution 2: “Value-to-key conversion” design pattern: form composite intermediate key, (k, v1) Let execution framework do the sorting Preserve state across multiple key-value pairs to handle processing Anything else we need to do?

Value-to-Key Conversion Before k → (v1, r), (v4, r), (v8, r), (v3, r)… Values arrive in arbitrary order… After (k, v1) → (v1, r) Values arrive in sorted order… (k, v3) → (v3, r) Process by preserving state across multiple keys Remember to partition correctly! (k, v4) → (v4, r) (k, v8) → (v8, r) …

Working Scenario Two tables: Analyses we might want to perform: User demographics (gender, age, income, etc.) User page visits (URL, time spent, etc.) Analyses we might want to perform: Statistics on demographic characteristics Statistics on page visits Statistics on page visits by URL Statistics on page visits by demographic characteristic …

Relational Algebra Primitives Other operations Projection () Selection () Cartesian product () Set union () Set difference () Rename () Other operations Join (⋈) Group by… aggregation …

Projection R1 R1 R2 R2 R3 R3 R4 R4 R5 R5

Projection in MapReduce Easy! Map over tuples, emit new tuples with appropriate attributes No reducers, unless for regrouping or resorting tuples Alternatively: perform in reducer, after some other processing Basically limited by HDFS streaming speeds Speed of encoding/decoding tuples becomes important Relational databases take advantage of compression Semistructured data? No problem!

Selection R1 R2 R1 R3 R3 R4 R5

Selection in MapReduce Easy! Map over tuples, emit only tuples that meet criteria No reducers, unless for regrouping or resorting tuples Alternatively: perform in reducer, after some other processing Basically limited by HDFS streaming speeds Speed of encoding/decoding tuples becomes important Relational databases take advantage of compression Semistructured data? No problem!

Group by… Aggregation Example: What is the average time spent per URL? In SQL: SELECT url, AVG(time) FROM visits GROUP BY url In MapReduce: Map over tuples, emit time, keyed by url Framework automatically groups values by keys Compute average in reducer Optimize with combiners

Relational Joins Source: Microsoft Office Clip Art

Relational Joins R1 S1 R2 S2 R3 S3 R4 S4 R1 S2 R2 S4 R3 S1 R4 S3

Natural Join Operation – Example Relations r, s: B D E A B C D 1 3 2 a b          1 2 4    a b r s r s A B C D E   1 2    a b   

Natural Join Example R1 S1 R1 S1 =

Types of Relationships Many-to-Many One-to-Many One-to-One

Join Algorithms in MapReduce Reduce-side join Map-side join In-memory join Striped variant Memcached variant

Reduce-side Join Basic idea: group by join key Two variants Map over both sets of tuples Emit tuple as value with join key as the intermediate key Execution framework brings together tuples sharing the same key Perform actual join in reducer Similar to a “sort-merge join” in database terminology Two variants 1-to-1 joins 1-to-many and many-to-many joins

Reduce-side Join: 1-to-1 Map keys values R1 R1 R4 R4 S2 S2 S3 S3 Reduce keys values R1 S2 S3 R4 Note: no guarantee if R is going to come first or S

Reduce-side Join: 1-to-many Map keys values R1 R1 S2 S2 S3 S3 S9 S9 Reduce keys values R1 S2 S3 … What’s the problem?

Reduce-side Join: V-to-K Conversion In reducer… keys values R1 New key encountered: hold in memory Cross with records from other set S2 S3 S9 R4 New key encountered: hold in memory Cross with records from other set S3 S7

Reduce-side Join: many-to-many In reducer… keys values R1 R5 Hold in memory R8 S2 Cross with records from other set S3 S9 What’s the problem?

Map-side Join: Basic Idea Assume two datasets are sorted by the join key: R1 S2 R2 S4 R4 S3 R3 S1 A sequential scan through both datasets to join (called a “merge join” in database terminology)

Map-side Join: Parallel Scans If datasets are sorted by join key, join can be accomplished by a scan over both datasets How can we accomplish this in parallel? Partition and sort both datasets in the same manner In MapReduce: Map over one dataset, read from other corresponding partition No reducers necessary (unless to repartition or resort) Consistently partitioned datasets: realistic to expect?

In-Memory Join Basic idea: load one dataset into memory, stream over other dataset Works if R << S and R fits into memory Called a “hash join” in database terminology MapReduce implementation Distribute R to all nodes Map over S, each mapper loads R in memory, hashed by join key For every tuple in S, look up join key in R No reducers, unless for regrouping or resorting tuples

In-Memory Join: Variants Striped variant: R too big to fit into memory? Divide R into R1, R2, R3, … s.t. each Rn fits into memory Perform in-memory join: n, Rn ⋈ S Take the union of all join results Memcached join: Load R into memcached Replace in-memory hash lookup with memcached lookup

Memcached Caching servers: 15 million requests per second, 95% handled by memcache (15 TB of RAM) Database layer: 800 eight-core Linux servers running MySQL (40 TB user data) Source: Technology Review (July/August, 2008)

Memcached Join Memcached join: Capacity and scalability? Latency? Load R into memcached Replace in-memory hash lookup with memcached lookup Capacity and scalability? Memcached capacity >> RAM of individual node Memcached scales out with cluster Latency? Memcached is fast (basically, speed of network) Batch requests to amortize latency costs Source: See tech report by Lin et al. (2009)

Which join to use? In-memory join > map-side join > reduce-side join Why? Limitations of each? In-memory join: memory Map-side join: sort order and partitioning Reduce-side join: general purpose

Processing Relational Data: Summary MapReduce algorithms for processing relational data: Group by, sorting, partitioning are handled automatically by shuffle/sort in MapReduce Selection, projection, and other computations (e.g., aggregation), are performed either in mapper or reducer Multiple strategies for relational joins Complex operations require multiple MapReduce jobs Example: top ten URLs in terms of average time spent Opportunities for automatic optimization

Evolving roles for relational database and MapReduce

OLTP/OLAP/Hadoop Architecture ETL (Extract, Transform, and Load) Why does this make sense?

Need for High-Level Languages Hadoop is great for large-data processing! But writing Java programs for everything is verbose and slow Analysts don’t want to (or can’t) write Java Solution: develop higher-level data processing languages Hive: HQL is like SQL Pig: Pig Latin is a bit like Perl

Hive and Pig Hive: data warehousing application in Hadoop Query language is HQL, variant of SQL Tables stored on HDFS as flat files Developed by Facebook, now open source Pig: large-scale data processing system Scripts are written in Pig Latin, a dataflow language Developed by Yahoo!, now open source Roughly 1/3 of all Yahoo! internal jobs Common idea: Provide higher-level language to facilitate large-data processing Higher-level language “compiles down” to Hadoop jobs