SlideShare a Scribd company logo
Correctness and Performance
of Apache Spark SQL
Spark + AI Summit, London
October 4, 2018
1
2
NICOLAS POGGI
Databricks, Performance Engineer
• Spark benchmarking
Barcelona Supercomputing - Microsoft Research Centre
• Lead researcher ALOJA project
• New architectures for Big Data
BarcelonaTech (UPC), PhD in Computer Architecture
• Autonomic resource manager for the cloud
• Web customer modeling
About us
BOGDAN GHIT
Databricks, Software Engineer
• SQL performance optimizations
IBM T.J. Watson, Research Intern
• Bid advisor for cloud spot markets
Delft University of Technology, PhD in Computer Science
• Resource management in datacenters
• Performance of Spark, Hadoop
Databricks ecosystem
3
ToolsDevelopers
DBR Cluster Manager
Infrastructure Customers
DBR 5.0
DBR 4.3-LTS
DBR 4.3
Feb’18
Beta
Full Support
Marked for deprecation
Deprecated
Databricks runtime (DBR) releases
Our goal is to make releases automatic and frequent
Jun’18 Oct’18 Feb’19 Jun’19 Oct’19 Feb’20
Spark 2.4
Spark 2.3
Spark 2.3
Apache Spark contributions
5
Hundreds of commits monthly to the Apache Spark project
Numberofcommits
At this pace of development, mistakes are bound to happen
Where do these contributions go?
6
Scope of the testing
Developers put a significant engineering effort in testing
Query
Input data
Configuration
Over 200 built-in functions
Yet another brick in the wall
Unit testing is not enough to guarantee correctness and performance
Unit testing
Integration
E2E
Micro
Benchmarks
Plan
stability
Fuzz
testing
Macro
benchmarks
Stress
testing
Customer
workloads
Failure
testing
8
Continuous Integration pipeline
New artifacts Metrics
- Correctness
- Performance
Test
Alerts
- Merge
- Build
Dev
- Rules
- Policies
Analyze
9
Classification and alerting
- Impact
- Scope
- Correlation
- Confirm?
Failure
Regression
- Minimize
- Drill-down
- Profile
- Compare
- Validate
Events Re-test Alert
Classify Root-cause
Correctness
Performance
10
Failure
Regression
Events
Re-test
Alert
Classify Root-cause
Correctness
Performance
Correctness
Random query generation
11
Query profile
Model
translator
Spark
Query
Postgres
Query
vs
vs
...
...
DDL and datagen
12
...
...
BigIntBoolean
Timestamp
Decimal
FloatInteger
SmallInt
String
Choose a data type
Random number of rows
Random number of columns
Random number of tables
Random partition columns
Recursive query model
13
SQL Query
WITH
FROMUNION
SELECT
Functions
Constant
GROUP BY
ORDER BY
Table
Column
Alias
Query
Clause
Expression
JOIN
WHERE
Probabilistic query profile
Independent weights
• Optional query clauses
Inter-dependent weights
• Join types
• Select functions
ORDER BY
UNION
GROUP BY WHERE
10%
10%
50%
10%
Coalesce flattening (1/4)
SELECT COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3) AS int_col,
IF(NULL, VARIANCE(COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3)),
COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3)) AS int_col_1,
STDDEV(t2.double_col_2) AS float_col,
COALESCE(MIN((t1.smallint_col_3) - (COALESCE(t2.smallint_col_3, t1.smallint_col_3,
t2.smallint_col_3))), COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3),
COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3)) AS int_col_2
FROM table_4 t1
INNER JOIN table_4 t2 ON (t2.timestamp_col_7) = (t1.timestamp_col_7)
WHERE (t1.smallint_col_3) IN (CAST('0.04' AS DECIMAL(10,10)), t1.smallint_col_3)
GROUP BY COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3)
Small dataset with 2 tables of 5x5 size
Within 10 randomly generated queries
Error: Operation is in ERROR_STATE
Coalesce flattening (2/3)
Aggregate
Project
Join
FILTERSCAN foo
SCAN bar
foo.id IN
(CAST(‘0.04’ AS DECIMAL(10, 10)), foo.id)
foo.ts = bar.ts
COALESCE(COALESCE(foo.id, foo.val), 88)
GROUP BY COALESCE(foo.id, foo.val)
Coalesce flattening (3/4)
Aggregate
Project
Join
FILTERSCAN t1
SCAN t2
foo.id IN
(CAST(‘0.04’ AS DECIMAL(10, 10)), foo.id)
foo.ts = bar.ts
COALESCE(COALESCE(foo.id, foo.val), 88)
COALESCE(foo.id, foo.val)
Coalesce flattening (4/4)
Aggregate
Project
SCAN foo
Minimized query:
SELECT
COALESCE(COALESCE(foo.id, foo.val), 88)
FROM foo
GROUP BY
COALESCE(foo.id, foo.val)
Analyzing the error
● The optimizer flattens the nested coalesce calls
● The SELECT clause doesn’t contain the GROUP BY expression
● Possibly a problem with any GROUP BY expression that can be optimized
Lead function (1/3)
SELECT (t1.decimal0803_col_3) / (t1.decimal0803_col_3) AS decimal_col,
CAST(696 AS STRING) AS char_col, t1.decimal0803_col_3,
(COALESCE(CAST('0.02' AS DECIMAL(10,10)),
CAST('0.47' AS DECIMAL(10,10)),
CAST('-0.53' AS DECIMAL(10,10)))) +
(LEAD(-65, 4) OVER (ORDER BY (t1.decimal0803_col_3) / (t1.decimal0803_col_3),
CAST(696 AS STRING))) AS decimal_col_1,
CAST(-349 AS STRING) AS char_col_1
FROM table_16 t1
WHERE (943) > (889)
Error: Column 4 in row 10 does not match:
[1.0, 696, -871.81, <<-64.98>>, -349] SPARK row
[1.0, 696, -871.81, <<None>>, -349] POSTGRESQL row
Lead function (2/3)
Project
FILTER
SCAN foo
WHERE expr
COALESCE(expr) + LEAD(-65, 4) OVER ORDER BY expr
Lead function (3/3)
Project
FILTER WHERE expr
COALESCE(expr) + LEAD(-65, 4) OVER ORDER BY expr
Analyzing the error
● Using constant input values breaks the behaviour of the LEAD function
● SC-16633: https://github.com/apache/spark/pull/14284
SCAN foo
22
Performance
22
Failure
Regression
Events
Re-test
Alert
Classify Root-cause
Correctness
Performance
Benchmarking tools
•We use spark-sql-perf public library for
TPC workloads
• Provides datagen and import scripts
• local, cluster, S3
• Dashboards for analyzing results
•The Spark micro benchmarks
•And the async-profiler
• to produce flamegraphs
23
https://github.com/databricks/spark-sql-perf
Source:
http://www.brendangregg.com/flamegraphs.html
CPU Flame Graph
15%
------------- journey
Per query drill-down: 67
First, scope and validate
• in 2.4-master (dev) compared
• to 2.3 in DBR 4.3 (prod)
Query 67: 18% regression From 320s to 390s
Q67 executor profile for Spark 2.4-master
Side-by-side 2.3 vs 2.4: find the differences
Spark 2.3 Spark 2.4
Framegraph diff zoom Red slower White new
unsafe/Platform.copyMemory()
unsafe/BytesToBytesMap.safeLookup
New: hash/Murmur3_x86_32.hashUTF8String()
Murmur3_x86_32.hashUnsafeBytesBlock()
Look for hints:
- Mem mgmt
- Hashing
- unsafe
Root-causing
Results:
• Spark 2.3: hashUnsafeBytes() -> 40µs
• Spark 2.4 hashUnsafeBytesBlock() -> 140µs
• also slower UTF8String.getBytes()
Microbenchmark for UTF8String
GIT BISECT
1.)
2.)
3.)
It is a journey to get a release out
DBR and Spark testing and performance are a continuous effort
• Over a month effort to bring performance to improving
TPC-DS 2.4-master vs. 2.3 at SF 1000
15%
5%
< 0%
Conclusion
Spark in production is not just the framework
Unit and integration testing are not enough
We need Spark specific tools to automate the process
to ensure both correctness and performance
Thanks!
Correctness and Performance of Apache Spark SQL
October 2018
32
Test AnalyzeDev

