SlideShare a Scribd company logo
1© Cloudera, Inc. All rights reserved.
Simplifying Analytic Workloads via Complex Schemas
Marcel Kornacker
Data Modeling for Data Science
2© Cloudera, Inc. All rights reserved.
• Relational databases are optimized
to work with flat schemas
• Much of the useful information in
the world is stored using complex
schemas (a.k.a., the “document
model”)
• Log files
• NoSQL data stores
• REST APIs
On Complex Schemas
3© Cloudera, Inc. All rights reserved.
Handling Complex Schemas in SQL
4© Cloudera, Inc. All rights reserved.
Complex Schemas and Data Science
5© Cloudera, Inc. All rights reserved.
Think Like A Data Scientist
6© Cloudera, Inc. All rights reserved.
Building Data Science Teams: A Moneyball Approach
7© Cloudera, Inc. All rights reserved.
Leveraging The Power of SQL Engines…
8© Cloudera, Inc. All rights reserved.
…While Managing the Cost of SQL Engines
9© Cloudera, Inc. All rights reserved.
Intentional Complex Schemas
10© Cloudera, Inc. All rights reserved.
Better Resource Utilization
11© Cloudera, Inc. All rights reserved.
Higher Data Quality
12© Cloudera, Inc. All rights reserved.
Simplifying Analytic Queries
13© Cloudera, Inc. All rights reserved.
Data Science For Everyone
14© Cloudera, Inc. All rights reserved.
Nested Types in Impala
Support for Nested Data Types: STRUCT, MAP, ARRAY
Natural Extensions to SQL
Full Expressiveness of SQL with Nested Types
15© Cloudera, Inc. All rights reserved.
Example TPCH-like Schema
CREATE TABLE Customers {
id BIGINT,
address STRUCT<
city: STRING,
zip: INT
>
orders ARRAY<STRUCT<
date: TIMESTAMP,
price: DECIMAL(12,2),
cc: BIGINT,
items: ARRAY<STRUCT<
item_no: STRING,
price: DECIMAL(9,2)
>>
>>
}
16© Cloudera, Inc. All rights reserved.
Impala Syntax Extensions
• Path expressions extend column references to scalars (nested structs)
• Can appear anywhere a conventional column reference is used
• Collections (maps and arrays) are exposed like sub-tables
• Use FROM clause to specify which collections to read like conventional tables
• Can use JOIN conditions to express join relationship (default is INNER JOIN)
Find the ids and city of customers who live in the zip code 94305:
SELECT id, address.city FROM customers WHERE address.zip = 94305
Find all orders that were paid for with a customer’s preferred credit card:
SELECT o.txn_id FROM customers c, c.orders o WHERE o.cc = c.preferred_cc
17© Cloudera, Inc. All rights reserved.
Referencing Arrays & Maps
• Basic idea: Flatten nested collections referenced in the FROM clause
• Can be thought of as an implicit join on the parent/child relationship
SELECT c.id, o.date FROM customers c, c.c_orders o
c.id o.date
100 2012-05-03
100 2013-07-08
100 2011-01-29
… …
101 2014-02-04
101 2015-11-15
… …
id of a customer
repeated for every order
18© Cloudera, Inc. All rights reserved.
Referencing Arrays & Maps
SELECT c.c_custkey, o.o_orderkey
FROM customers c, c.c_orders o
Returns customer/order data for customers that have at least one order
SELECT c.c_custkey, o.o_orderkey
FROM customers c LEFT OUTER JOIN c.c_orders o
Also returns customers with no orders (with order fields NULL)
SELECT c.c_custkey, o.o_orderkey
FROM customers c LEFT ANTI JOIN c.orders o
Find all customers that have no orders
SELECT c.c_custkey, o.o_orderkey
FROM customers c INNER JOIN c.c_orders o
19© Cloudera, Inc. All rights reserved.
Motivation for Advanced Querying Capabilities
• Count the number of orders per customer
• Count the number of items per order
• Impractical Requires unique id at every nesting level
• Information is already expressed in nesting relationship!
• What about even more interesting queries?
• Get the number of orders and the average item price per customer?
• “Group by” multiple nesting levels at the same time
SELECT COUNT(*) FROM customers c, c.orders o GROUP BY c.id
SELECT COUNT(*) FROM customers.orders o, o.items GROUP BY ???
Must be unique
20© Cloudera, Inc. All rights reserved.
Advanced Querying: Aggregates over Nested Collections
• Count the number of orders per customer
• Count the number of items per order
• Get the number of orders and the average item price per customer
SELECT id, COUNT(orders) FROM customers
SELECT date, COUNT(items) FROM customers.orders
SELECT id, COUNT(orders), AVG(orders.items.price) FROM customers
21© Cloudera, Inc. All rights reserved.
Advanced Querying: Relative Table References
• Full expressibility of SQL with nested collections
• Arbitrary SQL allowed in inline views and subqueries with relative table refs
• Exploits nesting relationship
• No need for stored unique ids at all interesting levels
SELECT id FROM customers c
WHERE (SELECT AVG(price) FROM c.orders.items) > 1000
SELECT id FROM customers c JOIN
(SELECT price FROM c.orders ORDER BY date DESC LIMIT 2) v
22© Cloudera, Inc. All rights reserved.
Impala Nested Types in Action
Josh Wills’ Blog post on analyzing misspelled queries
http://blog.cloudera.com/blog/2014/08/how-to-count-events-like-a-data-scientist/
• Goal: Rudimentary spell checker based on counting query/click events
• Problem: Cross referencing items in multiple nested collections
• Representative of many machine learning tasks (Josh tells me)
• Goal was not naturally achievable with Hive
• Josh implemented a custom Hive extension “WITHIN”
• How can Impala serve this use case?
23© Cloudera, Inc. All rights reserved.
Impala Nested Types in Action
account_id: bigint
search_events:
array<struct<
event_id: bigint
query: string
tstamp_sec: bigint
...
>>
install_events:
array<struct<
event_id: bigint
search_event_id: bigint
app_id: bigint
...
>>
SELECT bad.query, good.query, count(*) as cnt
FROM sessions s,
s.search_events bad,
s.search_events good,
WHERE bad.tstamp_sec < good.tstamp_sec
AND good.tstamp_sec - bad.tstamp_sec < 30
AND bad.event_id NOT IN (select search_event_id FROM s.install_events)
AND good.event_id IN (select search_event_id FROM s.install_events),
GROUP BY bad.query, good.query
Schema
24© Cloudera, Inc. All rights reserved.
Design Considerations for Complex Schemas
• Turn parent-child hierarchies into nested collections
• logical hierarchy becomes physical hierarchy
• nested structure = join index
physical clustering of child with parent
• For distributed, big data systems, this matter:
distributed join turns into local join
25© Cloudera, Inc. All rights reserved.
Flat TPCH vs. Nested TPCH
Part PartSupp
Supplier Lineitem
Customer Orders
Nation Region
Part
PartSupp
Suppliers
Lineitems
Customer
Orders
Nation
Region
1 N
1
N
1
N
1
N
N
1 N
1
N
1
N 1
N
1
1
N
N
1
26© Cloudera, Inc. All rights reserved.
Columnar Storage for Complex Schemas
• Columnar storage: a necessity for processing nested data at speed
• complex schemas = really wide tables
• row-wise storage: read lots of data you don’t care about
• Columnar formats effectively store a join index
{id: 17
orders: [{date: 2014-01-29, price: 10.2}, {date: ….} …]
}
{id: 18
orders: [{date: 2015-04-10, price: 2000.0}, {date: ….} …]
}
17
18
10.2
22.1
100
200
id orders.price
…
…
…
27© Cloudera, Inc. All rights reserved.
Columnar Storage for Complex Schemas
• A “join” between parent and child is essentially free:
• coordinated scan of parent and child columns
• data effectively pre-sorted on parent PK
• merge join beats hash join!
• Aggregating child data is cheap:
• the data is already pre-grouped by the parent
• Amenable to vectorized execution
• Local non-grouping aggregation <<< distributed grouping aggregation
28© Cloudera, Inc. All rights reserved.
Analytics on Nested Data: Cheap & Easy!
SELECT c.id, AVG(orders.items.price) avg_price
FROM customer
ORDER BY avg_price DESC LIMIT 10
Query: Find the 10 customers that buy the most expensive items on average
SELECT c.id, AVG(i.price) avg_price
FROM customer c, order o, item i
WHERE c.id = o.cid and o.id = i.oid
GROUP BY c.id
ORDER BY avg_price DESC LIMIT 10
Flat Nested
29© Cloudera, Inc. All rights reserved.
Scan Scan
Xch Xch
Join
Scan
Xch
Join
Agg
Xch
Agg
Scan
Unnest
Agg
Top-n
Xch
Top-n
Top-n
Xch
Top-n
Analytics on Nested Data: Cheap & Easy!
$$$
30© Cloudera, Inc. All rights reserved.
A Note to BI Tool Vendors
Please support nested types, it’s not that hard!
• you already take advantage of declared PK/FK relationships
• a nested collection isn’t really that different
• except you don’t need a join predicate
31© Cloudera, Inc. All rights reserved.
Thank you

