Getting Data Into ClickHouse - Part 3 - Using S3

Dale McDiarmid & Tom Schreiber
24 min readbeginner
--
View Original

Overview

This article is the third part of a series on loading data into ClickHouse, focusing on utilizing Amazon S3 as a data source. It explores querying forex data stored in S3 and demonstrates how to optimize performance for real-time analytics using ClickHouse's capabilities.

What You'll Learn

1

How to query forex data directly from Amazon S3 using ClickHouse

2

Why using ClickHouse for real-time analytics improves performance

3

How to insert data from S3 into ClickHouse for optimized querying

Prerequisites & Requirements

  • Basic understanding of forex trading concepts(optional)
  • Familiarity with ClickHouse and Amazon S3

Key Questions Answered

How can I query data stored in Amazon S3 using ClickHouse?
You can query data in Amazon S3 using ClickHouse by utilizing the S3 table function. This allows you to run SQL queries directly on the data stored in S3 without needing to load it into ClickHouse first, which is ideal for infrequently accessed datasets.
What are the benefits of using ClickHouse for real-time analytics?
ClickHouse offers high performance for real-time analytics due to its ability to efficiently compress data and utilize parallel processing. This results in significantly faster query times compared to querying raw data directly from S3.
What is the structure of the forex dataset used in ClickHouse?
The forex dataset consists of approximately 11.5 billion rows and includes columns for datetime, bid, ask, base, and quote currencies. It spans from May 2000 to August 2022, with a total size of nearly 600GB when decompressed.

Key Statistics & Figures

Total number of rows in forex dataset
11.5 billion
The dataset covers forex ticks from May 2000 to August 2022.
Size of the dataset when decompressed
600GB
This is the total size of the forex dataset, which includes 66 currency pairs.
Query performance for processing rows
51.14 million rows/s.
This performance was achieved when querying the forex dataset using the s3Cluster function.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Database
Clickhouse
Used for querying and analyzing forex data stored in Amazon S3.
Storage
Amazon S3
Serves as the data lake for storing forex datasets.

Key Actionable Insights

1
Utilize ClickHouse's S3 table function for ad-hoc queries on infrequently accessed datasets to save on storage costs.
This approach allows you to analyze data without the need to load it into ClickHouse, making it cost-effective for datasets that do not require frequent access.
2
Leverage the parallel processing capabilities of ClickHouse to optimize query performance when analyzing large datasets.
By adjusting settings like max_download_threads, you can significantly reduce query times, especially when dealing with large volumes of data.
3
Consider inserting frequently accessed data into ClickHouse for improved query performance and analytics.
While querying directly from S3 is useful, inserting data into ClickHouse can lead to faster query execution times, making it a better option for real-time analytics.

Common Pitfalls

1
Failing to optimize query settings can lead to slower performance when querying large datasets.
It's important to adjust parameters like max_download_threads and max_insert_threads to leverage ClickHouse's parallel processing capabilities effectively.
2
Not understanding the structure of the dataset can result in inefficient queries.
Familiarity with the dataset's schema is crucial for writing effective queries that utilize ClickHouse's strengths.

Related Concepts

Data Lakes
Real-time Analytics
Performance Optimization Techniques