More Related Content

What's hot (20)

PPTX
Spark real world use cases and optimizations
Gal Marder
 
PDF
Continuous Delivery of Deep Transformer-Based NLP Models Using MLflow and AWS...
Databricks
 
PPTX
Dive into spark2
Gal Marder
 
PPTX
Analytics Metrics delivery and ML Feature visualization: Evolution of Data Pl...
Chester Chen
 
PDF
Spark DataFrames: Simple and Fast Analytics on Structured Data at Spark Summi...
Databricks
 
PDF
MLeap: Productionize Data Science Workflows Using Spark
Jen Aman
 
PDF
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...
Flink Forward
 
PPTX
Stream processing from single node to a cluster
Gal Marder
 
ODP
Introduction to ScalaZ
Knoldus Inc.
 
PPT
Spark stream - Kafka
Dori Waldman
 
PPTX
Flink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
Flink Forward
 
PPT
Introduction to Spark Streaming
Knoldus Inc.
 
PPTX
JVM languages "flame wars"
Gal Marder
 
PDF
Developing Secure Scala Applications With Fortify For Scala
Lightbend
 
PDF
Flink Forward SF 2017: Dean Wampler - Streaming Deep Learning Scenarios with...
Flink Forward
 
PDF
Apache Spark 2.0: A Deep Dive Into Structured Streaming - by Tathagata Das
Databricks
 
