Streaming SQL

Julian Hyde
Julian HydeSoftware Developer at Google, Apache Software Foundation
Streaming SQL
Julian Hyde
Apache Samza meetup
Mountain View, CA
2016/2/17
@julianhyde
SQL
Query planning
Query federation
OLAP
Streaming
Hadoop
Thanks to Milinda Pathirage for his work on samza-
sql and the design of streaming SQL
Why SQL? ● API to your database
● Ask for what you want,
system decides how to get it
● Query planner (optimizer)
converts logical queries to
physical plans
● Mathematically sound
language (relational algebra)
● For all data, not just data in a
database
● Opportunity for novel data
organizations & algorithms
● Standard
https://www.flickr.com/photos/pere/523019984/ (CC BY-NC-SA 2.0)
➢ API to your database
➢ Ask for what you want,
system decides how to get it
➢ Query planner (optimizer)
converts logical queries to
physical plans
➢ Mathematically sound
language (relational algebra)
➢ For all data, not just “flat”
data in a database
➢ Opportunity for novel data
organizations & algorithms
➢ Standard
Why SQL?
How much is your data worth?
Recent data is more valuable
➢ ...if you act on it in time
Data moves from expensive
memory to cheaper disk as it cools
Old + new data is more valuable
still
➢ ...if we have a means to
combine them
Time
Value of
data ($/B)
Now1 hour
ago
1 day
ago
1 week
ago
1 year
ago
Simple queries
select *
from Products
where unitPrice < 20
select stream *
from Orders
where units > 1000
➢ Traditional (non-streaming)
➢ Products is a table
➢ Retrieves records from -∞ to now
➢ Streaming
➢ Orders is a stream
➢ Retrieves records from now to +∞
➢ Query never terminates
Stream-table duality
select *
from Orders
where units > 1000
➢ Yes, you can use a stream as
a table
➢ And you can use a table as a
stream
➢ Actually, Orders is both
➢ Use the stream keyword
➢ Where to actually find the
data? That’s up to the system
select stream *
from Orders
where units > 1000
Combining past and future
select stream *
from Orders as o
where units > (
select avg(units)
from Orders as h
where h.productId = o.productId
and h.rowtime > o.rowtime - interval ‘1’ year)
➢ Orders is used as both stream and table
➢ System determines where to find the records
➢ Query is invalid if records are not available
The “pie chart” problem
➢ Task: Write a web page summarizing
orders over the last hour
➢ Problem: The Orders stream only
contains the current few records
➢ Solution: Materialize short-term history
Orders over the last hour
Beer
48%
Cheese
30%
Wine
22%
select productId, count(*)
from Orders
where rowtime > current_timestamp - interval ‘1’ hour
group by productId
Aggregation and windows
on streams
GROUP BY aggregates multiple rows into sub-
totals
➢ In regular GROUP BY each row contributes
to exactly one sub-total
➢ In multi-GROUP BY (e.g. HOP, GROUPING
SETS) a row can contribute to more than
one sub-total
Window functions leave the number of rows
unchanged, but compute extra expressions for
each row (based on neighboring rows)
Multi
GROUP BY
Window
functions
GROUP BY
GROUP BY select stream productId,
floor(rowtime to hour) as rowtime,
sum(units) as u,
count(*) as c
from Orders
group by productId,
floor(rowtime to hour)
rowtime productId units
09:12 100 5
09:25 130 10
09:59 100 3
10:00 100 19
11:05 130 20
rowtime productId u c
09:00 100 8 2
09:00 130 10 1
10:00 100 19 1
not emitted yet; waiting
for a row >= 12:00
When are rows emitted?
The replay principle:
A streaming query produces the same result as the corresponding non-
streaming query would if given the same data in a table.
Output must not rely on implicit information (arrival order, arrival time,
processing time, or punctuations)
Making progress
It’s not enough to get the right result. We
need to give the right result at the right
time.
Ways to make progress without
compromising safety:
➢ Monotonic columns (e.g. rowtime)
and expressions (e.g. floor
(rowtime to hour))
➢ Punctuations (aka watermarks)
➢ Or a combination of both
select stream productId,
count(*) as c
from Orders
group by productId;
ERROR: Streaming aggregation
requires at least one
monotonic expression in
GROUP BY clause
Window types
➢ Tumbling window: “Every T seconds, emit the total for T seconds”
➢ Hopping window: “Every T seconds, emit the total for T2 seconds”
➢
➢ Sliding window: “Every record, emit the total for the surrounding T seconds”
or “Every record, emit the total for the surrounding T records” (see next slide…)
select … from Orders group by floor(rowtime to hour)
select … from Orders
group by tumble(rowtime, interval ‘1’ hour)
select stream … from Orders
group by hop(rowtime, interval ‘1’ hour, interval ‘2’ hour)
Window functions
select stream sum(units) over w as units1h,
sum(units) over w (partition by productId) as units1hp,
rowtime, productId, units
from Orders
window w as (order by rowtime range interval ‘1’ hour preceding)
rowtime productId units
09:12 100 5
09:25 130 10
09:59 100 3
10:17 100 10
units1h units1hp rowtime productId units
5 5 09:12 100 5
15 10 09:25 130 10
18 8 09:59 100 3
23 13 10:17 100 10
Join stream to a table
Inputs are the Orders stream and the
Products table, output is a stream.
Acts as a “lookup”.
Execute by caching the table in a hash-
map (if table is not too large) and
stream order will be preserved.
select stream *
from Orders as o
join Products as p
on o.productId = p.productId
Join stream to a changing table
Execution is more difficult if the
Products table is being changed
while the query executes.
To do things properly (e.g. to get the
same results when we re-play the
data), we’d need temporal database
semantics.
(Sometimes doing things properly is
too expensive.)
select stream *
from Orders as o
join Products as p
on o.productId = p.productId
and o.rowtime
between p.startEffectiveDate
and p.endEffectiveDate
Join stream to a stream
We can join streams if the join
condition forces them into “lock
step”, within a window (in this case,
1 hour).
Which stream to put input a hash
table? It depends on relative rates,
outer joins, and how we’d like the
output sorted.
select stream *
from Orders as o
join Shipments as s
on o.productId = p.productId
and s.rowtime
between o.rowtime
and o.rowtime + interval ‘1’ hour
Planning queries
MySQL
Splunk
join
Key: productId
group
Key: productName
Agg: count
filter
Condition:
action = 'purchase'
sort
Key: c desc
scan
scan
Table: products
select p.productName, count(*) as c
from splunk.splunk as s
join mysql.products as p
on s.productId = p.productId
where s.action = 'purchase'
group by p.productName
order by c desc
Table: splunk
Optimized query
MySQL
Splunk
join
Key: productId
group
Key: productName
Agg: count
filter
Condition:
action = 'purchase'
sort
Key: c desc
scan
scan
Table: splunk
Table: products
select p.productName, count(*) as c
from splunk.splunk as s
join mysql.products as p
on s.productId = p.productId
where s.action = 'purchase'
group by p.productName
order by c desc
Apache Calcite
Apache top-level project since October, 2015
Query planning framework
➢ Relational algebra, rewrite rules
➢ Cost model & statistics
➢ Federation via adapters
➢ Extensible
Packaging
➢ Library
➢ Optional SQL parser, JDBC server
➢ Community-authored rules, adapters
Embedded Adapters Streaming
Apache Drill
Apache Hive
Apache Kylin
Apache Phoenix*
Cascading
Lingual
Apache
Cassandra*
Apache Spark
CSV
In-memory
JDBC
JSON
MongoDB
Splunk
Web tables
Apache Flink*
Apache Samza
Apache Storm
* Under development
Architecture
Conventional database Calcite
Relational algebra (plus streaming)
Core operators:
➢ Scan
➢ Filter
➢ Project
➢ Join
➢ Sort
➢ Aggregate
➢ Union
➢ Values
Streaming operators:
➢ Delta (converts relation to
stream)
➢ Chi (converts stream to
relation)
In SQL, the STREAM keyword
signifies Delta
Optimizing streaming queries
The usual relational transformations still apply: push filters and projects towards
sources, eliminate empty inputs, etc.
The transformations for delta are mostly simple:
➢ Delta(Filter(r, predicate)) → Filter(Delta(r), predicate)
➢ Delta(Project(r, e0, ...)) → Project(Delta(r), e0, …)
➢ Delta(Union(r0, r1), ALL) → Union(Delta(r0), Delta(r1))
But not always:
➢ Delta(Join(r0, r1, predicate)) → Union(Join(r0, Delta(r1)), Join(Delta(r0), r1)
➢ Delta(Scan(aTable)) → Empty
ORDER BY
Sorting a streaming query is valid as long as the system can make
progress.
select stream productId,
floor(rowtime to hour) as rowtime,
sum(units) as u,
count(*) as c
from Orders
group by productId,
floor(rowtime to hour)
order by rowtime, c desc
Union
As in a typical database, we rewrite x union y
to select distinct * from (x union all y)
We can implement x union all y by simply combining the inputs in arrival
order but output is no longer monotonic. Monotonicity is too useful to squander!
To preserve monotonicity, we merge on the sort key (e.g. rowtime).
DML
➢ View & standing INSERT give same
results
➢ Useful for chained transforms
➢ But internals are different
insert into LargeOrders
select stream * from Orders
where units > 1000
create view LargeOrders as
select stream * from Orders
where units > 1000
upsert into OrdersSummary
select stream productId,
count(*) over lastHour as c
from Orders
window lastHour as (
partition by productId
order by rowtime
range interval ‘1’ hour preceding)
Use DML to maintain a “window”
(materialized stream history).
Summary: Streaming SQL features
Standard SQL over streams and relations
Streaming queries on relations, and relational queries on streams
Joins between stream-stream and stream-relation
Queries are valid if the system can get the data, with a reasonable latency
➢ Monotonic columns and punctuation are ways to achieve this
Views, materialized views and standing queries
Summary: The benefits of streaming SQL
High-level language lets the system optimize quality of service (QoS) and data
location
Give existing tools and traditional users to access streaming data
Combine streaming and historic data
Streaming SQL is a superset of standard SQL
Discussion continues at Apache Calcite, with contributions from Samza, Flink,
Storm and others. (Please join in!)
Thank you!
@julianhyde
@ApacheCalcite
http://calcite.apache.org
http://calcite.apache.org/docs/stream.html
“Data in Flight”, Communications of the ACM, January 2010 [article]
[SAMZA-390] High-level language for SAMZA
1 of 29

Recommended

Streaming SQL with Apache Calcite by
Streaming SQL with Apache CalciteStreaming SQL with Apache Calcite
Streaming SQL with Apache CalciteJulian Hyde
7.7K views34 slides
Toi uu hoa he thong 30 trieu nguoi dung by
Toi uu hoa he thong 30 trieu nguoi dungToi uu hoa he thong 30 trieu nguoi dung
Toi uu hoa he thong 30 trieu nguoi dungIT Expert Club
5.5K views33 slides
Unique ID generation in distributed systems by
Unique ID generation in distributed systemsUnique ID generation in distributed systems
Unique ID generation in distributed systemsDave Gardner
79.4K views31 slides
Apache Flink Adoption at Shopify by
Apache Flink Adoption at ShopifyApache Flink Adoption at Shopify
Apache Flink Adoption at ShopifyYaroslav Tkachenko
1.1K views36 slides
Apache Spark on K8S Best Practice and Performance in the Cloud by
Apache Spark on K8S Best Practice and Performance in the CloudApache Spark on K8S Best Practice and Performance in the Cloud
Apache Spark on K8S Best Practice and Performance in the CloudDatabricks
8K views30 slides
Webinar: Deep Dive on Apache Flink State - Seth Wiesman by
Webinar: Deep Dive on Apache Flink State - Seth WiesmanWebinar: Deep Dive on Apache Flink State - Seth Wiesman
Webinar: Deep Dive on Apache Flink State - Seth WiesmanVerverica
1.2K views49 slides

More Related Content

What's hot

Introduction to Storm by
Introduction to Storm Introduction to Storm
Introduction to Storm Chandler Huang
20.1K views36 slides
Parquet Hadoop Summit 2013 by
Parquet Hadoop Summit 2013Parquet Hadoop Summit 2013
Parquet Hadoop Summit 2013Julien Le Dem
26K views25 slides
Introduction to Apache Flink - Fast and reliable big data processing by
Introduction to Apache Flink - Fast and reliable big data processingIntroduction to Apache Flink - Fast and reliable big data processing
Introduction to Apache Flink - Fast and reliable big data processingTill Rohrmann
7.2K views23 slides
The Parquet Format and Performance Optimization Opportunities by
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesDatabricks
8.2K views32 slides
Evening out the uneven: dealing with skew in Flink by
Evening out the uneven: dealing with skew in FlinkEvening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkFlink Forward
2.5K views35 slides
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P... by
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...Databricks
1K views25 slides

What's hot(20)

Introduction to Storm by Chandler Huang
Introduction to Storm Introduction to Storm
Introduction to Storm
Chandler Huang20.1K views
Parquet Hadoop Summit 2013 by Julien Le Dem
Parquet Hadoop Summit 2013Parquet Hadoop Summit 2013
Parquet Hadoop Summit 2013
Julien Le Dem26K views
Introduction to Apache Flink - Fast and reliable big data processing by Till Rohrmann
Introduction to Apache Flink - Fast and reliable big data processingIntroduction to Apache Flink - Fast and reliable big data processing
Introduction to Apache Flink - Fast and reliable big data processing
Till Rohrmann7.2K views
The Parquet Format and Performance Optimization Opportunities by Databricks
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization Opportunities
Databricks8.2K views
Evening out the uneven: dealing with skew in Flink by Flink Forward
Evening out the uneven: dealing with skew in FlinkEvening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in Flink
Flink Forward2.5K views
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P... by Databricks
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...
Databricks1K views
Dynamic Rule-based Real-time Market Data Alerts by Flink Forward
Dynamic Rule-based Real-time Market Data AlertsDynamic Rule-based Real-time Market Data Alerts
Dynamic Rule-based Real-time Market Data Alerts
Flink Forward749 views
A Deep Dive into Query Execution Engine of Spark SQL by Databricks
A Deep Dive into Query Execution Engine of Spark SQLA Deep Dive into Query Execution Engine of Spark SQL
A Deep Dive into Query Execution Engine of Spark SQL
Databricks6.6K views
Dr. Elephant for Monitoring and Tuning Apache Spark Jobs on Hadoop with Carl ... by Databricks
Dr. Elephant for Monitoring and Tuning Apache Spark Jobs on Hadoop with Carl ...Dr. Elephant for Monitoring and Tuning Apache Spark Jobs on Hadoop with Carl ...
Dr. Elephant for Monitoring and Tuning Apache Spark Jobs on Hadoop with Carl ...
Databricks2.1K views
Deep Dive with Spark Streaming - Tathagata Das - Spark Meetup 2013-06-17 by spark-project
Deep Dive with Spark Streaming - Tathagata  Das - Spark Meetup 2013-06-17Deep Dive with Spark Streaming - Tathagata  Das - Spark Meetup 2013-06-17
Deep Dive with Spark Streaming - Tathagata Das - Spark Meetup 2013-06-17
spark-project53.4K views
Real Time Analytics: Algorithms and Systems by Arun Kejariwal
Real Time Analytics: Algorithms and SystemsReal Time Analytics: Algorithms and Systems
Real Time Analytics: Algorithms and Systems
Arun Kejariwal23K views
Hive, Presto, and Spark on TPC-DS benchmark by Dongwon Kim
Hive, Presto, and Spark on TPC-DS benchmarkHive, Presto, and Spark on TPC-DS benchmark
Hive, Presto, and Spark on TPC-DS benchmark
Dongwon Kim9.6K views
Parquet performance tuning: the missing guide by Ryan Blue
Parquet performance tuning: the missing guideParquet performance tuning: the missing guide
Parquet performance tuning: the missing guide
Ryan Blue40.5K views
Performant Streaming in Production: Preventing Common Pitfalls when Productio... by Databricks
Performant Streaming in Production: Preventing Common Pitfalls when Productio...Performant Streaming in Production: Preventing Common Pitfalls when Productio...
Performant Streaming in Production: Preventing Common Pitfalls when Productio...
Databricks1K views
Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro... by Spark Summit
Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro...Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro...
Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro...
Spark Summit18.2K views
Improving Kafka at-least-once performance at Uber by Ying Zheng
Improving Kafka at-least-once performance at UberImproving Kafka at-least-once performance at Uber
Improving Kafka at-least-once performance at Uber
Ying Zheng1.1K views
Query Compilation in Impala by Cloudera, Inc.
Query Compilation in ImpalaQuery Compilation in Impala
Query Compilation in Impala
Cloudera, Inc.7.8K views
Real-time Analytics with Trino and Apache Pinot by Xiang Fu
Real-time Analytics with Trino and Apache PinotReal-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache Pinot
Xiang Fu1.2K views
Fast federated SQL with Apache Calcite by Chris Baynes
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache Calcite
Chris Baynes1.4K views

Viewers also liked

Apache Calcite: One planner fits all by
Apache Calcite: One planner fits allApache Calcite: One planner fits all
Apache Calcite: One planner fits allJulian Hyde
6.7K views10 slides
Apache Calcite overview by
Apache Calcite overviewApache Calcite overview
Apache Calcite overviewJulian Hyde
19.5K views9 slides
Apache Gearpump next-gen streaming engine by
Apache Gearpump next-gen streaming engineApache Gearpump next-gen streaming engine
Apache Gearpump next-gen streaming engineTianlun Zhang
3.1K views50 slides
Streaming SQL (at FlinkForward, Berlin, 2016/09/12) by
Streaming SQL (at FlinkForward, Berlin, 2016/09/12)Streaming SQL (at FlinkForward, Berlin, 2016/09/12)
Streaming SQL (at FlinkForward, Berlin, 2016/09/12)Julian Hyde
2.8K views35 slides
Streaming SQL by
Streaming SQLStreaming SQL
Streaming SQLDataWorks Summit/Hadoop Summit
2K views36 slides
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ... by
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...Julian Hyde
2.7K views42 slides

Viewers also liked(20)

Apache Calcite: One planner fits all by Julian Hyde
Apache Calcite: One planner fits allApache Calcite: One planner fits all
Apache Calcite: One planner fits all
Julian Hyde6.7K views
Apache Calcite overview by Julian Hyde
Apache Calcite overviewApache Calcite overview
Apache Calcite overview
Julian Hyde19.5K views
Apache Gearpump next-gen streaming engine by Tianlun Zhang
Apache Gearpump next-gen streaming engineApache Gearpump next-gen streaming engine
Apache Gearpump next-gen streaming engine
Tianlun Zhang3.1K views
Streaming SQL (at FlinkForward, Berlin, 2016/09/12) by Julian Hyde
Streaming SQL (at FlinkForward, Berlin, 2016/09/12)Streaming SQL (at FlinkForward, Berlin, 2016/09/12)
Streaming SQL (at FlinkForward, Berlin, 2016/09/12)
Julian Hyde2.8K views
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ... by Julian Hyde
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Julian Hyde2.7K views
SQL on everything, in memory by Julian Hyde
SQL on everything, in memorySQL on everything, in memory
SQL on everything, in memory
Julian Hyde7.4K views
Optiq: A dynamic data management framework by Julian Hyde
Optiq: A dynamic data management frameworkOptiq: A dynamic data management framework
Optiq: A dynamic data management framework
Julian Hyde5.1K views
Towards sql for streams by Radu Tudoran
Towards sql for streamsTowards sql for streams
Towards sql for streams
Radu Tudoran521 views
SQL on Big Data using Optiq by Julian Hyde
SQL on Big Data using OptiqSQL on Big Data using Optiq
SQL on Big Data using Optiq
Julian Hyde3.1K views
Real-time Streaming Analytics for Enterprises based on Apache Storm - Impetus... by Impetus Technologies
Real-time Streaming Analytics for Enterprises based on Apache Storm - Impetus...Real-time Streaming Analytics for Enterprises based on Apache Storm - Impetus...
Real-time Streaming Analytics for Enterprises based on Apache Storm - Impetus...
Streaming SQL by Julian Hyde
Streaming SQLStreaming SQL
Streaming SQL
Julian Hyde1.3K views
Discardable In-Memory Materialized Queries With Hadoop by Julian Hyde
Discardable In-Memory Materialized Queries With HadoopDiscardable In-Memory Materialized Queries With Hadoop
Discardable In-Memory Materialized Queries With Hadoop
Julian Hyde6K views
The twins that everyone loved too much by Julian Hyde
The twins that everyone loved too muchThe twins that everyone loved too much
The twins that everyone loved too much
Julian Hyde2.3K views
Calcite meetup-2016-04-20 by Josh Elser
Calcite meetup-2016-04-20Calcite meetup-2016-04-20
Calcite meetup-2016-04-20
Josh Elser1.1K views
What's new in Mondrian 4? by Julian Hyde
What's new in Mondrian 4?What's new in Mondrian 4?
What's new in Mondrian 4?
Julian Hyde14.5K views
Why you care about
 relational algebra (even though you didn’t know it) by Julian Hyde
Why you care about
 relational algebra (even though you didn’t know it)Why you care about
 relational algebra (even though you didn’t know it)
Why you care about
 relational algebra (even though you didn’t know it)
Julian Hyde11.1K views
Cost-based query optimization in Apache Hive 0.14 by Julian Hyde
Cost-based query optimization in Apache Hive 0.14Cost-based query optimization in Apache Hive 0.14
Cost-based query optimization in Apache Hive 0.14
Julian Hyde4K views
Cost-based query optimization in Apache Hive 0.14 by Julian Hyde
Cost-based query optimization in Apache Hive 0.14Cost-based query optimization in Apache Hive 0.14
Cost-based query optimization in Apache Hive 0.14
Julian Hyde7.7K views

Similar to Streaming SQL

Querying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/Trident by
 Querying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/Trident Querying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/Trident
Querying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/TridentJulian Hyde
3.3K views30 slides
Querying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/Trident by
Querying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/TridentQuerying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/Trident
Querying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/TridentDataWorks Summit/Hadoop Summit
1.1K views30 slides
Julian Hyde - Streaming SQL by
Julian Hyde - Streaming SQLJulian Hyde - Streaming SQL
Julian Hyde - Streaming SQLFlink Forward
841 views35 slides
Streaming SQL w/ Apache Calcite by
Streaming SQL w/ Apache Calcite Streaming SQL w/ Apache Calcite
Streaming SQL w/ Apache Calcite Hortonworks
1.3K views34 slides
Streaming SQL by
Streaming SQLStreaming SQL
Streaming SQLJulian Hyde
6.3K views36 slides
Streaming SQL by
Streaming SQLStreaming SQL
Streaming SQLJulian Hyde
3.6K views30 slides

Similar to Streaming SQL(20)

Querying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/Trident by Julian Hyde
 Querying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/Trident Querying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/Trident
Querying the Internet of Things: Streaming SQL on Kafka/Samza and Storm/Trident
Julian Hyde3.3K views
Julian Hyde - Streaming SQL by Flink Forward
Julian Hyde - Streaming SQLJulian Hyde - Streaming SQL
Julian Hyde - Streaming SQL
Flink Forward841 views
Streaming SQL w/ Apache Calcite by Hortonworks
Streaming SQL w/ Apache Calcite Streaming SQL w/ Apache Calcite
Streaming SQL w/ Apache Calcite
Hortonworks1.3K views
Streaming SQL by Julian Hyde
Streaming SQLStreaming SQL
Streaming SQL
Julian Hyde6.3K views
Streaming SQL by Julian Hyde
Streaming SQLStreaming SQL
Streaming SQL
Julian Hyde3.6K views
Data all over the place! How SQL and Apache Calcite bring sanity to streaming... by Julian Hyde
Data all over the place! How SQL and Apache Calcite bring sanity to streaming...Data all over the place! How SQL and Apache Calcite bring sanity to streaming...
Data all over the place! How SQL and Apache Calcite bring sanity to streaming...
Julian Hyde4K views
WSO2Con USA 2015: WSO2 Analytics Platform - The One Stop Shop for All Your Da... by WSO2
WSO2Con USA 2015: WSO2 Analytics Platform - The One Stop Shop for All Your Da...WSO2Con USA 2015: WSO2 Analytics Platform - The One Stop Shop for All Your Da...
WSO2Con USA 2015: WSO2 Analytics Platform - The One Stop Shop for All Your Da...
WSO2641 views
Scalable Realtime Analytics with declarative SQL like Complex Event Processin... by Srinath Perera
Scalable Realtime Analytics with declarative SQL like Complex Event Processin...Scalable Realtime Analytics with declarative SQL like Complex Event Processin...
Scalable Realtime Analytics with declarative SQL like Complex Event Processin...
Srinath Perera19.8K views
Apache Calcite: One Frontend to Rule Them All by Michael Mior
Apache Calcite: One Frontend to Rule Them AllApache Calcite: One Frontend to Rule Them All
Apache Calcite: One Frontend to Rule Them All
Michael Mior676 views
Strtio Spark Streaming + Siddhi CEP Engine by Myung Ho Yun
Strtio Spark Streaming + Siddhi CEP EngineStrtio Spark Streaming + Siddhi CEP Engine
Strtio Spark Streaming + Siddhi CEP Engine
Myung Ho Yun958 views
WSO2Con ASIA 2016: WSO2 Analytics Platform: The One Stop Shop for All Your Da... by WSO2
WSO2Con ASIA 2016: WSO2 Analytics Platform: The One Stop Shop for All Your Da...WSO2Con ASIA 2016: WSO2 Analytics Platform: The One Stop Shop for All Your Da...
WSO2Con ASIA 2016: WSO2 Analytics Platform: The One Stop Shop for All Your Da...
WSO2873 views
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overview by Flink Forward
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overviewFlink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
Flink Forward465 views
WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor by WSO2
WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor
WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor
WSO2739 views
SCALE - Stream processing and Open Data, a match made in Heaven by Nicolas Frankel
SCALE - Stream processing and Open Data, a match made in HeavenSCALE - Stream processing and Open Data, a match made in Heaven
SCALE - Stream processing and Open Data, a match made in Heaven
Nicolas Frankel259 views
Advance sql - window functions patterns and tricks by Eyal Trabelsi
Advance sql - window functions patterns and tricksAdvance sql - window functions patterns and tricks
Advance sql - window functions patterns and tricks
Eyal Trabelsi1.1K views
Simplifying SQL with CTE's and windowing functions by Clayton Groom
Simplifying SQL with CTE's and windowing functionsSimplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functions
Clayton Groom2.1K views
JUG Tirana - Introduction to data streaming by Nicolas Frankel
JUG Tirana - Introduction to data streamingJUG Tirana - Introduction to data streaming
JUG Tirana - Introduction to data streaming
Nicolas Frankel229 views

More from Julian Hyde

Building a semantic/metrics layer using Calcite by
Building a semantic/metrics layer using CalciteBuilding a semantic/metrics layer using Calcite
Building a semantic/metrics layer using CalciteJulian Hyde
267 views55 slides
Cubing and Metrics in SQL, oh my! by
Cubing and Metrics in SQL, oh my!Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!Julian Hyde
371 views31 slides
Adding measures to Calcite SQL by
Adding measures to Calcite SQLAdding measures to Calcite SQL
Adding measures to Calcite SQLJulian Hyde
394 views30 slides
Morel, a data-parallel programming language by
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming languageJulian Hyde
174 views81 slides
Is there a perfect data-parallel programming language? (Experiments with More... by
Is there a perfect data-parallel programming language? (Experiments with More...Is there a perfect data-parallel programming language? (Experiments with More...
Is there a perfect data-parallel programming language? (Experiments with More...Julian Hyde
366 views97 slides
Morel, a Functional Query Language by
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query LanguageJulian Hyde
1.1K views70 slides

More from Julian Hyde(20)

Building a semantic/metrics layer using Calcite by Julian Hyde
Building a semantic/metrics layer using CalciteBuilding a semantic/metrics layer using Calcite
Building a semantic/metrics layer using Calcite
Julian Hyde267 views
Cubing and Metrics in SQL, oh my! by Julian Hyde
Cubing and Metrics in SQL, oh my!Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!
Julian Hyde371 views
Adding measures to Calcite SQL by Julian Hyde
Adding measures to Calcite SQLAdding measures to Calcite SQL
Adding measures to Calcite SQL
Julian Hyde394 views
Morel, a data-parallel programming language by Julian Hyde
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming language
Julian Hyde174 views
Is there a perfect data-parallel programming language? (Experiments with More... by Julian Hyde
Is there a perfect data-parallel programming language? (Experiments with More...Is there a perfect data-parallel programming language? (Experiments with More...
Is there a perfect data-parallel programming language? (Experiments with More...
Julian Hyde366 views
Morel, a Functional Query Language by Julian Hyde
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query Language
Julian Hyde1.1K views
Apache Calcite (a tutorial given at BOSS '21) by Julian Hyde
Apache Calcite (a tutorial given at BOSS '21)Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)
Julian Hyde2.6K views
The evolution of Apache Calcite and its Community by Julian Hyde
The evolution of Apache Calcite and its CommunityThe evolution of Apache Calcite and its Community
The evolution of Apache Calcite and its Community
Julian Hyde330 views
What to expect when you're Incubating by Julian Hyde
What to expect when you're IncubatingWhat to expect when you're Incubating
What to expect when you're Incubating
Julian Hyde402 views
Open Source SQL - beyond parsers: ZetaSQL and Apache Calcite by Julian Hyde
Open Source SQL - beyond parsers: ZetaSQL and Apache CalciteOpen Source SQL - beyond parsers: ZetaSQL and Apache Calcite
Open Source SQL - beyond parsers: ZetaSQL and Apache Calcite
Julian Hyde1.1K views
Efficient spatial queries on vanilla databases by Julian Hyde
Efficient spatial queries on vanilla databasesEfficient spatial queries on vanilla databases
Efficient spatial queries on vanilla databases
Julian Hyde329 views
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in... by Julian Hyde
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
Julian Hyde1.6K views
Tactical data engineering by Julian Hyde
Tactical data engineeringTactical data engineering
Tactical data engineering
Julian Hyde971 views
Don't optimize my queries, organize my data! by Julian Hyde
Don't optimize my queries, organize my data!Don't optimize my queries, organize my data!
Don't optimize my queries, organize my data!
Julian Hyde1.2K views
Spatial query on vanilla databases by Julian Hyde
Spatial query on vanilla databasesSpatial query on vanilla databases
Spatial query on vanilla databases
Julian Hyde1.1K views
Apache Calcite: A Foundational Framework for Optimized Query Processing Over ... by Julian Hyde
Apache Calcite: A Foundational Framework for Optimized Query Processing Over ...Apache Calcite: A Foundational Framework for Optimized Query Processing Over ...
Apache Calcite: A Foundational Framework for Optimized Query Processing Over ...
Julian Hyde2.3K views
Lazy beats Smart and Fast by Julian Hyde
Lazy beats Smart and FastLazy beats Smart and Fast
Lazy beats Smart and Fast
Julian Hyde975 views
Don’t optimize my queries, optimize my data! by Julian Hyde
Don’t optimize my queries, optimize my data!Don’t optimize my queries, optimize my data!
Don’t optimize my queries, optimize my data!
Julian Hyde4.4K views
Data profiling with Apache Calcite by Julian Hyde
Data profiling with Apache CalciteData profiling with Apache Calcite
Data profiling with Apache Calcite
Julian Hyde1.9K views
A smarter Pig: Building a SQL interface to Apache Pig using Apache Calcite by Julian Hyde
A smarter Pig: Building a SQL interface to Apache Pig using Apache CalciteA smarter Pig: Building a SQL interface to Apache Pig using Apache Calcite
A smarter Pig: Building a SQL interface to Apache Pig using Apache Calcite
Julian Hyde1.7K views

Recently uploaded

Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...ShapeBlue
83 views15 slides
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...ShapeBlue
88 views20 slides
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsShapeBlue
111 views13 slides
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueShapeBlue
96 views7 slides
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue by
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueShapeBlue
46 views13 slides
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueShapeBlue
46 views15 slides

Recently uploaded(20)

Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue83 views
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue88 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue111 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue96 views
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue by ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue46 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue46 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue50 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc77 views
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue by ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueVNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
ShapeBlue85 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays40 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10369 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue57 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue82 views
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... by Moses Kemibaro
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Moses Kemibaro29 views
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue46 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker50 views

Streaming SQL

  • 1. Streaming SQL Julian Hyde Apache Samza meetup Mountain View, CA 2016/2/17
  • 2. @julianhyde SQL Query planning Query federation OLAP Streaming Hadoop Thanks to Milinda Pathirage for his work on samza- sql and the design of streaming SQL
  • 3. Why SQL? ● API to your database ● Ask for what you want, system decides how to get it ● Query planner (optimizer) converts logical queries to physical plans ● Mathematically sound language (relational algebra) ● For all data, not just data in a database ● Opportunity for novel data organizations & algorithms ● Standard https://www.flickr.com/photos/pere/523019984/ (CC BY-NC-SA 2.0) ➢ API to your database ➢ Ask for what you want, system decides how to get it ➢ Query planner (optimizer) converts logical queries to physical plans ➢ Mathematically sound language (relational algebra) ➢ For all data, not just “flat” data in a database ➢ Opportunity for novel data organizations & algorithms ➢ Standard Why SQL?
  • 4. How much is your data worth? Recent data is more valuable ➢ ...if you act on it in time Data moves from expensive memory to cheaper disk as it cools Old + new data is more valuable still ➢ ...if we have a means to combine them Time Value of data ($/B) Now1 hour ago 1 day ago 1 week ago 1 year ago
  • 5. Simple queries select * from Products where unitPrice < 20 select stream * from Orders where units > 1000 ➢ Traditional (non-streaming) ➢ Products is a table ➢ Retrieves records from -∞ to now ➢ Streaming ➢ Orders is a stream ➢ Retrieves records from now to +∞ ➢ Query never terminates
  • 6. Stream-table duality select * from Orders where units > 1000 ➢ Yes, you can use a stream as a table ➢ And you can use a table as a stream ➢ Actually, Orders is both ➢ Use the stream keyword ➢ Where to actually find the data? That’s up to the system select stream * from Orders where units > 1000
  • 7. Combining past and future select stream * from Orders as o where units > ( select avg(units) from Orders as h where h.productId = o.productId and h.rowtime > o.rowtime - interval ‘1’ year) ➢ Orders is used as both stream and table ➢ System determines where to find the records ➢ Query is invalid if records are not available
  • 8. The “pie chart” problem ➢ Task: Write a web page summarizing orders over the last hour ➢ Problem: The Orders stream only contains the current few records ➢ Solution: Materialize short-term history Orders over the last hour Beer 48% Cheese 30% Wine 22% select productId, count(*) from Orders where rowtime > current_timestamp - interval ‘1’ hour group by productId
  • 9. Aggregation and windows on streams GROUP BY aggregates multiple rows into sub- totals ➢ In regular GROUP BY each row contributes to exactly one sub-total ➢ In multi-GROUP BY (e.g. HOP, GROUPING SETS) a row can contribute to more than one sub-total Window functions leave the number of rows unchanged, but compute extra expressions for each row (based on neighboring rows) Multi GROUP BY Window functions GROUP BY
  • 10. GROUP BY select stream productId, floor(rowtime to hour) as rowtime, sum(units) as u, count(*) as c from Orders group by productId, floor(rowtime to hour) rowtime productId units 09:12 100 5 09:25 130 10 09:59 100 3 10:00 100 19 11:05 130 20 rowtime productId u c 09:00 100 8 2 09:00 130 10 1 10:00 100 19 1 not emitted yet; waiting for a row >= 12:00
  • 11. When are rows emitted? The replay principle: A streaming query produces the same result as the corresponding non- streaming query would if given the same data in a table. Output must not rely on implicit information (arrival order, arrival time, processing time, or punctuations)
  • 12. Making progress It’s not enough to get the right result. We need to give the right result at the right time. Ways to make progress without compromising safety: ➢ Monotonic columns (e.g. rowtime) and expressions (e.g. floor (rowtime to hour)) ➢ Punctuations (aka watermarks) ➢ Or a combination of both select stream productId, count(*) as c from Orders group by productId; ERROR: Streaming aggregation requires at least one monotonic expression in GROUP BY clause
  • 13. Window types ➢ Tumbling window: “Every T seconds, emit the total for T seconds” ➢ Hopping window: “Every T seconds, emit the total for T2 seconds” ➢ ➢ Sliding window: “Every record, emit the total for the surrounding T seconds” or “Every record, emit the total for the surrounding T records” (see next slide…) select … from Orders group by floor(rowtime to hour) select … from Orders group by tumble(rowtime, interval ‘1’ hour) select stream … from Orders group by hop(rowtime, interval ‘1’ hour, interval ‘2’ hour)
  • 14. Window functions select stream sum(units) over w as units1h, sum(units) over w (partition by productId) as units1hp, rowtime, productId, units from Orders window w as (order by rowtime range interval ‘1’ hour preceding) rowtime productId units 09:12 100 5 09:25 130 10 09:59 100 3 10:17 100 10 units1h units1hp rowtime productId units 5 5 09:12 100 5 15 10 09:25 130 10 18 8 09:59 100 3 23 13 10:17 100 10
  • 15. Join stream to a table Inputs are the Orders stream and the Products table, output is a stream. Acts as a “lookup”. Execute by caching the table in a hash- map (if table is not too large) and stream order will be preserved. select stream * from Orders as o join Products as p on o.productId = p.productId
  • 16. Join stream to a changing table Execution is more difficult if the Products table is being changed while the query executes. To do things properly (e.g. to get the same results when we re-play the data), we’d need temporal database semantics. (Sometimes doing things properly is too expensive.) select stream * from Orders as o join Products as p on o.productId = p.productId and o.rowtime between p.startEffectiveDate and p.endEffectiveDate
  • 17. Join stream to a stream We can join streams if the join condition forces them into “lock step”, within a window (in this case, 1 hour). Which stream to put input a hash table? It depends on relative rates, outer joins, and how we’d like the output sorted. select stream * from Orders as o join Shipments as s on o.productId = p.productId and s.rowtime between o.rowtime and o.rowtime + interval ‘1’ hour
  • 18. Planning queries MySQL Splunk join Key: productId group Key: productName Agg: count filter Condition: action = 'purchase' sort Key: c desc scan scan Table: products select p.productName, count(*) as c from splunk.splunk as s join mysql.products as p on s.productId = p.productId where s.action = 'purchase' group by p.productName order by c desc Table: splunk
  • 19. Optimized query MySQL Splunk join Key: productId group Key: productName Agg: count filter Condition: action = 'purchase' sort Key: c desc scan scan Table: splunk Table: products select p.productName, count(*) as c from splunk.splunk as s join mysql.products as p on s.productId = p.productId where s.action = 'purchase' group by p.productName order by c desc
  • 20. Apache Calcite Apache top-level project since October, 2015 Query planning framework ➢ Relational algebra, rewrite rules ➢ Cost model & statistics ➢ Federation via adapters ➢ Extensible Packaging ➢ Library ➢ Optional SQL parser, JDBC server ➢ Community-authored rules, adapters Embedded Adapters Streaming Apache Drill Apache Hive Apache Kylin Apache Phoenix* Cascading Lingual Apache Cassandra* Apache Spark CSV In-memory JDBC JSON MongoDB Splunk Web tables Apache Flink* Apache Samza Apache Storm * Under development
  • 22. Relational algebra (plus streaming) Core operators: ➢ Scan ➢ Filter ➢ Project ➢ Join ➢ Sort ➢ Aggregate ➢ Union ➢ Values Streaming operators: ➢ Delta (converts relation to stream) ➢ Chi (converts stream to relation) In SQL, the STREAM keyword signifies Delta
  • 23. Optimizing streaming queries The usual relational transformations still apply: push filters and projects towards sources, eliminate empty inputs, etc. The transformations for delta are mostly simple: ➢ Delta(Filter(r, predicate)) → Filter(Delta(r), predicate) ➢ Delta(Project(r, e0, ...)) → Project(Delta(r), e0, …) ➢ Delta(Union(r0, r1), ALL) → Union(Delta(r0), Delta(r1)) But not always: ➢ Delta(Join(r0, r1, predicate)) → Union(Join(r0, Delta(r1)), Join(Delta(r0), r1) ➢ Delta(Scan(aTable)) → Empty
  • 24. ORDER BY Sorting a streaming query is valid as long as the system can make progress. select stream productId, floor(rowtime to hour) as rowtime, sum(units) as u, count(*) as c from Orders group by productId, floor(rowtime to hour) order by rowtime, c desc
  • 25. Union As in a typical database, we rewrite x union y to select distinct * from (x union all y) We can implement x union all y by simply combining the inputs in arrival order but output is no longer monotonic. Monotonicity is too useful to squander! To preserve monotonicity, we merge on the sort key (e.g. rowtime).
  • 26. DML ➢ View & standing INSERT give same results ➢ Useful for chained transforms ➢ But internals are different insert into LargeOrders select stream * from Orders where units > 1000 create view LargeOrders as select stream * from Orders where units > 1000 upsert into OrdersSummary select stream productId, count(*) over lastHour as c from Orders window lastHour as ( partition by productId order by rowtime range interval ‘1’ hour preceding) Use DML to maintain a “window” (materialized stream history).
  • 27. Summary: Streaming SQL features Standard SQL over streams and relations Streaming queries on relations, and relational queries on streams Joins between stream-stream and stream-relation Queries are valid if the system can get the data, with a reasonable latency ➢ Monotonic columns and punctuation are ways to achieve this Views, materialized views and standing queries
  • 28. Summary: The benefits of streaming SQL High-level language lets the system optimize quality of service (QoS) and data location Give existing tools and traditional users to access streaming data Combine streaming and historic data Streaming SQL is a superset of standard SQL Discussion continues at Apache Calcite, with contributions from Samza, Flink, Storm and others. (Please join in!)
  • 29. Thank you! @julianhyde @ApacheCalcite http://calcite.apache.org http://calcite.apache.org/docs/stream.html “Data in Flight”, Communications of the ACM, January 2010 [article] [SAMZA-390] High-level language for SAMZA