SlideShare a Scribd company logo
Building a SIMD supported
vectorized native engine for
Spark SQL
Chendi Xue(chendi.xue@intel.com), Software Engineer
Yuan Zhou(yuan.zhou@intel.com), Software Engineer
Intel Corp
Agenda
▪ Native SQL Engine Introduction
▪ Native SQL Engine Design
▪ Columnar Data Source
▪ Columnar Shuffle
▪ Columnar Compute
▪ Memory Management
▪ Summary
Motivations for Native SQL Engine
• Issue of current Spark SQL Engine:
▪ Internal row based, difficult to use SIMD optimizations
▪ High GC Overhead under low memory
▪ JIT code quality relies on JVM, hard to tune
▪ High overhead of integration with other native library
Proposed Solution
Issue of current Spark SQL Engine:
▪ Internal row based, not possible to use SIMD
→ Columnar-based Arrow Format
▪ High GC Overhead under low memory
→ native codes for core compute instead of java
▪ JIT code quality relies on JVM, hard to tune
→ cpp / llvm / assembly code generation
▪ High overhead of integration with other native
library
→ Lightweighted JNI based call framework
Source: https://www.slideshare.net/dremio/apache-arrow-an-overview
Native SQL Engine Layers
Physical Plan Execution
Columnar PluginJVM SQL Engine
Row Column
Conversion
Operator
strategy
(Cost /
Support )
Spark Application
SQL Python APP Java/Scala APP R APP
Native Arrow Data Source
ColumnarCompute Memory
Management
UDF Cache Scheduler
DAOS / HDFS /
S3 / KUDU /
LOCALFS / …
Parquet /
ORC / CSV /
JASON / …
Query Plan Optimization
ColumnarRules ColumnarCollapseRules ColumnarAQERules
WSCG join/sort/aggr/proj/…
PUSHDOWN
Native Compute
JNI WRAPPER
Native Shuffle
LLVM
Gandiva
CPP Code
Generator
pre-
compiled
kernels
Spark
Compatible
Partition
Streamer /
Compressed
Serialization
Optimal
Batch
Memory
Manage /
Register
• A standard columnar data format as basic data format
• Data keeps on off-heap, data operations offload to highly optimized native library
Data Format
Row RDD Column RDD Optimal Column RDD
iter iter
next()
iter
• Auto split and coalesce
• Tunable batch size
next()
next()
next()
Columnar Spark Plan Rules
Parser Analyzer Optimizer Planner Query Execution
SQL
Dataset
DataFrame
Unresolved
Logical Plan
Logical
Plan
Optimized
Logical Plan
Physical
Plan
Selected
Physical Plans
RDD
Cost
Model
Metadata
Catalog
Cache
Manager
Spark
Native Engine
SQL
Dataset
DataFrame
Unresolved
Logical Plan
Logical
Plan
Optimized
Logical Plan
Physical
Plan
Selected
Physical Plans
Cost
Model
Metadata
Catalog
Cache
Manager
ColumnarAQE
Native SQL Engine
ColumnarPlan
ColumnarWSCG
LLVM/SIMD
Kernel
Columnar Whole Stage Codegen
JVM Native
Stage1 Evaluate
Parquet Read
Filter
Columnar
Shuffle
Columnar Exchange
operator
Columnar
Shuffle
Stage2 Evaluate
Parquet Read
Hash Join
Aggregate
Columnar Exchange
operator
Columnar
Aggregate
Aggregate
JVM Native
Stage1 Evaluate Parquet Read
Gandiva Filter
Columnar
Shuffle
Columnar Exchange
operator
HashJoin
Aggregate
Columnar
Shuffle
Stage2 Evaluate Parquet Read
Columnar Exchange
operator
Columnar
Aggregate
Aggregate
Native SQL Engine Design
▪ Columnar Data Source
▪ Columnar Shuffle
▪ Columnar Compute
▪ Memory Management
Spark Internal Format
UnsafeRow
Columnar Data Source
Columnized Format
(parquet, orc)
Column to Row?
Spark used a virtual
way to treat column
data as row, while
memory is not
adjacent
Row-based Data Source Arrow based Data Source
Arrow Format
MetaData
Parquet orc csv
kudu cassandra HBase
RowBased Format
(csv, …)
Unify and fastJSON
V.S.
Columnar Data Source
11
Spark Arrow DataSource
(pyspark, thriftserver, sparksql,…)
Arrow Java Datasets API
(Zero data copy, memory
reference only)
Arrow C++ Datasets API
(HDFS, localFS, S3A)
(Parquet, ORC, CSV, ..)
▪ Features
▪ Fast / Parallel / Auth supported Native Libraries for HDFS / S3A / Local FS
▪ PushDown supported Pre-executed statistics/metadata filters
▪ Partitioned File and DPP enabled
Columnar Data Source
0 <= ID < 5000
5000 <= ID < 10000
unread ID = 7500
ID = 7500
Truncated
Files
Columnar Shuffle
• Hash-based partitioning(split) with
LLVM optimized execution
• Ser/de-ser based on arrow record
batch
• Efficient data compression for
different data format
• Coalesce batches during shuffle read
• Supports Adaptive Query
Execution(AQE)
ColumnarExchange
Mapper
ColumnarExchange
Reducer
compressed
file
compressed
file
compressed
file
compressed
file
CoalesceBatches
Hash based partition
Supported SQL Operators Overview
Operators
WindowExec
UnionExec
ExpandExec
SortExec
ScalarSubquery
ProjectExec
ShuffledHashJoin
BroadcastJoinExec
FilterExec
ShuffleExchangeExec
BroadcastExchangeExec
datasources.v2.BatchScanExec
datasources.v1.FileScanExec
HashAggregateExec
…..
Expression
NormalizeNaNAndZero
Subtract
Substring
ShiftRight
Round
PromotePrecision
Multiply
Literal
LessThanOrEqual
LessThan
KnownFloatingPointNormalized
IsNull
And
Add
….
Expression
IsNotNull
GreaterThanOrEqual
GreaterThan
EqualTo
ExtractYear
Divide
Concat
Coalesce
CheckOverflow
Cast
CaseWhen
BitwiseAnd
AttributeReference
Alias
….
Automatically fallback to row-based execution if there are unsupported operators/expressions
ColumnarCondProjection
Columnar Projector & Filter
▪ LLVM IR based execution w/ AVX optimized
code
▪ Based on Arrow Gandiva, extended with
more functions
▪ Combined filter & projection into
CondProjector
▪ ColumnarBatch based execution
Scan B
Filter
ColumnarExchange
Projection
Example:
If (Field_A + Field_B + Field_C) as Field_new > Field_D
output [Field_new, Field_A, Field_B, Field_C, Field_D]
LLVM
IR
One call
Native Hashmap
▪ Faster Hashmap building and
lookup w/ AVX optimizations
▪ Compatible with Spark’s
murmurhash if configured
▪ Performance benefits for
HashAggregation and HashJoins
Scan A
Scan B
Filter
BoradcastHashJoin
HashAggregate
BoradcastExchange
ShuffleExchange
HashAggregate
Stage
ColumnarExchange
Stage
Columnar
BroadcastExchange
Stage
ColumnarShuffleReader
ColumnarBroadcastHashJoin
Broadcast data consists of
1. HashMap (key -> indices)
2. Arrow RecordBatch
using ColumnarBroadcastExchange,
data size is reduced by 80%
Stage
ColumnarBroadcastJoin
ColumnarExchange
… …
ColumnarShuffleReader
hash payload
0x8198 <0, 0>, key1
0x7723 <0, 1>,key2
… …
0x6388
<10240, 1076>
Key1076
0x9944
<10240, 1077>
Key1077
0x8761
<10240, 1078>
key1078
+
Native Sort
▪ Faster sort implementation w/
AVX optimizations
▪ Most powerful algorithms used for
different data structures
▪ Performance benefits for sort and
sort merge joins
Scan A Scan B
CondProjection
SortMergeJoin
Exchange
CondProjection
Exchange
Sort Sort
Exchange
Sort
Stage
ColumnarSortMergeJoin
ColumnarExchange
… …
Stage
ColumnarSort
Stage
Columnarsort
Stage
ColumnarShuffleReader
ColumnarSort and ColumnarSortMergeJoin
3 implementation of sort
1. One column data sort(used by semi or anti)
-> inplace radix sort (AVX optimizable)
2. One column of key with multiple columns of payload
-> radix sort to indices (AVX optimizable)
-> lazy materialization
3. Multiple columns of keys with payloads
-> codegened quick sort to indices(AVX optimizable)
-> lazy materialization
AVX optimized project {
chain key_0 in left table #1
apply project
compare key_0 and key_1 in right table #2
apply condition
materialize one line to arrow
}
Stage
ColumnarExchange
Stage
ColumnarBroadcastExchange
Stage
ColumnarBroadcastExchange
Stage
ColumnarExchange
Stage
ColumnarShuffleReader
Stage
ColumnarShuffleReader
ColumnarShuffledHashJoin
ColumnarProject
ColumnarBroadcastJoin
ColumnarFilter
ColumnarBroadcastJoin
ColumnarExchange
Columnar WholeStageCodeGen
WSCG
Code generated Cpp codes
1. Build HashRelation #0
2. Build HashRelation #1
3. Build HashRelation #2
Loop keys_arrays {
probe key_0 in HashRelation #0
apply Project
probe key_1 in HashRelation #1
apply condition
probe key_2 in HashRelation #2
materialize one line to arrow
}
AVX optimized {
probe key_0 in HashRelation #0
apply project
probe key_1 in HashRelation #1
apply condition
probe key_2 in HashRelation #2
materialize one line to arrow
}
g++ compilation
Native SQL engine call flow
Spark Context
Executor
Oap-native-sql
executeColumnar().mapPartitions
JniWrapper
Expression
Tree
RecordBatch
Gandiva
Native SQL Engine
CPPCodeGenerator
RecordBatch
Expression Input Output
Precompiled kernels
Memory Management
SparkTaskMemoryManager ArrowAllocationManager
Native MemoryDirect MemoryJVM Memory
[java] Spark.TaskMemoryManager [Java] arrow.AllocationManager [cpp] arrow::MemoryPool
register
grant
spill
Data
Source
Column
Project
Column
Sort
Column
Shuffle
Column
Reader
Native
Memory
Native
Memory
Direct
Memory
Direct
Memory
Direct
Memory
Column
To Row
JVM
Memory
Row
TakeOrdered
AndProject
JVM
Memory
Column
BHJ
Native
Memory
release release release release release release
Data
retain hashMap
Example run of TPCH-Q4
Summary
▪ AVX instructions can greatly improve performance on SQL workloads
▪ Native SQL is open sourced. For more details please visit:
https://github.com/Intel-bigdata/OAP
▪ Native SQL engine is under heavy development, works for TPC-
H/TPC-DS now
Q&A
Feedback
Your feedback is important to us.
Don’t forget to rate
and review the sessions.
Legal Information: Benchmark and Performance
Disclaimers
▪ Performance results are based on testing as of Feb. 2019 & Aug 2020 and
may not reflect all publicly available security updates. See configuration
disclosure for details. No product can be absolutely secure.
▪ Software and workloads used in performance tests may have been
optimized for performance only on Intel microprocessors. Performance
tests, such as SYSmark and MobileMark, are measured using specific
computer systems, components, software, operations and functions. Any
change to any of those factors may cause the results to vary. You should
consult other information and performance tests to assist you in fully
evaluating your contemplated purchases, including the performance of
that product when combined with other products. For more information,
see Performance Benchmark Test Disclosure.
▪ Configurations: see performance benchmark test configurations.
Notices and Disclaimers
▪ No license (express or implied, by estoppel or otherwise) to any intellectual property rights is
granted by this document.
▪ Intel disclaims all express and implied warranties, including without limitation, the implied
warranties of merchantability, fitness for a particular purpose, and non-infringement, as well as
any warranty arising from course of performance, course of dealing, or usage in trade.
▪ This document contains information on products, services and/or processes in development. All
information provided here is subject to change without notice. Contact your Intel representative
to obtain the latest forecast, schedule, specifications and roadmaps.
▪ The products and services described may contain defects or errors known as errata which may
cause deviations from published specifications. Current characterized errata are available on
request.
▪ Intel, the Intel logo, Xeon, Optane, Optane Persistent Memory are trademarks of Intel Corporation
in the U.S. and/or other countries.
▪ *Other names and brands may be claimed as the property of others
▪ © Intel Corporation.

