Google Cloud Storage
Doris 提供两种方式从 Google Cloud Storage 导入文件:
- 使用 S3 Load 将 Google Cloud Storage 文件导入到 Doris 中,这是一个异步的导入方式。
- 使用 TVF 将 Google Cloud Storage 文件导入到 Doris 中,这是一个同步的导入方式。
使用 S3 Load 导入
使用 S3 Load 导入对象存储上的文件,详细步骤可以参考 Broker Load 手册
第 1 步:准备数据
创建 CSV 文件 s3load_example.csv 文件存储在 Google Cloud Storage 上,其内容如下:
1,Emily,25
2,Benjamin,35
3,Olivia,28
4,Alexander,60
5,Ava,17
6,William,69
7,Sophia,32
8,James,64
9,Emma,37
10,Liam,64
第 2 步:在 Doris 中创建表
CREATE TABLE test_s3load(
user_id BIGINT NOT NULL COMMENT "user id",
name VARCHAR(20) COMMENT "name",
age INT COMMENT "age"
)
DUPLICATE KEY(user_id)
DISTRIBUTED BY HASH(user_id) BUCKETS 10;
第 3 步:使用 S3 Load 导入数据
LOAD LABEL s3_load_2022_04_01
(
DATA INFILE("s3://your_bucket_name/s3load_example.csv")
INTO TABLE test_s3load
COLUMNS TERMINATED BY ","
FORMAT AS "CSV"
(user_id, name, age)
)
WITH S3
(
"provider" = "GCP",
"s3.endpoint" = "storage.us-west2.rep.googleapis.com",
"s3.region" = "US-WEST2",
"s3.access_key" = "AKIAIOSFODNN7EXAMPLE",
"s3.secret_key" = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
)
PROPERTIES
(
"timeout" = "3600"
);
第 4 步:检查导入数据
SELECT * FROM test_s3load;
结果:
mysql> select * from test_s3load;
+---------+-----------+------+
| user_id | name | age |
+---------+-----------+------+
| 5 | Ava | 17 |
| 10 | Liam | 64 |
| 7 | Sophia | 32 |
| 9 | Emma | 37 |
| 1 | Emily | 25 |
| 4 | Alexander | 60 |
| 2 | Benjamin | 35 |
| 3 | Olivia | 28 |
| 6 | William | 69 |
| 8 | James | 64 |
+---------+-----------+------+
10 rows in set (0.04 sec)
使用 TVF 导入
第 1 步:准备数据
创建 CSV 文件 s3load_example.csv 文件存储在 Google Cloud Storage 上,其内容如下:
1,Emily,25
2,Benjamin,35
3,Olivia,28
4,Alexander,60
5,Ava,17
6,William,69
7,Sophia,32
8,James,64
9,Emma,37
10,Liam,64
第 2 步:在 Doris 中创建表
CREATE TABLE test_s3load(
user_id BIGINT NOT NULL COMMENT "user id",
name VARCHAR(20) COMMENT "name",
age INT COMMENT "age"
)
DUPLICATE KEY(user_id)
DISTRIBUTED BY HASH(user_id) BUCKETS 10;
第 3 步:使用 TVF 导入数据
INSERT INTO test_s3load
SELECT * FROM S3
(
"uri" = "s3://your_bucket_name/s3load_example.csv",
"format" = "csv",
"provider" = "GCP",
"s3.endpoint" = "storage.us-west2.rep.googleapis.com",
"s3.region" = "US-WEST2",
"s3.access_key" = "AKIAIOSFODNN7EXAMPLE",
"s3.secret_key" = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"column_separator" = ",",
"csv_schema" = "user_id:int;name:string;age:int"
);
第 4 步:检查导入数据
SELECT * FROM test_s3load;
结果:
mysql> select * from test_s3load;
+---------+-----------+------+
| user_id | name | age |
+---------+-----------+------+
| 5 | Ava | 17 |
| 10 | Liam | 64 |
| 7 | Sophia | 32 |
| 9 | Emma | 37 |
| 1 | Emily | 25 |
| 4 | Alexander | 60 |
| 2 | Benjamin | 35 |
| 3 | Olivia | 28 |
| 6 | William | 69 |
| 8 | James | 64 |
+---------+-----------+------+
10 rows in set (0.04 sec)