PDF
Robust Operations of Kafka Streams
confluent
 
PDF
ROCm and Distributed Deep Learning on Spark and TensorFlow
Databricks
 
PPTX
Achieve big data analytic platform with lambda architecture on cloud
Scott Miao
 
PDF
Revitalizing Enterprise Integration with Reactive Streams
Lightbend
 
Spark real world use cases and optimizations
Gal Marder
 
Continuous Delivery of Deep Transformer-Based NLP Models Using MLflow and AWS...
Databricks
 
Dive into spark2
Gal Marder
 
Analytics Metrics delivery and ML Feature visualization: Evolution of Data Pl...
Chester Chen
 
Spark DataFrames: Simple and Fast Analytics on Structured Data at Spark Summi...
Databricks
 
MLeap: Productionize Data Science Workflows Using Spark
Jen Aman
 
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...
Flink Forward
 
Stream processing from single node to a cluster
Gal Marder
 
Introduction to ScalaZ
Knoldus Inc.
 
Spark stream - Kafka
Dori Waldman
 
Flink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
Flink Forward
 
Introduction to Spark Streaming
Knoldus Inc.
 
JVM languages "flame wars"
Gal Marder
 
Developing Secure Scala Applications With Fortify For Scala
Lightbend
 
Flink Forward SF 2017: Dean Wampler - Streaming Deep Learning Scenarios with...
Flink Forward
 
Apache Spark 2.0: A Deep Dive Into Structured Streaming - by Tathagata Das
Databricks
 
Robust Operations of Kafka Streams
confluent
 
ROCm and Distributed Deep Learning on Spark and TensorFlow
Databricks
 
Achieve big data analytic platform with lambda architecture on cloud
Scott Miao
 
Revitalizing Enterprise Integration with Reactive Streams
Lightbend
 

Similar to Correctness and Performance of Apache Spark SQL with Bogdan Ghit and Nicolas Poggi (20)

PDF
Fast and Reliable Apache Spark SQL Releases
DataWorks Summit
 
PDF
Fast and Reliable Apache Spark SQL Engine
Databricks
 
PPTX
Big Data-Driven Applications with Cassandra and Spark
Artem Chebotko
 
PDF
SparkSQL: A Compiler from Queries to RDDs
Databricks
 
PDF
How the Postgres Query Optimizer Works
EDB
 
PPTX
Typesafe spark- Zalando meetup
Stavros Kontopoulos
 
PDF
The Nitty Gritty of Advanced Analytics Using Apache Spark in Python
Miklos Christine
 