More Related Content

What's hot (20)

PDF
Efficient Data Storage for Analytics with Apache Parquet 2.0
Cloudera, Inc.
 
PDF
Deep Dive: Memory Management in Apache Spark
Databricks
 
PDF
Apache Spark in Depth: Core Concepts, Architecture & Internals
Anton Kirillov
 
PDF
Spark SQL Join Improvement at Facebook
Databricks
 
PDF
The Parquet Format and Performance Optimization Opportunities
Databricks
 
PDF
A Deep Dive into Query Execution Engine of Spark SQL
Databricks
 
PPTX
Using Apache Hive with High Performance
Inderaj (Raj) Bains
 
PDF
Parquet performance tuning: the missing guide
Ryan Blue
 
PDF
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Databricks
 
PDF
Spark shuffle introduction
colorant
 
PDF
Producer Performance Tuning for Apache Kafka
Jiangjie Qin
 
PDF
Materialized Column: An Efficient Way to Optimize Queries on Nested Columns
Databricks
 
PDF
Spark SQL
Joud Khattab
 
PDF
Spark (Structured) Streaming vs. Kafka Streams
Guido Schmutz
 
PDF
Spark + Parquet In Depth: Spark Summit East Talk by Emily Curtin and Robbie S...
Spark Summit
 