More Related Content

PDF
Actionable Insights with AI - Snowflake for Data Science
PPTX
Intro to Data Vault 2.0 on Snowflake
PPTX
Introducing the Snowflake Computing Cloud Data Warehouse
PDF
Analyzing Semi-Structured Data At Volume In The Cloud
PPTX
Demystifying Data Warehouse as a Service
PDF
Sydney: Certus Data 2.0 Vault Meetup with Snowflake - Data Vault In The Cloud
PDF
Making Sense of Schema on Read
PPTX
Elastic Data Warehousing
Actionable Insights with AI - Snowflake for Data Science
Intro to Data Vault 2.0 on Snowflake
Introducing the Snowflake Computing Cloud Data Warehouse
Analyzing Semi-Structured Data At Volume In The Cloud
Demystifying Data Warehouse as a Service
Sydney: Certus Data 2.0 Vault Meetup with Snowflake - Data Vault In The Cloud
Making Sense of Schema on Read
Elastic Data Warehousing

What's hot (17)

PDF
Demystifying Data Warehousing as a Service (GLOC 2019)
PPTX
Altis AWS Snowflake Practice
PDF
SLC Snowflake User Group - Mar 12, 2020
PDF
Delivering rapid-fire Analytics with Snowflake and Tableau
PDF
Agile Data Warehousing: Using SDDM to Build a Virtualized ODS
PDF
AWS Summit Singapore 2019 | Snowflake: Your Data. No Limits
PDF
Melbourne: Certus Data 2.0 Vault Meetup with Snowflake - Data Vault In The Cl...
PDF
Dataiku & Snowflake Meetup Berlin 2020
PPTX
How to Realize an Additional 270% ROI on Snowflake
PDF
Demystifying Data Warehousing as a Service - DFW
PPTX
A 30 day plan to start ending your data struggle with Snowflake
PPTX
Optimize the performance, cost, and value of databases.pptx
PDF
Smartsheet’s Transition to Snowflake and Databricks: The Why and Immediate Im...
PDF
Self-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
PPTX
Get Savvy with Snowflake
PPT
Star schema my sql
PDF
Changing the game with cloud dw
Demystifying Data Warehousing as a Service (GLOC 2019)
Altis AWS Snowflake Practice
SLC Snowflake User Group - Mar 12, 2020
Delivering rapid-fire Analytics with Snowflake and Tableau
Agile Data Warehousing: Using SDDM to Build a Virtualized ODS
AWS Summit Singapore 2019 | Snowflake: Your Data. No Limits
Melbourne: Certus Data 2.0 Vault Meetup with Snowflake - Data Vault In The Cl...
Dataiku & Snowflake Meetup Berlin 2020
How to Realize an Additional 270% ROI on Snowflake
Demystifying Data Warehousing as a Service - DFW
A 30 day plan to start ending your data struggle with Snowflake
Optimize the performance, cost, and value of databases.pptx
Smartsheet’s Transition to Snowflake and Databricks: The Why and Immediate Im...
Self-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
Get Savvy with Snowflake
Star schema my sql
Changing the game with cloud dw
Ad