PDF
Explaining the Postgres Query Optimizer (Bruce Momjian)
Ontico
 
PDF
Ehsan parallel accelerator-dec2015
Christian Peel
 
PDF
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
ScyllaDB
 
PDF
Cost-Based Optimizer in Apache Spark 2.2
Databricks
 
PDF
Sparkly Notebook: Interactive Analysis and Visualization with Spark
felixcss
 
PDF
Reducing Redundancies in Multi-Revision Code Analysis
Sebastiano Panichella
 
PPTX
Optimizing Tcl Bytecode
Donal Fellows
 
PDF
A Deep Dive into Query Execution Engine of Spark SQL
Databricks
 
PDF
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Databricks
 
PPTX
Code instrumentation
Bryan Reinero
 
PPTX
MySQL Optimizer Overview
Olav Sandstå
 
PDF
Fast federated SQL with Apache Calcite
Chris Baynes
 
PPTX
Grow and Shrink - Dynamically Extending the Ruby VM Stack
KeitaSugiyama1
 
Fast and Reliable Apache Spark SQL Releases
DataWorks Summit
 
Fast and Reliable Apache Spark SQL Engine
Databricks
 
Big Data-Driven Applications with Cassandra and Spark
Artem Chebotko
 
SparkSQL: A Compiler from Queries to RDDs
Databricks
 
How the Postgres Query Optimizer Works
EDB
 
Typesafe spark- Zalando meetup
Stavros Kontopoulos
 
The Nitty Gritty of Advanced Analytics Using Apache Spark in Python
Miklos Christine
 
Explaining the Postgres Query Optimizer (Bruce Momjian)
Ontico
 
Ehsan parallel accelerator-dec2015
Christian Peel
 
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
ScyllaDB
 
Cost-Based Optimizer in Apache Spark 2.2
Databricks
 
Sparkly Notebook: Interactive Analysis and Visualization with Spark
felixcss
 
Reducing Redundancies in Multi-Revision Code Analysis
Sebastiano Panichella
 
Optimizing Tcl Bytecode
Donal Fellows
 
A Deep Dive into Query Execution Engine of Spark SQL
Databricks
 
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Databricks
 
Code instrumentation
Bryan Reinero
 
MySQL Optimizer Overview
Olav Sandstå
 
Fast federated SQL with Apache Calcite
Chris Baynes
 
Grow and Shrink - Dynamically Extending the Ruby VM Stack
KeitaSugiyama1
 
Ad

More from Databricks (20)

PPTX
DW Migration Webinar-March 2022.pptx
Databricks
 
PPTX
Data Lakehouse Symposium | Day 1 | Part 1
Databricks
 
PPT
Data Lakehouse Symposium | Day 1 | Part 2
Databricks
 
PPTX
Data Lakehouse Symposium | Day 2
Databricks
 
PPTX
Data Lakehouse Symposium | Day 4
Databricks
 
PDF
5 Critical Steps to Clean Your Data Swamp When Migrating Off of Hadoop
Databricks
 
PDF
Democratizing Data Quality Through a Centralized Platform
Databricks
 
PDF
Learn to Use Databricks for Data Science
Databricks
 
PDF
Why APM Is Not the Same As ML Monitoring
Databricks
 
PDF
The Function, the Context, and the Data—Enabling ML Ops at Stitch Fix
Databricks
 
PDF
Stage Level Scheduling Improving Big Data and AI Integration
Databricks
 
PDF
Simplify Data Conversion from Spark to TensorFlow and PyTorch
Databricks
 
PDF
Scaling your Data Pipelines with Apache Spark on Kubernetes
Databricks
 
PDF
Scaling and Unifying SciKit Learn and Apache Spark Pipelines
Databricks
 
PDF
Sawtooth Windows for Feature Aggregations
Databricks
 
PDF
Redis + Apache Spark = Swiss Army Knife Meets Kitchen Sink
Databricks
 
PDF
Re-imagine Data Monitoring with whylogs and Spark
Databricks
 
PDF
Raven: End-to-end Optimization of ML Prediction Queries
Databricks
 
PDF
Processing Large Datasets for ADAS Applications using Apache Spark
Databricks
 