PDF
Accelerating Apache Spark Shuffle for Data Analytics on the Cloud with Remote...
Databricks
 
PDF
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Noritaka Sekiyama
 
PPTX
Spark
Koushik Mondal
 
PDF
Vectorized Query Execution in Apache Spark at Facebook
Databricks
 
PDF
Introduction to apache spark
Aakashdata
 
Efficient Data Storage for Analytics with Apache Parquet 2.0
Cloudera, Inc.
 
Deep Dive: Memory Management in Apache Spark
Databricks
 
Apache Spark in Depth: Core Concepts, Architecture & Internals
Anton Kirillov
 
Spark SQL Join Improvement at Facebook
Databricks
 
The Parquet Format and Performance Optimization Opportunities
Databricks
 
A Deep Dive into Query Execution Engine of Spark SQL
Databricks
 
Using Apache Hive with High Performance
Inderaj (Raj) Bains
 
Parquet performance tuning: the missing guide
Ryan Blue
 
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Databricks
 
Spark shuffle introduction
colorant
 
Producer Performance Tuning for Apache Kafka
Jiangjie Qin
 
Materialized Column: An Efficient Way to Optimize Queries on Nested Columns
Databricks
 
Spark SQL
Joud Khattab
 
Spark (Structured) Streaming vs. Kafka Streams
Guido Schmutz
 
