ClickHouse - Query files stored in OVHcloud Object Storage
Find out how to read, write and join Parquet or CSV files stored in OVHcloud Object Storage from a ClickHouse cluster, without exposing your S3 credentials
Objective
ClickHouse can query files stored in an S31-compatible bucket without loading them first: you can read them, write query results to them, join them with your tables or load them into a table. Your data stays in your own OVHcloud Object Storage bucket.
This guide explains how to query files stored in OVHcloud Object Storage from a Public Cloud Analytics with ClickHouse cluster, and how to give other users access to these files without sharing your S3 credentials.
Requirements
- A Public Cloud project in your OVHcloud account.
- A ClickHouse cluster running on OVHcloud Public Cloud and accepting incoming connections. See How to create a ClickHouse cluster and How to connect to a ClickHouse cluster.
- The password of the
avnadminuser of the cluster, or of a user with the privileges described in this guide. - An OVHcloud Object Storage bucket and an S3 user with read and write access to it, with its access key and secret key. See Object Storage - Getting started and Object Storage - Identity and access management.
Instructions
The examples in this guide are SQL queries. You can run them with clickhouse-client or over HTTPS, as described in How to connect to a ClickHouse cluster.
Step 1 - Building the URL of your files
ClickHouse addresses a file with the URL of the bucket endpoint, followed by the bucket name and the path of the file (path-style URL):
<region>is the region of your bucket in lowercase, for examplegraoreu-west-par. The endpoint of each region is listed in Object Storage - Endpoints and geoavailability.<bucket>is the name of your bucket.<path>/<file>is the key of the object, for examplesales/2026/orders.parquet.
The URL must start with https://. Without it, ClickHouse returns the error Host is empty in S3 URI.
Step 2 - Storing your S3 credentials in a named collection
You could write your access key and secret key in each query, but they would then appear in your scripts and in the query history. Store them once in a named collection instead: ClickHouse keeps them encrypted and never displays them.
Connected as avnadmin, run:
The values are hidden when you list the named collections:
In the next steps, filename is the path of the file relative to the url of the collection.
A named collection that is used by a table cannot be dropped. Drop or modify the table first.
Step 3 - Reading files
Read a Parquet file with the s3 table function:
The structure of Parquet files is detected automatically.
The s3 table function also accepts the full URL of the file, the access key, the secret key and the format. For CSV files with a header line, use the CSVWithNames format:
To read several files at once, use a wildcard (*) in the path. The virtual column _file gives the name of the file each row comes from:
Step 4 - Creating a table on your files
To query the same files regularly, create a table with the S3 engine. The data stays in your bucket and is read at each query:
Step 5 - Joining files with your tables, or loading them
You can join files with the tables of your cluster in the same query:
To load the content of files into a table of your cluster, use INSERT … SELECT:
Step 6 - Exporting query results to your bucket
Write the result of a query to a file with INSERT INTO FUNCTION:
To replace an existing file, add SETTINGS s3_truncate_on_insert = 1 at the end of the query.
Step 7 - Giving other users access to the files
Connected as avnadmin, grant other users the rights they need with SQL. For a user who only reads the files through the ovh_bucket named collection, without knowing the S3 credentials:
READ ON S3allows reading from S3.NAMED COLLECTION ON ovh_bucketallows using the named collection, without seeing its values.CREATE TEMPORARY TABLEis required to use thes3table function.SELECTon the database is required to query tables created with theS3engine.
Troubleshooting
Go further
- ClickHouse documentation - s3 table function
- ClickHouse documentation - S3 table engine
- ClickHouse documentation - Named collections
- Capabilities and Limitations of Public Cloud Analytics with ClickHouse
We would love to help answer questions and appreciate any feedback you may have.
For training or technical assistance implementing our solutions, contact your sales representative or visit our Professional Services page to request a quote and have your project analysed by our experts.
Are you on Discord? Connect to our channel at https://discord.gg/ovhcloud and interact directly with the team that builds our Analytics service!
Join our community of users.
1: S3 is a trademark of Amazon Technologies, Inc. OVHcloud's service is not sponsored by, endorsed by, or otherwise affiliated with Amazon Technologies, Inc.