PDF
Massive Data Processing in Adobe Using Delta Lake
Databricks
 
DW Migration Webinar-March 2022.pptx
Databricks
 
Data Lakehouse Symposium | Day 1 | Part 1
Databricks
 
Data Lakehouse Symposium | Day 1 | Part 2
Databricks
 
Data Lakehouse Symposium | Day 2
Databricks
 
Data Lakehouse Symposium | Day 4
Databricks
 
5 Critical Steps to Clean Your Data Swamp When Migrating Off of Hadoop
Databricks
 
Democratizing Data Quality Through a Centralized Platform
Databricks
 
Learn to Use Databricks for Data Science
Databricks
 
Why APM Is Not the Same As ML Monitoring
Databricks
 
The Function, the Context, and the Data—Enabling ML Ops at Stitch Fix
Databricks
 
Stage Level Scheduling Improving Big Data and AI Integration
Databricks
 
Simplify Data Conversion from Spark to TensorFlow and PyTorch
Databricks
 
Scaling your Data Pipelines with Apache Spark on Kubernetes
Databricks
 
Scaling and Unifying SciKit Learn and Apache Spark Pipelines
Databricks
 
Sawtooth Windows for Feature Aggregations
Databricks
 
Redis + Apache Spark = Swiss Army Knife Meets Kitchen Sink
Databricks
 
Re-imagine Data Monitoring with whylogs and Spark
Databricks
 
Raven: End-to-end Optimization of ML Prediction Queries
Databricks
 
Processing Large Datasets for ADAS Applications using Apache Spark
Databricks
 
Massive Data Processing in Adobe Using Delta Lake
Databricks
 
Ad

Recently uploaded (20)

PDF
apidays Singapore 2025 - From API Intelligence to API Governance by Harsha Ch...
apidays
 
PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
PDF
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
PPTX
Listify-Intelligent-Voice-to-Catalog-Agent.pptx
nareshkottees
 
PPTX
What Is Data Integration and Transformation?
subhashenia
 
PPT
Growth of Public Expendituuure_55423.ppt
NavyaDeora
 
PDF
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
PDF
Technical-Report-GPS_GIS_RS-for-MSF-finalv2.pdf
KPycho
 
PDF
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
PPTX
thid ppt defines the ich guridlens and gives the information about the ICH gu...
shaistabegum14
 
PPTX
01_Nico Vincent_Sailpeak.pptx_AI_Barometer_2025
FinTech Belgium
 
PPTX
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
PPTX
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
PDF
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 
PDF
A GraphRAG approach for Energy Efficiency Q&A
Marco Brambilla
 
PPTX
Powerful Uses of Data Analytics You Should Know
subhashenia
 
PDF
1750162332_Snapshot-of-Indias-oil-Gas-data-May-2025.pdf
sandeep718278
 
PPTX
Feb 2021 Ransomware Recovery presentation.pptx
enginsayin1
 
PDF
Optimizing Large Language Models with vLLM and Related Tools.pdf
Tamanna36
 
PPTX
Aict presentation on dpplppp sjdhfh.pptx
vabaso5932
 
apidays Singapore 2025 - From API Intelligence to API Governance by Harsha Ch...
apidays
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
Listify-Intelligent-Voice-to-Catalog-Agent.pptx
nareshkottees
 
What Is Data Integration and Transformation?
subhashenia
 
Growth of Public Expendituuure_55423.ppt
NavyaDeora
 
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
Technical-Report-GPS_GIS_RS-for-MSF-finalv2.pdf
KPycho
 
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
thid ppt defines the ich guridlens and gives the information about the ICH gu...
shaistabegum14
 
01_Nico Vincent_Sailpeak.pptx_AI_Barometer_2025
FinTech Belgium
 
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 
A GraphRAG approach for Energy Efficiency Q&A
Marco Brambilla
 
Powerful Uses of Data Analytics You Should Know
subhashenia
 
1750162332_Snapshot-of-Indias-oil-Gas-data-May-2025.pdf
sandeep718278
 
Feb 2021 Ransomware Recovery presentation.pptx
enginsayin1
 
