我想导出数据,并将 S3 存储桶中的路径分隔为如下结构
- 2022
- 1
- 2
- ...
- 12
- 2021
- 1
- 2
- ...
- 12
等等…
答案
考虑 ClickHouse 表
CREATE TABLE sample_data (
`name` String,
`age` Int,
`time` DateTime
) ENGINE = MergeTree
ORDER BY
name
添加 10000 条条目
INSERT INTO
sample_data
SELECT
*
FROM
generateRandom(
'name String, age Int, time DateTime',
10,
10,
10
)
LIMIT
10000;
运行此命令以在 s3 存储桶 my_bucket
中创建所需的结构(请注意,此示例以 parquet 格式写入文件)
INSERT INTO
FUNCTION s3(
'https://s3-host:4321/my_bucket/{_partition_id}/file.parquet.gz',
's3-access-key',
's3-secret-access-key',
Parquet,
'name String, age Int, time DateTime'
) PARTITION BY concat(
formatDateTime(time, '%Y'),
'/',
formatDateTime(time, '%m')
)
SELECT
name,
age,
time
FROM
sample_data
Query id: 55adcf22-f6af-491e-b697-d09694bbcc56
Ok.
0 rows in set. Elapsed: 15.579 sec. Processed 10.00 thousand rows, 219.93 KB (641.87 rows/s., 14.12 KB/s.)