Spark + Parquet In Depth: Spark Summit East Talk by Emily Curtin and Robbie S...
Spark Summit
 
Accelerating Apache Spark Shuffle for Data Analytics on the Cloud with Remote...
Databricks
 
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Noritaka Sekiyama
 
Vectorized Query Execution in Apache Spark at Facebook
Databricks
 
Introduction to apache spark
Aakashdata
 

Similar to Building a SIMD Supported Vectorized Native Engine for Spark SQL (20)

PDF
Build Large-Scale Data Analytics and AI Pipeline Using RayDP
Databricks
 
PDF
SamzaSQL QCon'16 presentation
Yi Pan
 
PPTX
Seattle Spark Meetup Mobius CSharp API
shareddatamsft
 
PDF
Scala & Spark(1.6) in Performance Aspect for Scala Taiwan
Jimin Hsieh
 
PDF
Intro to AutoML + Hands-on Lab - Erin LeDell, Machine Learning Scientist, H2O.ai
Sri Ambati
 
PPT
Jvm Performance Tunning
Terry Cho
 
PPT
Jvm Performance Tunning
guest1f2740
 
PDF
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Databricks
 
PDF
Byte code engineering 21st May Saturday 2016
Sarath Soman
 
PPTX
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Spark Summit
 
PDF
Nodejs - Should Ruby Developers Care?
Felix Geisendörfer
 
PDF
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
Vladimir Ivanov
 
PPTX
FrameGraph: Extensible Rendering Architecture in Frostbite
Electronic Arts / DICE
 