Optimizing Large Language Models with vLLM and Related Tools.pdf
Tamanna36
 
Aict presentation on dpplppp sjdhfh.pptx
vabaso5932
 

Correctness and Performance of Apache Spark SQL with Bogdan Ghit and Nicolas Poggi

  • 1. Correctness and Performance of Apache Spark SQL Spark + AI Summit, London October 4, 2018 1
  • 2. 2 NICOLAS POGGI Databricks, Performance Engineer • Spark benchmarking Barcelona Supercomputing - Microsoft Research Centre • Lead researcher ALOJA project • New architectures for Big Data BarcelonaTech (UPC), PhD in Computer Architecture • Autonomic resource manager for the cloud • Web customer modeling About us BOGDAN GHIT Databricks, Software Engineer • SQL performance optimizations IBM T.J. Watson, Research Intern • Bid advisor for cloud spot markets Delft University of Technology, PhD in Computer Science • Resource management in datacenters • Performance of Spark, Hadoop
  • 3. Databricks ecosystem 3 ToolsDevelopers DBR Cluster Manager Infrastructure Customers
  • 4. DBR 5.0 DBR 4.3-LTS DBR 4.3 Feb’18 Beta Full Support Marked for deprecation Deprecated Databricks runtime (DBR) releases Our goal is to make releases automatic and frequent Jun’18 Oct’18 Feb’19 Jun’19 Oct’19 Feb’20 Spark 2.4 Spark 2.3 Spark 2.3
  • 5. Apache Spark contributions 5 Hundreds of commits monthly to the Apache Spark project Numberofcommits At this pace of development, mistakes are bound to happen
  • 6. Where do these contributions go? 6 Scope of the testing Developers put a significant engineering effort in testing Query Input data Configuration Over 200 built-in functions
  • 7. Yet another brick in the wall Unit testing is not enough to guarantee correctness and performance Unit testing Integration E2E Micro Benchmarks Plan stability Fuzz testing Macro benchmarks Stress testing Customer workloads Failure testing
  • 8. 8 Continuous Integration pipeline New artifacts Metrics - Correctness - Performance Test Alerts - Merge - Build Dev - Rules - Policies Analyze
  • 9. 9 Classification and alerting - Impact - Scope - Correlation - Confirm? Failure Regression - Minimize - Drill-down - Profile - Compare - Validate Events Re-test Alert Classify Root-cause Correctness Performance
  • 11. Random query generation 11 Query profile Model translator Spark Query Postgres Query vs vs
  • 12. ... ... DDL and datagen 12 ... ... BigIntBoolean Timestamp Decimal FloatInteger SmallInt String Choose a data type Random number of rows Random number of columns Random number of tables Random partition columns
  • 13. Recursive query model 13 SQL Query WITH FROMUNION SELECT Functions Constant GROUP BY ORDER BY Table Column Alias Query Clause Expression JOIN WHERE
  • 14. Probabilistic query profile Independent weights • Optional query clauses Inter-dependent weights • Join types • Select functions ORDER BY UNION GROUP BY WHERE 10% 10% 50% 10%
  • 15. Coalesce flattening (1/4) SELECT COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3) AS int_col, IF(NULL, VARIANCE(COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3)), COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3)) AS int_col_1, STDDEV(t2.double_col_2) AS float_col, COALESCE(MIN((t1.smallint_col_3) - (COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3))), COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3), COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3)) AS int_col_2 FROM table_4 t1 INNER JOIN table_4 t2 ON (t2.timestamp_col_7) = (t1.timestamp_col_7) WHERE (t1.smallint_col_3) IN (CAST('0.04' AS DECIMAL(10,10)), t1.smallint_col_3) GROUP BY COALESCE(t2.smallint_col_3, t1.smallint_col_3, t2.smallint_col_3) Small dataset with 2 tables of 5x5 size Within 10 randomly generated queries Error: Operation is in ERROR_STATE
  • 16. Coalesce flattening (2/3) Aggregate Project Join FILTERSCAN foo SCAN bar foo.id IN (CAST(‘0.04’ AS DECIMAL(10, 10)), foo.id) foo.ts = bar.ts COALESCE(COALESCE(foo.id, foo.val), 88) GROUP BY COALESCE(foo.id, foo.val)
  • 17. Coalesce flattening (3/4) Aggregate Project Join FILTERSCAN t1 SCAN t2 foo.id IN (CAST(‘0.04’ AS DECIMAL(10, 10)), foo.id) foo.ts = bar.ts COALESCE(COALESCE(foo.id, foo.val), 88) COALESCE(foo.id, foo.val)
  • 18. Coalesce flattening (4/4) Aggregate Project SCAN foo Minimized query: SELECT COALESCE(COALESCE(foo.id, foo.val), 88) FROM foo GROUP BY COALESCE(foo.id, foo.val) Analyzing the error ● The optimizer flattens the nested coalesce calls ● The SELECT clause doesn’t contain the GROUP BY expression ● Possibly a problem with any GROUP BY expression that can be optimized
  • 19. Lead function (1/3) SELECT (t1.decimal0803_col_3) / (t1.decimal0803_col_3) AS decimal_col, CAST(696 AS STRING) AS char_col, t1.decimal0803_col_3, (COALESCE(CAST('0.02' AS DECIMAL(10,10)), CAST('0.47' AS DECIMAL(10,10)), CAST('-0.53' AS DECIMAL(10,10)))) + (LEAD(-65, 4) OVER (ORDER BY (t1.decimal0803_col_3) / (t1.decimal0803_col_3), CAST(696 AS STRING))) AS decimal_col_1, CAST(-349 AS STRING) AS char_col_1 FROM table_16 t1 WHERE (943) > (889) Error: Column 4 in row 10 does not match: [1.0, 696, -871.81, <<-64.98>>, -349] SPARK row [1.0, 696, -871.81, <<None>>, -349] POSTGRESQL row
  • 20. Lead function (2/3) Project FILTER SCAN foo WHERE expr COALESCE(expr) + LEAD(-65, 4) OVER ORDER BY expr
  • 21. Lead function (3/3) Project FILTER WHERE expr COALESCE(expr) + LEAD(-65, 4) OVER ORDER BY expr Analyzing the error ● Using constant input values breaks the behaviour of the LEAD function ● SC-16633: https://github.com/apache/spark/pull/14284 SCAN foo
  • 23. Benchmarking tools •We use spark-sql-perf public library for TPC workloads • Provides datagen and import scripts • local, cluster, S3 • Dashboards for analyzing results •The Spark micro benchmarks •And the async-profiler • to produce flamegraphs 23 https://github.com/databricks/spark-sql-perf Source: http://www.brendangregg.com/flamegraphs.html CPU Flame Graph
  • 25. Per query drill-down: 67 First, scope and validate • in 2.4-master (dev) compared • to 2.3 in DBR 4.3 (prod) Query 67: 18% regression From 320s to 390s
  • 26. Q67 executor profile for Spark 2.4-master
  • 27. Side-by-side 2.3 vs 2.4: find the differences Spark 2.3 Spark 2.4
  • 28. Framegraph diff zoom Red slower White new unsafe/Platform.copyMemory() unsafe/BytesToBytesMap.safeLookup New: hash/Murmur3_x86_32.hashUTF8String() Murmur3_x86_32.hashUnsafeBytesBlock() Look for hints: - Mem mgmt - Hashing - unsafe
  • 29. Root-causing Results: • Spark 2.3: hashUnsafeBytes() -> 40µs • Spark 2.4 hashUnsafeBytesBlock() -> 140µs • also slower UTF8String.getBytes() Microbenchmark for UTF8String GIT BISECT 1.) 2.) 3.)
  • 30. It is a journey to get a release out DBR and Spark testing and performance are a continuous effort • Over a month effort to bring performance to improving TPC-DS 2.4-master vs. 2.3 at SF 1000 15% 5% < 0%
  • 31. Conclusion Spark in production is not just the framework Unit and integration testing are not enough We need Spark specific tools to automate the process to ensure both correctness and performance
  • 32. Thanks! Correctness and Performance of Apache Spark SQL October 2018 32 Test AnalyzeDev