Viewers also liked (20)

PPTX
Sumo Logic quickStart Webinar June 2016
PPTX
Sumo Logic QuickStart Webinar Oct 2016
PPTX
Sumo Logic Webinar: Visibility into your Host Metrics
PPTX
Sumo Logic: Optimizing Scheduled Searches
PPTX
Sumo Logic Quickstart - Nv 2016
PPTX
How Hudl and Cloud Cruiser Leverage Sumo Logic's Unified Logs and Metrics
PPTX
Sumo Logic Quickstart - Jan 2017
PDF
Sumo Logic - Optimizing Your Search Experience (2016-08-17)
PPTX
Sumo Logic "How to" Webinar: Advanced Analytics
PPTX
"How to" Webinar: Sending Data to Sumo Logic
PPTX
Sumo Logic QuickStart Webinar - Dec 2016
PPTX
Standing Up an Effective Enterprise Data Hub -- Technology and Beyond
PDF
The Future of Data Management: The Enterprise Data Hub
PPTX
Bring your Graphite-compatible metrics into Sumo Logic
PPTX
Enterprise Data Hub: The Next Big Thing in Big Data
PDF
Memory Heap Analysis with AppDynamics - AppSphere16
PDF
Thousands of JVMs, Hundreds of Applications, and Two People: How Cerner Learn...
PDF
How the World Bank Standardized on AppDynamics as its Enterprise-Wide APM Sol...
PPTX
The Future of Data Management: The Enterprise Data Hub
PDF
AppDynamics Administration - AppSphere16
Sumo Logic quickStart Webinar June 2016
Sumo Logic QuickStart Webinar Oct 2016
Sumo Logic Webinar: Visibility into your Host Metrics
Sumo Logic: Optimizing Scheduled Searches
Sumo Logic Quickstart - Nv 2016
How Hudl and Cloud Cruiser Leverage Sumo Logic's Unified Logs and Metrics
Sumo Logic Quickstart - Jan 2017
Sumo Logic - Optimizing Your Search Experience (2016-08-17)
Sumo Logic "How to" Webinar: Advanced Analytics
"How to" Webinar: Sending Data to Sumo Logic
Sumo Logic QuickStart Webinar - Dec 2016
Standing Up an Effective Enterprise Data Hub -- Technology and Beyond
The Future of Data Management: The Enterprise Data Hub
Bring your Graphite-compatible metrics into Sumo Logic
Enterprise Data Hub: The Next Big Thing in Big Data
Memory Heap Analysis with AppDynamics - AppSphere16
Thousands of JVMs, Hundreds of Applications, and Two People: How Cerner Learn...
How the World Bank Standardized on AppDynamics as its Enterprise-Wide APM Sol...
The Future of Data Management: The Enterprise Data Hub
AppDynamics Administration - AppSphere16
Ad