PDF
An Introduction to Java Compiler and Runtime
Omar Bashir
 
PDF
Machine Learning with H2O, Spark, and Python at Strata 2015
Sri Ambati
 
PDF
20170126 big data processing
Vienna Data Science Group
 
PDF
Low Latency Polyglot Model Scoring using Apache Apex
Apache Apex
 
PDF
Five cool ways the JVM can run Apache Spark faster
Tim Ellison
 
PDF
Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...
Databricks
 
PDF
Grails 101
David Jacobs
 
Build Large-Scale Data Analytics and AI Pipeline Using RayDP
Databricks
 
SamzaSQL QCon'16 presentation
Yi Pan
 
Seattle Spark Meetup Mobius CSharp API
shareddatamsft
 
Scala & Spark(1.6) in Performance Aspect for Scala Taiwan
Jimin Hsieh
 
Intro to AutoML + Hands-on Lab - Erin LeDell, Machine Learning Scientist, H2O.ai
Sri Ambati
 
Jvm Performance Tunning
Terry Cho
 
Jvm Performance Tunning
guest1f2740
 
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Databricks
 
Byte code engineering 21st May Saturday 2016
Sarath Soman
 
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Spark Summit
 
Nodejs - Should Ruby Developers Care?
Felix Geisendörfer
 
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
Vladimir Ivanov
 
FrameGraph: Extensible Rendering Architecture in Frostbite
Electronic Arts / DICE
 
An Introduction to Java Compiler and Runtime
Omar Bashir
 
Machine Learning with H2O, Spark, and Python at Strata 2015
Sri Ambati
 
20170126 big data processing
Vienna Data Science Group
 
Low Latency Polyglot Model Scoring using Apache Apex
Apache Apex
 
Five cool ways the JVM can run Apache Spark faster
Tim Ellison
 
Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...
Databricks
 
Grails 101
David Jacobs
 
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 - Surviving an interconnected world with API governanc...
apidays
 
PPTX
How to Add Columns and Rows in an R Data Frame
subhashenia
 
PPTX
美国史蒂文斯理工学院毕业证书{SIT学费发票SIT录取通知书}哪里购买
Taqyea
 
PDF
Technical-Report-GPS_GIS_RS-for-MSF-finalv2.pdf
KPycho
 
PPT
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
PDF
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 
PPTX
Aict presentation on dpplppp sjdhfh.pptx
vabaso5932
 
PDF
InformaticsPractices-MS - Google Docs.pdf
seshuashwin0829
 
PPTX
What Is Data Integration and Transformation?
subhashenia
 
PPTX
01_Nico Vincent_Sailpeak.pptx_AI_Barometer_2025
FinTech Belgium
 
PPTX
05_Jelle Baats_Tekst.pptx_AI_Barometer_Release_Event
FinTech Belgium
 
PPTX
Feb 2021 Ransomware Recovery presentation.pptx
enginsayin1
 
PDF
Business implication of Artificial Intelligence.pdf
VishalChugh12
 
PPTX
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
PPTX
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
PDF
The Best NVIDIA GPUs for LLM Inference in 2025.pdf
Tamanna36
 
PDF
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
PPTX
b6057ea5-8e8c-4415-90c0-ed8e9666ffcd.pptx
Anees487379
 
PPTX
apidays Singapore 2025 - Generative AI Landscape Building a Modern Data Strat...
apidays
 
PPTX
BinarySearchTree in datastructures in detail
kichokuttu
 
apidays Singapore 2025 - Surviving an interconnected world with API governanc...
apidays
 
How to Add Columns and Rows in an R Data Frame
subhashenia
 
美国史蒂文斯理工学院毕业证书{SIT学费发票SIT录取通知书}哪里购买
Taqyea
 
Technical-Report-GPS_GIS_RS-for-MSF-finalv2.pdf
KPycho
 
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 
Aict presentation on dpplppp sjdhfh.pptx
vabaso5932
 
InformaticsPractices-MS - Google Docs.pdf
seshuashwin0829
 
What Is Data Integration and Transformation?
subhashenia
 
01_Nico Vincent_Sailpeak.pptx_AI_Barometer_2025
FinTech Belgium
 
