SlideShare a Scribd company logo
Fun with ClickHouse
Window Functions
Robert Hodges and Vitaliy Zakaznikov @ Altinity
1
Presenter Bios and Altinity Introduction
The #1 enterprise ClickHouse provider. Now offering Altinity.Cloud
Major committer and community sponsor for ClickHouse in US/EU
Robert Hodges - CEO
30+ years on DBMS plus
virtualization and security.
ClickHouse is DBMS #20
Vitaliy Zakaznikov - QA Manager
13+ years testing hardware and
software; author of TestFlows
open source testing framework
ClickHouse: a great SQL data warehouse
Understands SQL
Runs on bare metal to cloud
Shared nothing architecture
Stores data in columns
Parallel and vectorized execution
Scales to many petabytes
Is Open source (Apache 2.0)
a b c d
a b c d
a b c d
a b c d
And it’s really fast!
3
Using the Altinity.Cloud public endpoint
4
https://github.demo.trial.altinity.cloud:8443/play
User
“demo”
Password
“demo”
clickhouse-client --host=github.demo.trial.altinity.cloud
-s --user=demo --password
What are
Window
Functions?
5
Let’s start with a simple query...
SELECT FlightDate,
count() AS Flights,
sum(Cancelled) AS Sum_Cancelled
FROM ontime
WHERE toYYYYMM(FlightDate) = 201901
GROUP BY FlightDate
ORDER BY FlightDate
FlightDate|Flights|Sum_Cancelled|
----------|-------|-------------|
2019-01-01| 18009| 141|
2019-01-02| 20384| 173|
6
Cancelled flights for
Jan 2019
7
SQL queries work like “cubes”
7
FlightDate
Cancelled
0 --
1 --
1/01 1/02 1/03 1/04 1/05 1/06 1/07 1/07 . ..
16807 Flights
129 Cancelled
Dimension
Metrics
(count, sum)
Dimension
Carrier
F
l
i
g
h
t
N
u
m
TailNum
(Other dimensions)
...But what happens if we want to...
8
Rank particular days by
number of cancelled flights?
Print cumulative cancellations
for each month?
Print trailing 7-day average
cancellations?
8
How can I do that in SQL??
This is a job for window functions!
9
Set session variable
clickhouse101 :) SET allow_experimental_window_functions = 1
SET allow_experimental_window_functions = 1
Query id: f8aec38c-7f31-4544-96df-bcdb4034f0ac
Ok.
<yandex>
<profiles>
<default>
<allow_experimental_window_functions>1</allow_...tions>
. . .
</default></profiles></yandex>
But first we need to enable them...
Set in user profile
Window functions add a new option to SQL
SELECT FlightDate, count() AS Flights,
sum(Cancelled) AS Daily_Cancelled,
avg(Daily_Cancelled)
OVER (ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)
AS Avg_Cancelled_7
FROM ontime_ref
WHERE Year = 2019 GROUP BY FlightDate ORDER BY FlightDate
FlightDate|Flights|Daily_Cancelled|Avg_Cancelled_7 |
----------|-------|---------------|------------------|
. . .
2019-01-30| 19102| 2145| 805.5714285714286|
2019-01-31| 19962| 1775| 999.0|
2019-02-01| 20045| 459|1037.2857142857142|
10
Window function!
How window functions work conceptually
SELECT FlightDate,
count() AS Flights,
sum(Cancelled) AS Daily_Cancelled,
avg(Daily_Cancelled)
OVER (ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)
AS Avg_Cancelled_7
FROM ontime_ref
WHERE Year = 2019
GROUP BY FlightDate
ORDER BY FlightDate
11
Operates on the
computed aggregate
Computes average
within a window
“frame” of 7 rows
Result is another
output column
Window
Functions -- The
gory details
21.3 (LTS) - First experimental
support
21.8 - Pre-release experimental
feature (should be enabled by
default soon)
12
How do window functions work for users?
13
Why do we need “gory details” anyway?
14
● Empty OVER clause means that there is
only one window that includes all the
result rows
● When no ORDER BY clause is specified
then all rows are the peers of the
current row
● The default frame is RANGE BETWEEN
UNBOUNDED PRECEDING AND
CURRENT ROW
SELECT
number,
sum(number) OVER ()
FROM numbers(1, 5)
┌─number─┬─sum(number) OVER ()─┐
│ 1 │ 15 │
│ 2 │ 15 │
│ 3 │ 15 │
│ 4 │ 15 │
│ 5 │ 15 │
└────────┴─────────────────────┘
Window function behavior is not obvious!
What can be a window function?
15
Any aggregate function
● min
● max
● sum
● avg
● etc.
SELECT number, min(number)
OVER () FROM numbers(1,5)
Window native function
● row_number
● first_value
● last_value
● rank
● dense_rank
● leadInFrame
● lagInFrame
SELECT number, rank() OVER (ORDER BY
number) FROM numbers(1,5)
What is an OVER clause?
16
● Can be empty
OVER defines the window specification
● Can contain window
specification
SELECT number,
sum(number) OVER ()
FROM numbers(1,5)
SELECT number,
sum(number) OVER (PARTITION BY number)
FROM numbers(1,5)
● Can refer to a named
window
SELECT number,
sum(number) OVER w
FROM numbers(1,5)
WINDOW w AS (PARTITION BY number)
What do window specifications look like?
17
● PARTITION BY clause
Defines window partition
Window Specification clause
[partition_clause] [order_clause] [frame_clause]
● ORDER BY clause
Orders rows within a frame
SELECT number,
sum(number) OVER (PARTITION BY number % 2)
FROM numbers(1,5)
SELECT number,
sum(number) OVER (ORDER BY number)
FROM numbers(1,5)
● FRAME clause
Defines frame within a
window partition
SELECT number,
sum(number) OVER (ROWS BETWEEN
UNBOUNDED PRECEDING AND CURRENT ROW)
FROM numbers(1,5)
What kind of frames are there?
18
● ROWS frame
Defines a frame with the range in
terms of relationship of rows to the
current row number
SELECT
number,
sum(number) OVER (ORDER BY
number ROWS 1 PRECEDING) AS sum
FROM numbers(1, 3)
┌─number─┬─sum─┐
│ 1 │ 1 │
│ 2 │ 3 │
│ 3 │ 5 │
└────────┴─────┘
FRAME clause
● RANGE frame
Defines a frame with the range in terms of row
values from the current row value.
SELECT
number,
sum(number) OVER (ORDER BY number RANGE
1 PRECEDING) AS sum
FROM values('number Int8', 1, 2, 2, 4)
┌─number─┬─sum─┐
│ 1 │ 1 │
│ 2 │ 5 │
│ 2 │ 5 │
│ 4 │ 4 │
└────────┴─────┘
What are current rows peers?
19
● With ORDER BY clause
SELECT
number,
sum(number) OVER (ORDER BY number)
AS sum
FROM values('number Int8', 1, 2, 2, 3,
4, 5)
┌─number─┬─sum─┐
│ 1 │ 1 │
│ 2 │ 5 │
│ 2 │ 5 │
│ 3 │ 8 │
│ 4 │ 12 │
│ 5 │ 17 │
└────────┴─────┘
CURRENT ROW Peers
Are rows that fall into the same sort bucket and applies only to RANGE frame.
● No ORDER BY clause
SELECT
number,
sum(number) OVER () AS sum
FROM values('number Int8', 1, 2, 2, 3,
4, 5)
┌─number─┬─sum─┐
│ 1 │ 17 │
│ 2 │ 17 │
│ 2 │ 17 │
│ 3 │ 17 │
│ 4 │ 17 │
│ 5 │ 17 │
└────────┴─────┘
How do we define the extent of the frame?
20
● frame START
Defines start of the frame with the end
being set implicitly to current row (for
both ROWS and RANGE frame)
SELECT number,sum(number) OVER
(ORDER BY number ROWS 1
PRECEDING) AS sum FROM
numbers(1,5)
is actually
SELECT
number,
sum(number) OVER (ORDER BY
number ASC ROWS BETWEEN 1
PRECEDING AND CURRENT ROW) AS sum
FROM numbers(1, 5)
FRAME extent clause
● frame BETWEEN
Defines a frame with start and end specified explicitly
SELECT number,sum(number) OVER (ORDER BY
number ROWS BETWEEN 1 PRECEDING AND 1
FOLLOWING) AS sum FROM numbers(1,5)
is actually the same
SELECT
number,
sum(number) OVER (ORDER BY number ASC
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
AS sum
FROM numbers(1, 5)
More on frame extents!
21
● CURRENT ROW
Current row as the frame slides through the window
● UNBOUNDED PRECEDING
All rows before current row, if ROWS frame,
or first row’s value in window partition, if RANGE
frame
● UNBOUNDED FOLLOWING
All rows after current row, if ROWS frame,
or last row’s value in window partition if RANGE frame
FRAME extent clause
● expr PRECEDING
Offset in rows before current row, if ROWS frame,
or current row value minus expr, if RANGE frame
● expr FOLLOWING
Offset in rows before current row, if ROWS frame,
or current row value plus expr, if RANGE frame
Frame START and frame END offsets can be specified as
How do window functions work internally?
22
Apply window
functions
Fully
Aggregate,
Sort
Scan,
Partially
Aggregate
Scan,
Partially
Aggregate
Scan,
Partially
Aggregate
Data
Data
Data
Result
Sequential Sequential
Parallel
Using Window
functions in
practice
21.3 (LTS) - First experimental
support
21.8 - Pre-release experimental
feature
23
Computing cumulative monthly cancellations
SELECT FlightDate, count() AS Flights,
sum(Cancelled) AS Daily_Cancelled,
sum(Daily_Cancelled)
OVER (PARTITION BY toStartOfMonth(FlightDate)
ORDER BY FlightDate)
AS Cumul_Cancelled
FROM ontime
WHERE Year = 2019 GROUP BY FlightDate ORDER BY FlightDate
FlightDate|Flights|Daily_Cancelled|Cumul_Cancelled|
----------|-------|---------------|---------------|
2019-01-01| 18009| 141| 141|
2019-01-02| 20384| 173| 314|
. . .
24
Group by flight month
Order by date of light
Rank cancellations by week
SELECT FlightDate, count() AS Flights,
sum(Cancelled) AS Daily_Cancelled,
rank() OVER
(PARTITION BY toStartOfWeek(FlightDate)
ORDER BY Daily_Cancelled DESC) as Weekly_Rank
FROM ontime
WHERE Year = 2019 GROUP BY FlightDate ORDER BY FlightDate
FlightDate|Flights|Daily_Cancelled|Weekly_Rank|
----------|-------|---------------|-----------|
2019-01-01| 18009| 141| 2|
2019-01-02| 20384| 173| 1|
2019-01-03| 19522| 134| 3|
25
Group by week
Multiple ranks for aircraft flights
SELECT TailNum, any(Carrier) AS Carrier, count() Flights,
rank() OVER (ORDER BY Flights DESC) as Overall_Rank,
rank() OVER (PARTITION BY Carrier ORDER BY Flights DESC) as
Carrier_Rank
FROM ontime
WHERE toYYYYMM(FlightDate) = 201901
GROUP BY TailNum ORDER BY Flights DESC
TailNum|Carrier|Flights|Overall_Rank|Carrier_Rank|
-------|-------|-------|------------|------------|
|OH | 2543| 1| 1|
N488HA |HA | 361| 2| 1|
N481HA |HA | 348| 3| 2|
26
Reuse window definitions
SELECT FlightDate, count() AS Flights,
sum(Cancelled) AS Daily_Cancelled,
min(Daily_Cancelled) OVER 7_day as Min_Cancelled_7,
avg(Daily_Cancelled) OVER 7_day as Avg_Cancelled_7,
max(Daily_Cancelled) OVER 7_day as Max_Cancelled_7
FROM ontime WHERE Year = 2019
GROUP BY FlightDate WINDOW 7_day AS (ROWS BETWEEN 6 PRECEDING
AND CURRENT ROW) ORDER BY FlightDate
FlightDate|Flights|Daily_Cancelled|Min_Cancelled_7|...
----------|-------|---------------|---------------|...
2019-01-01| 18009| 141| 141|...
2019-01-02| 20384| 173| 141|...
27
Are window functions the only way?
28
“Definitely not!”
Rank cancellations by week using arrays
SELECT FlightDate, Flights, Daily_Cancelled, Weekly_Rank FROM
(
SELECT
groupArray(FlightDate) AS FlightDate_Arr,
groupArray(Flights) AS Flights_Arr,
groupArray(Daily_Cancelled) AS Daily_Cancelled_Arr,
arrayEnumerate(Daily_Cancelled_Arr) AS Daily_Cancelled_Indexes,
arraySort((x, y) -> -y, Daily_Cancelled_Indexes, Daily_Cancelled_Arr) as Rank_Array
FROM
(
SELECT FlightDate, count() AS Flights,
sum(Cancelled) AS Daily_Cancelled
FROM ontime
WHERE Year = 2019 GROUP BY FlightDate ORDER BY FlightDate
)
GROUP BY toStartOfWeek(FlightDate)
ORDER BY toStartOfWeek(FlightDate)
)
ARRAY JOIN FlightDate_Arr AS FlightDate, Flights_Arr AS Flights,
Daily_Cancelled_Arr AS Daily_Cancelled, Rank_Array AS Weekly_Rank
ORDER BY FlightDate
29
Sort indexes by descending
sum of cancelled flights
Unroll arrays again
Roll up values by week
Roadmap and
more
information
30
Not supported or doesn’t work
Some features of window functions that are not supported now or don’t work
● RANGE frame only works for UIntX/IntX, Date and DateTime types and is not
supported for other data types including Nullable
● No INTERVAL support for Date and DateTime types
● No EXCLUDE clause
● No GROUPS frame
● No lag(value, offset) and lag(value, offset) functions but workaround is
documented
● Expressions can’t use window functions
● Can’t use RANGE frame with a named window
31
More information on window functions
● ClickHouse window function docs
● Altinity Blog: ClickHouse Window Functions — Current State of the Art
● Altinity Software Requirements Spec: SRS019 ClickHouse Window Functions
● Alinity Knowledge Base, e.g., cumulative sums
● Blog article on Window Functions by TinyBird.co
32
33
And special thanks to:
33
Alexander Kuzmenkov @ Yandex -- Implemented window functions
Alexey Milovidov @ Yandex -- ClickHouse lead committer
Altinity QA team -- Testing!
Questions?
Thank you!
Altinity
https://altinity.com
ClickHouse
https://github.com/ClickH
ouse/ClickHouse
Altinity.Cloud
https://altinity.com/cloud-
database/
We are hiring!
34

More Related Content

What's hot

ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEOClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
Altinity Ltd
 
High Performance, High Reliability Data Loading on ClickHouse
High Performance, High Reliability Data Loading on ClickHouseHigh Performance, High Reliability Data Loading on ClickHouse
High Performance, High Reliability Data Loading on ClickHouse
Altinity Ltd
 
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdfDeep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Altinity Ltd
 
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
Altinity Ltd
 
Altinity Quickstart for ClickHouse-2202-09-15.pdf
Altinity Quickstart for ClickHouse-2202-09-15.pdfAltinity Quickstart for ClickHouse-2202-09-15.pdf
Altinity Quickstart for ClickHouse-2202-09-15.pdf
Altinity Ltd
 
Webinar slides: MORE secrets of ClickHouse Query Performance. By Robert Hodge...
Webinar slides: MORE secrets of ClickHouse Query Performance. By Robert Hodge...Webinar slides: MORE secrets of ClickHouse Query Performance. By Robert Hodge...
Webinar slides: MORE secrets of ClickHouse Query Performance. By Robert Hodge...
Altinity Ltd
 
All about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdfAll about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdf
Altinity Ltd
 
ClickHouse Materialized Views: The Magic Continues
ClickHouse Materialized Views: The Magic ContinuesClickHouse Materialized Views: The Magic Continues
ClickHouse Materialized Views: The Magic Continues
Altinity Ltd
 
A Fast Intro to Fast Query with ClickHouse, by Robert Hodges
A Fast Intro to Fast Query with ClickHouse, by Robert HodgesA Fast Intro to Fast Query with ClickHouse, by Robert Hodges
A Fast Intro to Fast Query with ClickHouse, by Robert Hodges
Altinity Ltd
 
Your first ClickHouse data warehouse
Your first ClickHouse data warehouseYour first ClickHouse data warehouse
Your first ClickHouse data warehouse
Altinity Ltd
 
ClickHouse Deep Dive, by Aleksei Milovidov
ClickHouse Deep Dive, by Aleksei MilovidovClickHouse Deep Dive, by Aleksei Milovidov
ClickHouse Deep Dive, by Aleksei Milovidov
Altinity Ltd
 
ClickHouse on Kubernetes! By Robert Hodges, Altinity CEO
ClickHouse on Kubernetes! By Robert Hodges, Altinity CEOClickHouse on Kubernetes! By Robert Hodges, Altinity CEO
ClickHouse on Kubernetes! By Robert Hodges, Altinity CEO
Altinity Ltd
 
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEOClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
Altinity Ltd
 
10 Good Reasons to Use ClickHouse
10 Good Reasons to Use ClickHouse10 Good Reasons to Use ClickHouse
10 Good Reasons to Use ClickHouse
rpolat
 
[Meetup] a successful migration from elastic search to clickhouse
[Meetup] a successful migration from elastic search to clickhouse[Meetup] a successful migration from elastic search to clickhouse
[Meetup] a successful migration from elastic search to clickhouse
Vianney FOUCAULT
 
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander ZaitsevMigration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
Altinity Ltd
 
Adventures with the ClickHouse ReplacingMergeTree Engine
Adventures with the ClickHouse ReplacingMergeTree EngineAdventures with the ClickHouse ReplacingMergeTree Engine
Adventures with the ClickHouse ReplacingMergeTree Engine
Altinity Ltd
 
Fun with click house window functions webinar slides 2021-08-19
Fun with click house window functions webinar slides  2021-08-19Fun with click house window functions webinar slides  2021-08-19
Fun with click house window functions webinar slides 2021-08-19
Altinity Ltd
 
Dangerous on ClickHouse in 30 minutes, by Robert Hodges, Altinity CEO
Dangerous on ClickHouse in 30 minutes, by Robert Hodges, Altinity CEODangerous on ClickHouse in 30 minutes, by Robert Hodges, Altinity CEO
Dangerous on ClickHouse in 30 minutes, by Robert Hodges, Altinity CEO
Altinity Ltd
 
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
Altinity Ltd
 

What's hot (20)

ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEOClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
 
High Performance, High Reliability Data Loading on ClickHouse
High Performance, High Reliability Data Loading on ClickHouseHigh Performance, High Reliability Data Loading on ClickHouse
High Performance, High Reliability Data Loading on ClickHouse
 
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdfDeep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
 
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
 
Altinity Quickstart for ClickHouse-2202-09-15.pdf
Altinity Quickstart for ClickHouse-2202-09-15.pdfAltinity Quickstart for ClickHouse-2202-09-15.pdf
Altinity Quickstart for ClickHouse-2202-09-15.pdf
 
Webinar slides: MORE secrets of ClickHouse Query Performance. By Robert Hodge...
Webinar slides: MORE secrets of ClickHouse Query Performance. By Robert Hodge...Webinar slides: MORE secrets of ClickHouse Query Performance. By Robert Hodge...
Webinar slides: MORE secrets of ClickHouse Query Performance. By Robert Hodge...
 
All about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdfAll about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdf
 
ClickHouse Materialized Views: The Magic Continues
ClickHouse Materialized Views: The Magic ContinuesClickHouse Materialized Views: The Magic Continues
ClickHouse Materialized Views: The Magic Continues
 
A Fast Intro to Fast Query with ClickHouse, by Robert Hodges
A Fast Intro to Fast Query with ClickHouse, by Robert HodgesA Fast Intro to Fast Query with ClickHouse, by Robert Hodges
A Fast Intro to Fast Query with ClickHouse, by Robert Hodges
 
Your first ClickHouse data warehouse
Your first ClickHouse data warehouseYour first ClickHouse data warehouse
Your first ClickHouse data warehouse
 
ClickHouse Deep Dive, by Aleksei Milovidov
ClickHouse Deep Dive, by Aleksei MilovidovClickHouse Deep Dive, by Aleksei Milovidov
ClickHouse Deep Dive, by Aleksei Milovidov
 
ClickHouse on Kubernetes! By Robert Hodges, Altinity CEO
ClickHouse on Kubernetes! By Robert Hodges, Altinity CEOClickHouse on Kubernetes! By Robert Hodges, Altinity CEO
ClickHouse on Kubernetes! By Robert Hodges, Altinity CEO
 
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEOClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
 
10 Good Reasons to Use ClickHouse
10 Good Reasons to Use ClickHouse10 Good Reasons to Use ClickHouse
10 Good Reasons to Use ClickHouse
 
[Meetup] a successful migration from elastic search to clickhouse
[Meetup] a successful migration from elastic search to clickhouse[Meetup] a successful migration from elastic search to clickhouse
[Meetup] a successful migration from elastic search to clickhouse
 
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander ZaitsevMigration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
 
Adventures with the ClickHouse ReplacingMergeTree Engine
Adventures with the ClickHouse ReplacingMergeTree EngineAdventures with the ClickHouse ReplacingMergeTree Engine
Adventures with the ClickHouse ReplacingMergeTree Engine
 
Fun with click house window functions webinar slides 2021-08-19
Fun with click house window functions webinar slides  2021-08-19Fun with click house window functions webinar slides  2021-08-19
Fun with click house window functions webinar slides 2021-08-19
 
Dangerous on ClickHouse in 30 minutes, by Robert Hodges, Altinity CEO
Dangerous on ClickHouse in 30 minutes, by Robert Hodges, Altinity CEODangerous on ClickHouse in 30 minutes, by Robert Hodges, Altinity CEO
Dangerous on ClickHouse in 30 minutes, by Robert Hodges, Altinity CEO
 
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
 

Similar to Fun with ClickHouse Window Functions-2021-08-19.pdf

Simplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functionsSimplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functions
Clayton Groom
 
The Magic of Window Functions in Postgres
The Magic of Window Functions in PostgresThe Magic of Window Functions in Postgres
The Magic of Window Functions in Postgres
EDB
 
Scaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQLScaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQL
Jim Mlodgenski
 
Demystifying cost based optimization
Demystifying cost based optimizationDemystifying cost based optimization
Demystifying cost based optimization
Riyaj Shamsudeen
 
SQL Windowing
SQL WindowingSQL Windowing
SQL Windowing
Sandun Perera
 
5.Analytical Function.pdf
5.Analytical Function.pdf5.Analytical Function.pdf
5.Analytical Function.pdf
ssuser8b6c85
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
Mahmoud Ouf
 
A day in the life of a click house query
A day in the life of a click house queryA day in the life of a click house query
A day in the life of a click house query
CristinaMunteanu43
 
PostgreSQL: Data analysis and analytics
PostgreSQL: Data analysis and analyticsPostgreSQL: Data analysis and analytics
PostgreSQL: Data analysis and analytics
Hans-Jürgen Schönig
 
Pro PostgreSQL
Pro PostgreSQLPro PostgreSQL
Pro PostgreSQL
Robert Treat
 
J. Adcock Bi Portfolio
J. Adcock   Bi PortfolioJ. Adcock   Bi Portfolio
J. Adcock Bi Portfolio
Jerry Adcock
 
Bis 345-final-exam-guide-set-1-new
Bis 345-final-exam-guide-set-1-newBis 345-final-exam-guide-set-1-new
Bis 345-final-exam-guide-set-1-new
assignmentcloud85
 
ClickHouse materialized views - a secret weapon for high performance analytic...
ClickHouse materialized views - a secret weapon for high performance analytic...ClickHouse materialized views - a secret weapon for high performance analytic...
ClickHouse materialized views - a secret weapon for high performance analytic...
Altinity Ltd
 
Data Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsData Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database Analytics
Dave Stokes
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
RaajTech
 
Do You Know The 11g Plan?
Do You Know The 11g Plan?Do You Know The 11g Plan?
Do You Know The 11g Plan?
Mahesh Vallampati
 
Aorta interpreter Builder 2019
Aorta interpreter Builder 2019Aorta interpreter Builder 2019
Aorta interpreter Builder 2019
Igor Braga
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performance
Guy Harrison
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
DataminingTools Inc
 

Similar to Fun with ClickHouse Window Functions-2021-08-19.pdf (20)

Simplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functionsSimplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functions
 
The Magic of Window Functions in Postgres
The Magic of Window Functions in PostgresThe Magic of Window Functions in Postgres
The Magic of Window Functions in Postgres
 
Scaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQLScaling PostgreSQL With GridSQL
Scaling PostgreSQL With GridSQL
 
Demystifying cost based optimization
Demystifying cost based optimizationDemystifying cost based optimization
Demystifying cost based optimization
 
SQL Windowing
SQL WindowingSQL Windowing
SQL Windowing
 
5.Analytical Function.pdf
5.Analytical Function.pdf5.Analytical Function.pdf
5.Analytical Function.pdf
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
 
A day in the life of a click house query
A day in the life of a click house queryA day in the life of a click house query
A day in the life of a click house query
 
PostgreSQL: Data analysis and analytics
PostgreSQL: Data analysis and analyticsPostgreSQL: Data analysis and analytics
PostgreSQL: Data analysis and analytics
 
Chapter5.ppt
Chapter5.pptChapter5.ppt
Chapter5.ppt
 
Pro PostgreSQL
Pro PostgreSQLPro PostgreSQL
Pro PostgreSQL
 
J. Adcock Bi Portfolio
J. Adcock   Bi PortfolioJ. Adcock   Bi Portfolio
J. Adcock Bi Portfolio
 
Bis 345-final-exam-guide-set-1-new
Bis 345-final-exam-guide-set-1-newBis 345-final-exam-guide-set-1-new
Bis 345-final-exam-guide-set-1-new
 
ClickHouse materialized views - a secret weapon for high performance analytic...
ClickHouse materialized views - a secret weapon for high performance analytic...ClickHouse materialized views - a secret weapon for high performance analytic...
ClickHouse materialized views - a secret weapon for high performance analytic...
 
Data Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsData Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database Analytics
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
 
Do You Know The 11g Plan?
Do You Know The 11g Plan?Do You Know The 11g Plan?
Do You Know The 11g Plan?
 
Aorta interpreter Builder 2019
Aorta interpreter Builder 2019Aorta interpreter Builder 2019
Aorta interpreter Builder 2019
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performance
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 

More from Altinity Ltd

Building an Analytic Extension to MySQL with ClickHouse and Open Source.pptx
Building an Analytic Extension to MySQL with ClickHouse and Open Source.pptxBuilding an Analytic Extension to MySQL with ClickHouse and Open Source.pptx
Building an Analytic Extension to MySQL with ClickHouse and Open Source.pptx
Altinity Ltd
 
Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...
Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...
Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...
Altinity Ltd
 
Building an Analytic Extension to MySQL with ClickHouse and Open Source
Building an Analytic Extension to MySQL with ClickHouse and Open SourceBuilding an Analytic Extension to MySQL with ClickHouse and Open Source
Building an Analytic Extension to MySQL with ClickHouse and Open Source
Altinity Ltd
 
Cloud Native Data Warehouses - Intro to ClickHouse on Kubernetes-2021-07.pdf
Cloud Native Data Warehouses - Intro to ClickHouse on Kubernetes-2021-07.pdfCloud Native Data Warehouses - Intro to ClickHouse on Kubernetes-2021-07.pdf
Cloud Native Data Warehouses - Intro to ClickHouse on Kubernetes-2021-07.pdf
Altinity Ltd
 
Building High Performance Apps with Altinity Stable Builds for ClickHouse | A...
Building High Performance Apps with Altinity Stable Builds for ClickHouse | A...Building High Performance Apps with Altinity Stable Builds for ClickHouse | A...
Building High Performance Apps with Altinity Stable Builds for ClickHouse | A...
Altinity Ltd
 
Application Monitoring using Open Source - VictoriaMetrics & Altinity ClickHo...
Application Monitoring using Open Source - VictoriaMetrics & Altinity ClickHo...Application Monitoring using Open Source - VictoriaMetrics & Altinity ClickHo...
Application Monitoring using Open Source - VictoriaMetrics & Altinity ClickHo...
Altinity Ltd
 
Own your ClickHouse data with Altinity.Cloud Anywhere-2023-01-17.pdf
Own your ClickHouse data with Altinity.Cloud Anywhere-2023-01-17.pdfOwn your ClickHouse data with Altinity.Cloud Anywhere-2023-01-17.pdf
Own your ClickHouse data with Altinity.Cloud Anywhere-2023-01-17.pdf
Altinity Ltd
 
ClickHouse ReplacingMergeTree in Telecom Apps
ClickHouse ReplacingMergeTree in Telecom AppsClickHouse ReplacingMergeTree in Telecom Apps
ClickHouse ReplacingMergeTree in Telecom Apps
Altinity Ltd
 
Building a Real-Time Analytics Application with Apache Pulsar and Apache Pinot
Building a Real-Time Analytics Application with  Apache Pulsar and Apache PinotBuilding a Real-Time Analytics Application with  Apache Pulsar and Apache Pinot
Building a Real-Time Analytics Application with Apache Pulsar and Apache Pinot
Altinity Ltd
 
Altinity Webinar: Introduction to Altinity.Cloud-Platform for Real-Time Data.pdf
Altinity Webinar: Introduction to Altinity.Cloud-Platform for Real-Time Data.pdfAltinity Webinar: Introduction to Altinity.Cloud-Platform for Real-Time Data.pdf
Altinity Webinar: Introduction to Altinity.Cloud-Platform for Real-Time Data.pdf
Altinity Ltd
 
OSA Con 2022 - What Data Engineering Can Learn from Frontend Engineering - Pe...
OSA Con 2022 - What Data Engineering Can Learn from Frontend Engineering - Pe...OSA Con 2022 - What Data Engineering Can Learn from Frontend Engineering - Pe...
OSA Con 2022 - What Data Engineering Can Learn from Frontend Engineering - Pe...
Altinity Ltd
 
OSA Con 2022 - Welcome to OSA CON Version 2022 - Robert Hodges - Altinity.pdf
OSA Con 2022 - Welcome to OSA CON Version 2022 - Robert Hodges - Altinity.pdfOSA Con 2022 - Welcome to OSA CON Version 2022 - Robert Hodges - Altinity.pdf
OSA Con 2022 - Welcome to OSA CON Version 2022 - Robert Hodges - Altinity.pdf
Altinity Ltd
 
OSA Con 2022 - Using ClickHouse Database to Power Analytics and Customer Enga...
OSA Con 2022 - Using ClickHouse Database to Power Analytics and Customer Enga...OSA Con 2022 - Using ClickHouse Database to Power Analytics and Customer Enga...
OSA Con 2022 - Using ClickHouse Database to Power Analytics and Customer Enga...
Altinity Ltd
 
OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...
OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...
OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...
Altinity Ltd
 
OSA Con 2022 - The Open Source Analytic Universe, Version 2022 - Robert Hodge...
OSA Con 2022 - The Open Source Analytic Universe, Version 2022 - Robert Hodge...OSA Con 2022 - The Open Source Analytic Universe, Version 2022 - Robert Hodge...
OSA Con 2022 - The Open Source Analytic Universe, Version 2022 - Robert Hodge...
Altinity Ltd
 
OSA Con 2022 - Switching Jaeger Distributed Tracing to ClickHouse to Enable A...
OSA Con 2022 - Switching Jaeger Distributed Tracing to ClickHouse to Enable A...OSA Con 2022 - Switching Jaeger Distributed Tracing to ClickHouse to Enable A...
OSA Con 2022 - Switching Jaeger Distributed Tracing to ClickHouse to Enable A...
Altinity Ltd
 
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...
Altinity Ltd
 
OSA Con 2022 - State of Open Source Databases - Peter Zaitsev - Percona.pdf
OSA Con 2022 - State of Open Source Databases - Peter Zaitsev - Percona.pdfOSA Con 2022 - State of Open Source Databases - Peter Zaitsev - Percona.pdf
OSA Con 2022 - State of Open Source Databases - Peter Zaitsev - Percona.pdf
Altinity Ltd
 
OSA Con 2022 - Specifics of data analysis in Time Series Databases - Roman Kh...
OSA Con 2022 - Specifics of data analysis in Time Series Databases - Roman Kh...OSA Con 2022 - Specifics of data analysis in Time Series Databases - Roman Kh...
OSA Con 2022 - Specifics of data analysis in Time Series Databases - Roman Kh...
Altinity Ltd
 
OSA Con 2022 - Signal Correlation, the Ho11y Grail - Michael Hausenblas - AWS...
OSA Con 2022 - Signal Correlation, the Ho11y Grail - Michael Hausenblas - AWS...OSA Con 2022 - Signal Correlation, the Ho11y Grail - Michael Hausenblas - AWS...
OSA Con 2022 - Signal Correlation, the Ho11y Grail - Michael Hausenblas - AWS...
Altinity Ltd
 

More from Altinity Ltd (20)

Building an Analytic Extension to MySQL with ClickHouse and Open Source.pptx
Building an Analytic Extension to MySQL with ClickHouse and Open Source.pptxBuilding an Analytic Extension to MySQL with ClickHouse and Open Source.pptx
Building an Analytic Extension to MySQL with ClickHouse and Open Source.pptx
 
Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...
Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...
Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...
 
Building an Analytic Extension to MySQL with ClickHouse and Open Source
Building an Analytic Extension to MySQL with ClickHouse and Open SourceBuilding an Analytic Extension to MySQL with ClickHouse and Open Source
Building an Analytic Extension to MySQL with ClickHouse and Open Source
 
Cloud Native Data Warehouses - Intro to ClickHouse on Kubernetes-2021-07.pdf
Cloud Native Data Warehouses - Intro to ClickHouse on Kubernetes-2021-07.pdfCloud Native Data Warehouses - Intro to ClickHouse on Kubernetes-2021-07.pdf
Cloud Native Data Warehouses - Intro to ClickHouse on Kubernetes-2021-07.pdf
 
Building High Performance Apps with Altinity Stable Builds for ClickHouse | A...
Building High Performance Apps with Altinity Stable Builds for ClickHouse | A...Building High Performance Apps with Altinity Stable Builds for ClickHouse | A...
Building High Performance Apps with Altinity Stable Builds for ClickHouse | A...
 
Application Monitoring using Open Source - VictoriaMetrics & Altinity ClickHo...
Application Monitoring using Open Source - VictoriaMetrics & Altinity ClickHo...Application Monitoring using Open Source - VictoriaMetrics & Altinity ClickHo...
Application Monitoring using Open Source - VictoriaMetrics & Altinity ClickHo...
 
Own your ClickHouse data with Altinity.Cloud Anywhere-2023-01-17.pdf
Own your ClickHouse data with Altinity.Cloud Anywhere-2023-01-17.pdfOwn your ClickHouse data with Altinity.Cloud Anywhere-2023-01-17.pdf
Own your ClickHouse data with Altinity.Cloud Anywhere-2023-01-17.pdf
 
ClickHouse ReplacingMergeTree in Telecom Apps
ClickHouse ReplacingMergeTree in Telecom AppsClickHouse ReplacingMergeTree in Telecom Apps
ClickHouse ReplacingMergeTree in Telecom Apps
 
Building a Real-Time Analytics Application with Apache Pulsar and Apache Pinot
Building a Real-Time Analytics Application with  Apache Pulsar and Apache PinotBuilding a Real-Time Analytics Application with  Apache Pulsar and Apache Pinot
Building a Real-Time Analytics Application with Apache Pulsar and Apache Pinot
 
Altinity Webinar: Introduction to Altinity.Cloud-Platform for Real-Time Data.pdf
Altinity Webinar: Introduction to Altinity.Cloud-Platform for Real-Time Data.pdfAltinity Webinar: Introduction to Altinity.Cloud-Platform for Real-Time Data.pdf
Altinity Webinar: Introduction to Altinity.Cloud-Platform for Real-Time Data.pdf
 
OSA Con 2022 - What Data Engineering Can Learn from Frontend Engineering - Pe...
OSA Con 2022 - What Data Engineering Can Learn from Frontend Engineering - Pe...OSA Con 2022 - What Data Engineering Can Learn from Frontend Engineering - Pe...
OSA Con 2022 - What Data Engineering Can Learn from Frontend Engineering - Pe...
 
OSA Con 2022 - Welcome to OSA CON Version 2022 - Robert Hodges - Altinity.pdf
OSA Con 2022 - Welcome to OSA CON Version 2022 - Robert Hodges - Altinity.pdfOSA Con 2022 - Welcome to OSA CON Version 2022 - Robert Hodges - Altinity.pdf
OSA Con 2022 - Welcome to OSA CON Version 2022 - Robert Hodges - Altinity.pdf
 
OSA Con 2022 - Using ClickHouse Database to Power Analytics and Customer Enga...
OSA Con 2022 - Using ClickHouse Database to Power Analytics and Customer Enga...OSA Con 2022 - Using ClickHouse Database to Power Analytics and Customer Enga...
OSA Con 2022 - Using ClickHouse Database to Power Analytics and Customer Enga...
 
OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...
OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...
OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...
 
OSA Con 2022 - The Open Source Analytic Universe, Version 2022 - Robert Hodge...
OSA Con 2022 - The Open Source Analytic Universe, Version 2022 - Robert Hodge...OSA Con 2022 - The Open Source Analytic Universe, Version 2022 - Robert Hodge...
OSA Con 2022 - The Open Source Analytic Universe, Version 2022 - Robert Hodge...
 
OSA Con 2022 - Switching Jaeger Distributed Tracing to ClickHouse to Enable A...
OSA Con 2022 - Switching Jaeger Distributed Tracing to ClickHouse to Enable A...OSA Con 2022 - Switching Jaeger Distributed Tracing to ClickHouse to Enable A...
OSA Con 2022 - Switching Jaeger Distributed Tracing to ClickHouse to Enable A...
 
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...
OSA Con 2022 - Streaming Data Made Easy - Tim Spann & David Kjerrumgaard - St...
 
OSA Con 2022 - State of Open Source Databases - Peter Zaitsev - Percona.pdf
OSA Con 2022 - State of Open Source Databases - Peter Zaitsev - Percona.pdfOSA Con 2022 - State of Open Source Databases - Peter Zaitsev - Percona.pdf
OSA Con 2022 - State of Open Source Databases - Peter Zaitsev - Percona.pdf
 
OSA Con 2022 - Specifics of data analysis in Time Series Databases - Roman Kh...
OSA Con 2022 - Specifics of data analysis in Time Series Databases - Roman Kh...OSA Con 2022 - Specifics of data analysis in Time Series Databases - Roman Kh...
OSA Con 2022 - Specifics of data analysis in Time Series Databases - Roman Kh...
 
OSA Con 2022 - Signal Correlation, the Ho11y Grail - Michael Hausenblas - AWS...
OSA Con 2022 - Signal Correlation, the Ho11y Grail - Michael Hausenblas - AWS...OSA Con 2022 - Signal Correlation, the Ho11y Grail - Michael Hausenblas - AWS...
OSA Con 2022 - Signal Correlation, the Ho11y Grail - Michael Hausenblas - AWS...
 

Recently uploaded

一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
ewymefz
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Linda486226
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
NABLAS株式会社
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
ewymefz
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
Opendatabay
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
Tiktokethiodaily
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Subhajit Sahu
 
FP Growth Algorithm and its Applications
FP Growth Algorithm and its ApplicationsFP Growth Algorithm and its Applications
FP Growth Algorithm and its Applications
MaleehaSheikh2
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
Jpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization SampleJpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization Sample
James Polillo
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
vcaxypu
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
axoqas
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar
 
Tabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflowsTabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflows
alex933524
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
ewymefz
 
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
correoyaya
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 

Recently uploaded (20)

一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
 
FP Growth Algorithm and its Applications
FP Growth Algorithm and its ApplicationsFP Growth Algorithm and its Applications
FP Growth Algorithm and its Applications
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Jpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization SampleJpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization Sample
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
 
Tabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflowsTabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflows
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
 
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 

Fun with ClickHouse Window Functions-2021-08-19.pdf

  • 1. Fun with ClickHouse Window Functions Robert Hodges and Vitaliy Zakaznikov @ Altinity 1
  • 2. Presenter Bios and Altinity Introduction The #1 enterprise ClickHouse provider. Now offering Altinity.Cloud Major committer and community sponsor for ClickHouse in US/EU Robert Hodges - CEO 30+ years on DBMS plus virtualization and security. ClickHouse is DBMS #20 Vitaliy Zakaznikov - QA Manager 13+ years testing hardware and software; author of TestFlows open source testing framework
  • 3. ClickHouse: a great SQL data warehouse Understands SQL Runs on bare metal to cloud Shared nothing architecture Stores data in columns Parallel and vectorized execution Scales to many petabytes Is Open source (Apache 2.0) a b c d a b c d a b c d a b c d And it’s really fast! 3
  • 4. Using the Altinity.Cloud public endpoint 4 https://github.demo.trial.altinity.cloud:8443/play User “demo” Password “demo” clickhouse-client --host=github.demo.trial.altinity.cloud -s --user=demo --password
  • 6. Let’s start with a simple query... SELECT FlightDate, count() AS Flights, sum(Cancelled) AS Sum_Cancelled FROM ontime WHERE toYYYYMM(FlightDate) = 201901 GROUP BY FlightDate ORDER BY FlightDate FlightDate|Flights|Sum_Cancelled| ----------|-------|-------------| 2019-01-01| 18009| 141| 2019-01-02| 20384| 173| 6 Cancelled flights for Jan 2019
  • 7. 7 SQL queries work like “cubes” 7 FlightDate Cancelled 0 -- 1 -- 1/01 1/02 1/03 1/04 1/05 1/06 1/07 1/07 . .. 16807 Flights 129 Cancelled Dimension Metrics (count, sum) Dimension Carrier F l i g h t N u m TailNum (Other dimensions)
  • 8. ...But what happens if we want to... 8 Rank particular days by number of cancelled flights? Print cumulative cancellations for each month? Print trailing 7-day average cancellations? 8 How can I do that in SQL??
  • 9. This is a job for window functions! 9 Set session variable clickhouse101 :) SET allow_experimental_window_functions = 1 SET allow_experimental_window_functions = 1 Query id: f8aec38c-7f31-4544-96df-bcdb4034f0ac Ok. <yandex> <profiles> <default> <allow_experimental_window_functions>1</allow_...tions> . . . </default></profiles></yandex> But first we need to enable them... Set in user profile
  • 10. Window functions add a new option to SQL SELECT FlightDate, count() AS Flights, sum(Cancelled) AS Daily_Cancelled, avg(Daily_Cancelled) OVER (ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS Avg_Cancelled_7 FROM ontime_ref WHERE Year = 2019 GROUP BY FlightDate ORDER BY FlightDate FlightDate|Flights|Daily_Cancelled|Avg_Cancelled_7 | ----------|-------|---------------|------------------| . . . 2019-01-30| 19102| 2145| 805.5714285714286| 2019-01-31| 19962| 1775| 999.0| 2019-02-01| 20045| 459|1037.2857142857142| 10 Window function!
  • 11. How window functions work conceptually SELECT FlightDate, count() AS Flights, sum(Cancelled) AS Daily_Cancelled, avg(Daily_Cancelled) OVER (ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS Avg_Cancelled_7 FROM ontime_ref WHERE Year = 2019 GROUP BY FlightDate ORDER BY FlightDate 11 Operates on the computed aggregate Computes average within a window “frame” of 7 rows Result is another output column
  • 12. Window Functions -- The gory details 21.3 (LTS) - First experimental support 21.8 - Pre-release experimental feature (should be enabled by default soon) 12
  • 13. How do window functions work for users? 13
  • 14. Why do we need “gory details” anyway? 14 ● Empty OVER clause means that there is only one window that includes all the result rows ● When no ORDER BY clause is specified then all rows are the peers of the current row ● The default frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW SELECT number, sum(number) OVER () FROM numbers(1, 5) ┌─number─┬─sum(number) OVER ()─┐ │ 1 │ 15 │ │ 2 │ 15 │ │ 3 │ 15 │ │ 4 │ 15 │ │ 5 │ 15 │ └────────┴─────────────────────┘ Window function behavior is not obvious!
  • 15. What can be a window function? 15 Any aggregate function ● min ● max ● sum ● avg ● etc. SELECT number, min(number) OVER () FROM numbers(1,5) Window native function ● row_number ● first_value ● last_value ● rank ● dense_rank ● leadInFrame ● lagInFrame SELECT number, rank() OVER (ORDER BY number) FROM numbers(1,5)
  • 16. What is an OVER clause? 16 ● Can be empty OVER defines the window specification ● Can contain window specification SELECT number, sum(number) OVER () FROM numbers(1,5) SELECT number, sum(number) OVER (PARTITION BY number) FROM numbers(1,5) ● Can refer to a named window SELECT number, sum(number) OVER w FROM numbers(1,5) WINDOW w AS (PARTITION BY number)
  • 17. What do window specifications look like? 17 ● PARTITION BY clause Defines window partition Window Specification clause [partition_clause] [order_clause] [frame_clause] ● ORDER BY clause Orders rows within a frame SELECT number, sum(number) OVER (PARTITION BY number % 2) FROM numbers(1,5) SELECT number, sum(number) OVER (ORDER BY number) FROM numbers(1,5) ● FRAME clause Defines frame within a window partition SELECT number, sum(number) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM numbers(1,5)
  • 18. What kind of frames are there? 18 ● ROWS frame Defines a frame with the range in terms of relationship of rows to the current row number SELECT number, sum(number) OVER (ORDER BY number ROWS 1 PRECEDING) AS sum FROM numbers(1, 3) ┌─number─┬─sum─┐ │ 1 │ 1 │ │ 2 │ 3 │ │ 3 │ 5 │ └────────┴─────┘ FRAME clause ● RANGE frame Defines a frame with the range in terms of row values from the current row value. SELECT number, sum(number) OVER (ORDER BY number RANGE 1 PRECEDING) AS sum FROM values('number Int8', 1, 2, 2, 4) ┌─number─┬─sum─┐ │ 1 │ 1 │ │ 2 │ 5 │ │ 2 │ 5 │ │ 4 │ 4 │ └────────┴─────┘
  • 19. What are current rows peers? 19 ● With ORDER BY clause SELECT number, sum(number) OVER (ORDER BY number) AS sum FROM values('number Int8', 1, 2, 2, 3, 4, 5) ┌─number─┬─sum─┐ │ 1 │ 1 │ │ 2 │ 5 │ │ 2 │ 5 │ │ 3 │ 8 │ │ 4 │ 12 │ │ 5 │ 17 │ └────────┴─────┘ CURRENT ROW Peers Are rows that fall into the same sort bucket and applies only to RANGE frame. ● No ORDER BY clause SELECT number, sum(number) OVER () AS sum FROM values('number Int8', 1, 2, 2, 3, 4, 5) ┌─number─┬─sum─┐ │ 1 │ 17 │ │ 2 │ 17 │ │ 2 │ 17 │ │ 3 │ 17 │ │ 4 │ 17 │ │ 5 │ 17 │ └────────┴─────┘
  • 20. How do we define the extent of the frame? 20 ● frame START Defines start of the frame with the end being set implicitly to current row (for both ROWS and RANGE frame) SELECT number,sum(number) OVER (ORDER BY number ROWS 1 PRECEDING) AS sum FROM numbers(1,5) is actually SELECT number, sum(number) OVER (ORDER BY number ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS sum FROM numbers(1, 5) FRAME extent clause ● frame BETWEEN Defines a frame with start and end specified explicitly SELECT number,sum(number) OVER (ORDER BY number ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS sum FROM numbers(1,5) is actually the same SELECT number, sum(number) OVER (ORDER BY number ASC ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS sum FROM numbers(1, 5)
  • 21. More on frame extents! 21 ● CURRENT ROW Current row as the frame slides through the window ● UNBOUNDED PRECEDING All rows before current row, if ROWS frame, or first row’s value in window partition, if RANGE frame ● UNBOUNDED FOLLOWING All rows after current row, if ROWS frame, or last row’s value in window partition if RANGE frame FRAME extent clause ● expr PRECEDING Offset in rows before current row, if ROWS frame, or current row value minus expr, if RANGE frame ● expr FOLLOWING Offset in rows before current row, if ROWS frame, or current row value plus expr, if RANGE frame Frame START and frame END offsets can be specified as
  • 22. How do window functions work internally? 22 Apply window functions Fully Aggregate, Sort Scan, Partially Aggregate Scan, Partially Aggregate Scan, Partially Aggregate Data Data Data Result Sequential Sequential Parallel
  • 23. Using Window functions in practice 21.3 (LTS) - First experimental support 21.8 - Pre-release experimental feature 23
  • 24. Computing cumulative monthly cancellations SELECT FlightDate, count() AS Flights, sum(Cancelled) AS Daily_Cancelled, sum(Daily_Cancelled) OVER (PARTITION BY toStartOfMonth(FlightDate) ORDER BY FlightDate) AS Cumul_Cancelled FROM ontime WHERE Year = 2019 GROUP BY FlightDate ORDER BY FlightDate FlightDate|Flights|Daily_Cancelled|Cumul_Cancelled| ----------|-------|---------------|---------------| 2019-01-01| 18009| 141| 141| 2019-01-02| 20384| 173| 314| . . . 24 Group by flight month Order by date of light
  • 25. Rank cancellations by week SELECT FlightDate, count() AS Flights, sum(Cancelled) AS Daily_Cancelled, rank() OVER (PARTITION BY toStartOfWeek(FlightDate) ORDER BY Daily_Cancelled DESC) as Weekly_Rank FROM ontime WHERE Year = 2019 GROUP BY FlightDate ORDER BY FlightDate FlightDate|Flights|Daily_Cancelled|Weekly_Rank| ----------|-------|---------------|-----------| 2019-01-01| 18009| 141| 2| 2019-01-02| 20384| 173| 1| 2019-01-03| 19522| 134| 3| 25 Group by week
  • 26. Multiple ranks for aircraft flights SELECT TailNum, any(Carrier) AS Carrier, count() Flights, rank() OVER (ORDER BY Flights DESC) as Overall_Rank, rank() OVER (PARTITION BY Carrier ORDER BY Flights DESC) as Carrier_Rank FROM ontime WHERE toYYYYMM(FlightDate) = 201901 GROUP BY TailNum ORDER BY Flights DESC TailNum|Carrier|Flights|Overall_Rank|Carrier_Rank| -------|-------|-------|------------|------------| |OH | 2543| 1| 1| N488HA |HA | 361| 2| 1| N481HA |HA | 348| 3| 2| 26
  • 27. Reuse window definitions SELECT FlightDate, count() AS Flights, sum(Cancelled) AS Daily_Cancelled, min(Daily_Cancelled) OVER 7_day as Min_Cancelled_7, avg(Daily_Cancelled) OVER 7_day as Avg_Cancelled_7, max(Daily_Cancelled) OVER 7_day as Max_Cancelled_7 FROM ontime WHERE Year = 2019 GROUP BY FlightDate WINDOW 7_day AS (ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) ORDER BY FlightDate FlightDate|Flights|Daily_Cancelled|Min_Cancelled_7|... ----------|-------|---------------|---------------|... 2019-01-01| 18009| 141| 141|... 2019-01-02| 20384| 173| 141|... 27
  • 28. Are window functions the only way? 28 “Definitely not!”
  • 29. Rank cancellations by week using arrays SELECT FlightDate, Flights, Daily_Cancelled, Weekly_Rank FROM ( SELECT groupArray(FlightDate) AS FlightDate_Arr, groupArray(Flights) AS Flights_Arr, groupArray(Daily_Cancelled) AS Daily_Cancelled_Arr, arrayEnumerate(Daily_Cancelled_Arr) AS Daily_Cancelled_Indexes, arraySort((x, y) -> -y, Daily_Cancelled_Indexes, Daily_Cancelled_Arr) as Rank_Array FROM ( SELECT FlightDate, count() AS Flights, sum(Cancelled) AS Daily_Cancelled FROM ontime WHERE Year = 2019 GROUP BY FlightDate ORDER BY FlightDate ) GROUP BY toStartOfWeek(FlightDate) ORDER BY toStartOfWeek(FlightDate) ) ARRAY JOIN FlightDate_Arr AS FlightDate, Flights_Arr AS Flights, Daily_Cancelled_Arr AS Daily_Cancelled, Rank_Array AS Weekly_Rank ORDER BY FlightDate 29 Sort indexes by descending sum of cancelled flights Unroll arrays again Roll up values by week
  • 31. Not supported or doesn’t work Some features of window functions that are not supported now or don’t work ● RANGE frame only works for UIntX/IntX, Date and DateTime types and is not supported for other data types including Nullable ● No INTERVAL support for Date and DateTime types ● No EXCLUDE clause ● No GROUPS frame ● No lag(value, offset) and lag(value, offset) functions but workaround is documented ● Expressions can’t use window functions ● Can’t use RANGE frame with a named window 31
  • 32. More information on window functions ● ClickHouse window function docs ● Altinity Blog: ClickHouse Window Functions — Current State of the Art ● Altinity Software Requirements Spec: SRS019 ClickHouse Window Functions ● Alinity Knowledge Base, e.g., cumulative sums ● Blog article on Window Functions by TinyBird.co 32
  • 33. 33 And special thanks to: 33 Alexander Kuzmenkov @ Yandex -- Implemented window functions Alexey Milovidov @ Yandex -- ClickHouse lead committer Altinity QA team -- Testing!