Similar to Marcel Kornacker, Software Enginner at Cloudera - "Data modeling for data science: Simplify your workload with complex types" (20)

PPTX
Data Modeling for Data Science: Simplify Your Workload with Complex Types in ...
PDF
Nested Types in Impala
PDF
Nested Types in Impala
PPTX
Friction-free ETL: Automating data transformation with Impala | Strata + Hado...
PPTX
Hug meetup impala 2.5 performance overview
PPTX
Apache Impala (incubating) 2.5 Performance Update
PDF
Impala: Real-time Queries in Hadoop
PDF
What's New in Apache Hive
PPTX
Hadoop vs. RDBMS for Advanced Analytics
PDF
Cjoin
PPTX
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
PPTX
Cloud DWH deep dive
PDF
Advanced MariaDB features that developers love.pdf
PDF
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
PPTX
Interactive query using hadoop
PPTX
Querying NoSQL with SQL - KCDC - August 2017
PPTX
Hadoop & Hive Change the Data Warehousing Game Forever
PDF
ClickHouse Features for Advanced Users, by Aleksei Milovidov
PPTX
The Impala Cookbook
PDF
Cloudera Impala
Data Modeling for Data Science: Simplify Your Workload with Complex Types in ...
Nested Types in Impala
Nested Types in Impala
Friction-free ETL: Automating data transformation with Impala | Strata + Hado...
Hug meetup impala 2.5 performance overview
Apache Impala (incubating) 2.5 Performance Update
Impala: Real-time Queries in Hadoop
What's New in Apache Hive
Hadoop vs. RDBMS for Advanced Analytics
Cjoin
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
Cloud DWH deep dive
Advanced MariaDB features that developers love.pdf
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
Interactive query using hadoop
Querying NoSQL with SQL - KCDC - August 2017
Hadoop & Hive Change the Data Warehousing Game Forever
ClickHouse Features for Advanced Users, by Aleksei Milovidov
The Impala Cookbook
Cloudera Impala