05_Jelle Baats_Tekst.pptx_AI_Barometer_Release_Event
FinTech Belgium
 
Feb 2021 Ransomware Recovery presentation.pptx
enginsayin1
 
Business implication of Artificial Intelligence.pdf
VishalChugh12
 
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
The Best NVIDIA GPUs for LLM Inference in 2025.pdf
Tamanna36
 
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
b6057ea5-8e8c-4415-90c0-ed8e9666ffcd.pptx
Anees487379
 
apidays Singapore 2025 - Generative AI Landscape Building a Modern Data Strat...
apidays
 
BinarySearchTree in datastructures in detail
kichokuttu
 

Building a SIMD Supported Vectorized Native Engine for Spark SQL

  • 1. Building a SIMD supported vectorized native engine for Spark SQL Chendi Xue([email protected]), Software Engineer Yuan Zhou([email protected]), Software Engineer Intel Corp
  • 2. Agenda ▪ Native SQL Engine Introduction ▪ Native SQL Engine Design ▪ Columnar Data Source ▪ Columnar Shuffle ▪ Columnar Compute ▪ Memory Management ▪ Summary
  • 3. Motivations for Native SQL Engine • Issue of current Spark SQL Engine: ▪ Internal row based, difficult to use SIMD optimizations ▪ High GC Overhead under low memory ▪ JIT code quality relies on JVM, hard to tune ▪ High overhead of integration with other native library
  • 4. Proposed Solution Issue of current Spark SQL Engine: ▪ Internal row based, not possible to use SIMD → Columnar-based Arrow Format ▪ High GC Overhead under low memory → native codes for core compute instead of java ▪ JIT code quality relies on JVM, hard to tune → cpp / llvm / assembly code generation ▪ High overhead of integration with other native library → Lightweighted JNI based call framework Source: https://www.slideshare.net/dremio/apache-arrow-an-overview
  • 5. Native SQL Engine Layers Physical Plan Execution Columnar PluginJVM SQL Engine Row Column Conversion Operator strategy (Cost / Support ) Spark Application SQL Python APP Java/Scala APP R APP Native Arrow Data Source ColumnarCompute Memory Management UDF Cache Scheduler DAOS / HDFS / S3 / KUDU / LOCALFS / … Parquet / ORC / CSV / JASON / … Query Plan Optimization ColumnarRules ColumnarCollapseRules ColumnarAQERules WSCG join/sort/aggr/proj/… PUSHDOWN Native Compute JNI WRAPPER Native Shuffle LLVM Gandiva CPP Code Generator pre- compiled kernels Spark Compatible Partition Streamer / Compressed Serialization Optimal Batch Memory Manage / Register • A standard columnar data format as basic data format • Data keeps on off-heap, data operations offload to highly optimized native library
  • 6. Data Format Row RDD Column RDD Optimal Column RDD iter iter next() iter • Auto split and coalesce • Tunable batch size next() next() next()
  • 7. Columnar Spark Plan Rules Parser Analyzer Optimizer Planner Query Execution SQL Dataset DataFrame Unresolved Logical Plan Logical Plan Optimized Logical Plan Physical Plan Selected Physical Plans RDD Cost Model Metadata Catalog Cache Manager Spark Native Engine SQL Dataset DataFrame Unresolved Logical Plan Logical Plan Optimized Logical Plan Physical Plan Selected Physical Plans Cost Model Metadata Catalog Cache Manager ColumnarAQE Native SQL Engine ColumnarPlan ColumnarWSCG LLVM/SIMD Kernel
  • 8. Columnar Whole Stage Codegen JVM Native Stage1 Evaluate Parquet Read Filter Columnar Shuffle Columnar Exchange operator Columnar Shuffle Stage2 Evaluate Parquet Read Hash Join Aggregate Columnar Exchange operator Columnar Aggregate Aggregate JVM Native Stage1 Evaluate Parquet Read Gandiva Filter Columnar Shuffle Columnar Exchange operator HashJoin Aggregate Columnar Shuffle Stage2 Evaluate Parquet Read Columnar Exchange operator Columnar Aggregate Aggregate
  • 9. Native SQL Engine Design ▪ Columnar Data Source ▪ Columnar Shuffle ▪ Columnar Compute ▪ Memory Management
  • 10. Spark Internal Format UnsafeRow Columnar Data Source Columnized Format (parquet, orc) Column to Row? Spark used a virtual way to treat column data as row, while memory is not adjacent Row-based Data Source Arrow based Data Source Arrow Format MetaData Parquet orc csv kudu cassandra HBase RowBased Format (csv, …) Unify and fastJSON V.S.
  • 11. Columnar Data Source 11 Spark Arrow DataSource (pyspark, thriftserver, sparksql,…) Arrow Java Datasets API (Zero data copy, memory reference only) Arrow C++ Datasets API (HDFS, localFS, S3A) (Parquet, ORC, CSV, ..)
  • 12. ▪ Features ▪ Fast / Parallel / Auth supported Native Libraries for HDFS / S3A / Local FS ▪ PushDown supported Pre-executed statistics/metadata filters ▪ Partitioned File and DPP enabled Columnar Data Source 0 <= ID < 5000 5000 <= ID < 10000 unread ID = 7500 ID = 7500 Truncated Files
  • 13. Columnar Shuffle • Hash-based partitioning(split) with LLVM optimized execution • Ser/de-ser based on arrow record batch • Efficient data compression for different data format • Coalesce batches during shuffle read • Supports Adaptive Query Execution(AQE) ColumnarExchange Mapper ColumnarExchange Reducer compressed file compressed file compressed file compressed file CoalesceBatches Hash based partition
  • 14. Supported SQL Operators Overview Operators WindowExec UnionExec ExpandExec SortExec ScalarSubquery ProjectExec ShuffledHashJoin BroadcastJoinExec FilterExec ShuffleExchangeExec BroadcastExchangeExec datasources.v2.BatchScanExec datasources.v1.FileScanExec HashAggregateExec ….. Expression NormalizeNaNAndZero Subtract Substring ShiftRight Round PromotePrecision Multiply Literal LessThanOrEqual LessThan KnownFloatingPointNormalized IsNull And Add …. Expression IsNotNull GreaterThanOrEqual GreaterThan EqualTo ExtractYear Divide Concat Coalesce CheckOverflow Cast CaseWhen BitwiseAnd AttributeReference Alias …. Automatically fallback to row-based execution if there are unsupported operators/expressions
  • 15. ColumnarCondProjection Columnar Projector & Filter ▪ LLVM IR based execution w/ AVX optimized code ▪ Based on Arrow Gandiva, extended with more functions ▪ Combined filter & projection into CondProjector ▪ ColumnarBatch based execution Scan B Filter ColumnarExchange Projection Example: If (Field_A + Field_B + Field_C) as Field_new > Field_D output [Field_new, Field_A, Field_B, Field_C, Field_D] LLVM IR One call
  • 16. Native Hashmap ▪ Faster Hashmap building and lookup w/ AVX optimizations ▪ Compatible with Spark’s murmurhash if configured ▪ Performance benefits for HashAggregation and HashJoins Scan A Scan B Filter BoradcastHashJoin HashAggregate BoradcastExchange ShuffleExchange HashAggregate
  • 17. Stage ColumnarExchange Stage Columnar BroadcastExchange Stage ColumnarShuffleReader ColumnarBroadcastHashJoin Broadcast data consists of 1. HashMap (key -> indices) 2. Arrow RecordBatch using ColumnarBroadcastExchange, data size is reduced by 80% Stage ColumnarBroadcastJoin ColumnarExchange … … ColumnarShuffleReader hash payload 0x8198 <0, 0>, key1 0x7723 <0, 1>,key2 … … 0x6388 <10240, 1076> Key1076 0x9944 <10240, 1077> Key1077 0x8761 <10240, 1078> key1078 +
  • 18. Native Sort ▪ Faster sort implementation w/ AVX optimizations ▪ Most powerful algorithms used for different data structures ▪ Performance benefits for sort and sort merge joins Scan A Scan B CondProjection SortMergeJoin Exchange CondProjection Exchange Sort Sort Exchange Sort
  • 19. Stage ColumnarSortMergeJoin ColumnarExchange … … Stage ColumnarSort Stage Columnarsort Stage ColumnarShuffleReader ColumnarSort and ColumnarSortMergeJoin 3 implementation of sort 1. One column data sort(used by semi or anti) -> inplace radix sort (AVX optimizable) 2. One column of key with multiple columns of payload -> radix sort to indices (AVX optimizable) -> lazy materialization 3. Multiple columns of keys with payloads -> codegened quick sort to indices(AVX optimizable) -> lazy materialization AVX optimized project { chain key_0 in left table #1 apply project compare key_0 and key_1 in right table #2 apply condition materialize one line to arrow }
  • 20. Stage ColumnarExchange Stage ColumnarBroadcastExchange Stage ColumnarBroadcastExchange Stage ColumnarExchange Stage ColumnarShuffleReader Stage ColumnarShuffleReader ColumnarShuffledHashJoin ColumnarProject ColumnarBroadcastJoin ColumnarFilter ColumnarBroadcastJoin ColumnarExchange Columnar WholeStageCodeGen WSCG Code generated Cpp codes 1. Build HashRelation #0 2. Build HashRelation #1 3. Build HashRelation #2 Loop keys_arrays { probe key_0 in HashRelation #0 apply Project probe key_1 in HashRelation #1 apply condition probe key_2 in HashRelation #2 materialize one line to arrow } AVX optimized { probe key_0 in HashRelation #0 apply project probe key_1 in HashRelation #1 apply condition probe key_2 in HashRelation #2 materialize one line to arrow } g++ compilation
  • 21. Native SQL engine call flow Spark Context Executor Oap-native-sql executeColumnar().mapPartitions JniWrapper Expression Tree RecordBatch Gandiva Native SQL Engine CPPCodeGenerator RecordBatch Expression Input Output Precompiled kernels
  • 22. Memory Management SparkTaskMemoryManager ArrowAllocationManager Native MemoryDirect MemoryJVM Memory [java] Spark.TaskMemoryManager [Java] arrow.AllocationManager [cpp] arrow::MemoryPool register grant spill Data Source Column Project Column Sort Column Shuffle Column Reader Native Memory Native Memory Direct Memory Direct Memory Direct Memory Column To Row JVM Memory Row TakeOrdered AndProject JVM Memory Column BHJ Native Memory release release release release release release Data retain hashMap
  • 23. Example run of TPCH-Q4
  • 24. Summary ▪ AVX instructions can greatly improve performance on SQL workloads ▪ Native SQL is open sourced. For more details please visit: https://github.com/Intel-bigdata/OAP ▪ Native SQL engine is under heavy development, works for TPC- H/TPC-DS now
  • 25. Q&A
  • 26. Feedback Your feedback is important to us. Don’t forget to rate and review the sessions.
  • 27. Legal Information: Benchmark and Performance Disclaimers ▪ Performance results are based on testing as of Feb. 2019 & Aug 2020 and may not reflect all publicly available security updates. See configuration disclosure for details. No product can be absolutely secure. ▪ Software and workloads used in performance tests may have been optimized for performance only on Intel microprocessors. Performance tests, such as SYSmark and MobileMark, are measured using specific computer systems, components, software, operations and functions. Any change to any of those factors may cause the results to vary. You should consult other information and performance tests to assist you in fully evaluating your contemplated purchases, including the performance of that product when combined with other products. For more information, see Performance Benchmark Test Disclosure. ▪ Configurations: see performance benchmark test configurations.
  • 28. Notices and Disclaimers ▪ No license (express or implied, by estoppel or otherwise) to any intellectual property rights is granted by this document. ▪ Intel disclaims all express and implied warranties, including without limitation, the implied warranties of merchantability, fitness for a particular purpose, and non-infringement, as well as any warranty arising from course of performance, course of dealing, or usage in trade. ▪ This document contains information on products, services and/or processes in development. All information provided here is subject to change without notice. Contact your Intel representative to obtain the latest forecast, schedule, specifications and roadmaps. ▪ The products and services described may contain defects or errors known as errata which may cause deviations from published specifications. Current characterized errata are available on request. ▪ Intel, the Intel logo, Xeon, Optane, Optane Persistent Memory are trademarks of Intel Corporation in the U.S. and/or other countries. ▪ *Other names and brands may be claimed as the property of others ▪ © Intel Corporation.