More from Dataconomy Media (20)

PDF
Data Natives Paris v 10.0 | "Blockchain in Healthcare" - Lea Dias & David An...
PDF
Data Natives Frankfurt v 11.0 | "Competitive advantages with knowledge graphs...
PDF
Data Natives Frankfurt v 11.0 | "Can we be responsible for misuse of data & a...
PDF
Data Natives Munich v 12.0 | "How to be more productive with Autonomous Data ...
PPTX
Data Natives meets DataRobot | "Build and deploy an anti-money laundering mo...
PPTX
Data Natives Munich v 12.0 | "Political Data Science: A tale of Fake News, So...
PPTX
Data Natives Vienna v 7.0 | "Building Kubernetes Operators with KUDO for Dat...
PDF
Data Natives Vienna v 7.0 | "The Ingredients of Data Innovation" - Robbert de...
PPTX
Data Natives Cologne v 4.0 | "The Data Lorax: Planting the Seeds of Fairness...
PDF
Data Natives Cologne v 4.0 | "How People Analytics Can Reveal the Hidden Aspe...
PPTX
Data Natives Amsterdam v 9.0 | "Ten Little Servers: A Story of no Downtime" -...
PDF
Data Natives Amsterdam v 9.0 | "Point in Time Labeling at Scale" - Timothy Th...
PDF
Data Natives Hamburg v 6.0 | "Interpersonal behavior: observing Alex to under...
PDF
Data Natives Hamburg v 6.0 | "About Surfing, Failing & Scaling" - Florian Sch...
PDF
Data NativesBerlin v 20.0 | "Serving A/B experimentation platform end-to-end"...
PPTX
Data Natives Berlin v 20.0 | "Ten Little Servers: A Story of no Downtime" - A...
PDF
Big Data Frankfurt meets Thinkport | "The Cloud as a Driver of Innovation" - ...
PPTX
Thinkport meets Frankfurt | "Financial Time Series Analysis using Wavelets" -...
PPTX
Big Data Helsinki v 3 | "Distributed Machine and Deep Learning at Scale with ...
PPTX
Big Data Helsinki v 3 | "Federated Learning and Privacy-preserving AI" - Oguz...
Data Natives Paris v 10.0 | "Blockchain in Healthcare" - Lea Dias & David An...
Data Natives Frankfurt v 11.0 | "Competitive advantages with knowledge graphs...
Data Natives Frankfurt v 11.0 | "Can we be responsible for misuse of data & a...
Data Natives Munich v 12.0 | "How to be more productive with Autonomous Data ...
Data Natives meets DataRobot | "Build and deploy an anti-money laundering mo...
Data Natives Munich v 12.0 | "Political Data Science: A tale of Fake News, So...
Data Natives Vienna v 7.0 | "Building Kubernetes Operators with KUDO for Dat...
Data Natives Vienna v 7.0 | "The Ingredients of Data Innovation" - Robbert de...
Data Natives Cologne v 4.0 | "The Data Lorax: Planting the Seeds of Fairness...
Data Natives Cologne v 4.0 | "How People Analytics Can Reveal the Hidden Aspe...
Data Natives Amsterdam v 9.0 | "Ten Little Servers: A Story of no Downtime" -...
Data Natives Amsterdam v 9.0 | "Point in Time Labeling at Scale" - Timothy Th...
Data Natives Hamburg v 6.0 | "Interpersonal behavior: observing Alex to under...
Data Natives Hamburg v 6.0 | "About Surfing, Failing & Scaling" - Florian Sch...
Data NativesBerlin v 20.0 | "Serving A/B experimentation platform end-to-end"...
Data Natives Berlin v 20.0 | "Ten Little Servers: A Story of no Downtime" - A...
Big Data Frankfurt meets Thinkport | "The Cloud as a Driver of Innovation" - ...
Thinkport meets Frankfurt | "Financial Time Series Analysis using Wavelets" -...
Big Data Helsinki v 3 | "Distributed Machine and Deep Learning at Scale with ...
Big Data Helsinki v 3 | "Federated Learning and Privacy-preserving AI" - Oguz...

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
Teaching material agriculture food technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Empathic Computing: Creating Shared Understanding
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Big Data Technologies - Introduction.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Encapsulation_ Review paper, used for researhc scholars
Diabetes mellitus diagnosis method based random forest with bat algorithm
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Teaching material agriculture food technology
sap open course for s4hana steps from ECC to s4
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Network Security Unit 5.pdf for BCA BBA.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
20250228 LYD VKU AI Blended-Learning.pptx
Machine learning based COVID-19 study performance prediction
Review of recent advances in non-invasive hemoglobin estimation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Building Integrated photovoltaic BIPV_UPV.pdf

Marcel Kornacker, Software Enginner at Cloudera - "Data modeling for data science: Simplify your workload with complex types"

  • 1. 1© Cloudera, Inc. All rights reserved. Simplifying Analytic Workloads via Complex Schemas Marcel Kornacker Data Modeling for Data Science
  • 2. 2© Cloudera, Inc. All rights reserved. • Relational databases are optimized to work with flat schemas • Much of the useful information in the world is stored using complex schemas (a.k.a., the “document model”) • Log files • NoSQL data stores • REST APIs On Complex Schemas
  • 3. 3© Cloudera, Inc. All rights reserved. Handling Complex Schemas in SQL
  • 4. 4© Cloudera, Inc. All rights reserved. Complex Schemas and Data Science
  • 5. 5© Cloudera, Inc. All rights reserved. Think Like A Data Scientist
  • 6. 6© Cloudera, Inc. All rights reserved. Building Data Science Teams: A Moneyball Approach
  • 7. 7© Cloudera, Inc. All rights reserved. Leveraging The Power of SQL Engines…
  • 8. 8© Cloudera, Inc. All rights reserved. …While Managing the Cost of SQL Engines
  • 9. 9© Cloudera, Inc. All rights reserved. Intentional Complex Schemas
  • 10. 10© Cloudera, Inc. All rights reserved. Better Resource Utilization
  • 11. 11© Cloudera, Inc. All rights reserved. Higher Data Quality
  • 12. 12© Cloudera, Inc. All rights reserved. Simplifying Analytic Queries
  • 13. 13© Cloudera, Inc. All rights reserved. Data Science For Everyone
  • 14. 14© Cloudera, Inc. All rights reserved. Nested Types in Impala Support for Nested Data Types: STRUCT, MAP, ARRAY Natural Extensions to SQL Full Expressiveness of SQL with Nested Types
  • 15. 15© Cloudera, Inc. All rights reserved. Example TPCH-like Schema CREATE TABLE Customers { id BIGINT, address STRUCT< city: STRING, zip: INT > orders ARRAY<STRUCT< date: TIMESTAMP, price: DECIMAL(12,2), cc: BIGINT, items: ARRAY<STRUCT< item_no: STRING, price: DECIMAL(9,2) >> >> }
  • 16. 16© Cloudera, Inc. All rights reserved. Impala Syntax Extensions • Path expressions extend column references to scalars (nested structs) • Can appear anywhere a conventional column reference is used • Collections (maps and arrays) are exposed like sub-tables • Use FROM clause to specify which collections to read like conventional tables • Can use JOIN conditions to express join relationship (default is INNER JOIN) Find the ids and city of customers who live in the zip code 94305: SELECT id, address.city FROM customers WHERE address.zip = 94305 Find all orders that were paid for with a customer’s preferred credit card: SELECT o.txn_id FROM customers c, c.orders o WHERE o.cc = c.preferred_cc
  • 17. 17© Cloudera, Inc. All rights reserved. Referencing Arrays & Maps • Basic idea: Flatten nested collections referenced in the FROM clause • Can be thought of as an implicit join on the parent/child relationship SELECT c.id, o.date FROM customers c, c.c_orders o c.id o.date 100 2012-05-03 100 2013-07-08 100 2011-01-29 … … 101 2014-02-04 101 2015-11-15 … … id of a customer repeated for every order
  • 18. 18© Cloudera, Inc. All rights reserved. Referencing Arrays & Maps SELECT c.c_custkey, o.o_orderkey FROM customers c, c.c_orders o Returns customer/order data for customers that have at least one order SELECT c.c_custkey, o.o_orderkey FROM customers c LEFT OUTER JOIN c.c_orders o Also returns customers with no orders (with order fields NULL) SELECT c.c_custkey, o.o_orderkey FROM customers c LEFT ANTI JOIN c.orders o Find all customers that have no orders SELECT c.c_custkey, o.o_orderkey FROM customers c INNER JOIN c.c_orders o
  • 19. 19© Cloudera, Inc. All rights reserved. Motivation for Advanced Querying Capabilities • Count the number of orders per customer • Count the number of items per order • Impractical Requires unique id at every nesting level • Information is already expressed in nesting relationship! • What about even more interesting queries? • Get the number of orders and the average item price per customer? • “Group by” multiple nesting levels at the same time SELECT COUNT(*) FROM customers c, c.orders o GROUP BY c.id SELECT COUNT(*) FROM customers.orders o, o.items GROUP BY ??? Must be unique
  • 20. 20© Cloudera, Inc. All rights reserved. Advanced Querying: Aggregates over Nested Collections • Count the number of orders per customer • Count the number of items per order • Get the number of orders and the average item price per customer SELECT id, COUNT(orders) FROM customers SELECT date, COUNT(items) FROM customers.orders SELECT id, COUNT(orders), AVG(orders.items.price) FROM customers
  • 21. 21© Cloudera, Inc. All rights reserved. Advanced Querying: Relative Table References • Full expressibility of SQL with nested collections • Arbitrary SQL allowed in inline views and subqueries with relative table refs • Exploits nesting relationship • No need for stored unique ids at all interesting levels SELECT id FROM customers c WHERE (SELECT AVG(price) FROM c.orders.items) > 1000 SELECT id FROM customers c JOIN (SELECT price FROM c.orders ORDER BY date DESC LIMIT 2) v
  • 22. 22© Cloudera, Inc. All rights reserved. Impala Nested Types in Action Josh Wills’ Blog post on analyzing misspelled queries http://blog.cloudera.com/blog/2014/08/how-to-count-events-like-a-data-scientist/ • Goal: Rudimentary spell checker based on counting query/click events • Problem: Cross referencing items in multiple nested collections • Representative of many machine learning tasks (Josh tells me) • Goal was not naturally achievable with Hive • Josh implemented a custom Hive extension “WITHIN” • How can Impala serve this use case?
  • 23. 23© Cloudera, Inc. All rights reserved. Impala Nested Types in Action account_id: bigint search_events: array<struct< event_id: bigint query: string tstamp_sec: bigint ... >> install_events: array<struct< event_id: bigint search_event_id: bigint app_id: bigint ... >> SELECT bad.query, good.query, count(*) as cnt FROM sessions s, s.search_events bad, s.search_events good, WHERE bad.tstamp_sec < good.tstamp_sec AND good.tstamp_sec - bad.tstamp_sec < 30 AND bad.event_id NOT IN (select search_event_id FROM s.install_events) AND good.event_id IN (select search_event_id FROM s.install_events), GROUP BY bad.query, good.query Schema
  • 24. 24© Cloudera, Inc. All rights reserved. Design Considerations for Complex Schemas • Turn parent-child hierarchies into nested collections • logical hierarchy becomes physical hierarchy • nested structure = join index physical clustering of child with parent • For distributed, big data systems, this matter: distributed join turns into local join
  • 25. 25© Cloudera, Inc. All rights reserved. Flat TPCH vs. Nested TPCH Part PartSupp Supplier Lineitem Customer Orders Nation Region Part PartSupp Suppliers Lineitems Customer Orders Nation Region 1 N 1 N 1 N 1 N N 1 N 1 N 1 N 1 N 1 1 N N 1
  • 26. 26© Cloudera, Inc. All rights reserved. Columnar Storage for Complex Schemas • Columnar storage: a necessity for processing nested data at speed • complex schemas = really wide tables • row-wise storage: read lots of data you don’t care about • Columnar formats effectively store a join index {id: 17 orders: [{date: 2014-01-29, price: 10.2}, {date: ….} …] } {id: 18 orders: [{date: 2015-04-10, price: 2000.0}, {date: ….} …] } 17 18 10.2 22.1 100 200 id orders.price … … …
  • 27. 27© Cloudera, Inc. All rights reserved. Columnar Storage for Complex Schemas • A “join” between parent and child is essentially free: • coordinated scan of parent and child columns • data effectively pre-sorted on parent PK • merge join beats hash join! • Aggregating child data is cheap: • the data is already pre-grouped by the parent • Amenable to vectorized execution • Local non-grouping aggregation <<< distributed grouping aggregation
  • 28. 28© Cloudera, Inc. All rights reserved. Analytics on Nested Data: Cheap & Easy! SELECT c.id, AVG(orders.items.price) avg_price FROM customer ORDER BY avg_price DESC LIMIT 10 Query: Find the 10 customers that buy the most expensive items on average SELECT c.id, AVG(i.price) avg_price FROM customer c, order o, item i WHERE c.id = o.cid and o.id = i.oid GROUP BY c.id ORDER BY avg_price DESC LIMIT 10 Flat Nested
  • 29. 29© Cloudera, Inc. All rights reserved. Scan Scan Xch Xch Join Scan Xch Join Agg Xch Agg Scan Unnest Agg Top-n Xch Top-n Top-n Xch Top-n Analytics on Nested Data: Cheap & Easy! $$$
  • 30. 30© Cloudera, Inc. All rights reserved. A Note to BI Tool Vendors Please support nested types, it’s not that hard! • you already take advantage of declared PK/FK relationships • a nested collection isn’t really that different • except you don’t need a join predicate
  • 31. 31© Cloudera, Inc. All rights reserved. Thank you