S3

Name

s3

description

S3 表函数(table-valued-function,tvf),可以让用户像访问关系表格式数据一样,读取并访问 S3 兼容的对象存储上的文件内容。目前支持csv/csv_with_names/csv_with_names_and_types/json/parquet/orc文件格式。

语法

  1. s3(
  2. "uri" = "..",
  3. "s3.access_key" = "...",
  4. "s3.secret_key" = "...",
  5. "s3.region" = "...",
  6. "s3.endpoint" = "...",
  7. "format" = "csv",
  8. "keyn" = "valuen",
  9. ...
  10. );

参数说明

S3 TVF 中的每一个参数都是一个 "key"="value" 对。 访问 S3 相关参数:

  • uri: (必填) 访问 S3 的 URI,S3 表函数会根据 use_path_style 参数来决定是否使用 Path Style 访问方式,默认为 Virtual-hosted Style 方式
  • s3.access_key: (必填)
  • s3.secret_key: (必填)
  • s3.region: (必填)
  • s3.endpoint: (必填)
  • s3.session_token: (选填)
  • use_path_style:(选填) 默认为false 。S3 SDK 默认使用 Virtual-hosted Syle 方式。但某些对象存储系统可能没开启或没支持 Virtual-hosted Style 方式的访问,此时我们可以添加 use_path_style 参数来强制使用 Path Style 方式。比如 minio 默认情况下只允许 path style 访问方式,所以在访问 MinIO 时要加上 use_path_style=true
  • force_parsing_by_standard_uri:(选填)默认 false 。我们可以添加 force_parsing_by_standard_uri 参数来强制将非标准的 URI 解析为标准 URI。

对于 AWS S3,标准 uri styles 有以下几种:

  1. AWS Client Style(Hadoop S3 Style): s3://my-bucket/path/to/file?versionId=abc123&partNumber=77&partNumber=88
  2. Virtual Host Style:https://my-bucket.s3.us-west-1.amazonaws.com/resources/doc.txt?versionId=abc123&partNumber=77&partNumber=88
  3. Path Style:https://s3.us-west-1.amazonaws.com/my-bucket/resources/doc.txt?versionId=abc123&partNumber=77&partNumber=88

除了支持以上三个标准常见的 URI Styles, 还支持其他一些 URI Styles(也许不常见,但也有可能有):

  1. Virtual Host AWS Client (Hadoop S3) Mixed Style: s3://my-bucket.s3.us-west-1.amazonaws.com/resources/doc.txt?versionId=abc123&partNumber=77&partNumber=88
  2. Path AWS Client (Hadoop S3) Mixed Style: s3://s3.us-west-1.amazonaws.com/my-bucket/resources/doc.txt?versionId=abc123&partNumber=77&partNumber=88

详细使用案例可以参考最下方 Best Practice。

文件格式参数:

  • format:(必填) 目前支持 csv/csv_with_names/csv_with_names_and_types/json/parquet/orc
  • column_separator:(选填) 列分割符,默认为\t
  • line_delimiter:(选填) 行分割符,默认为\n
  • compress_type: (选填) 目前支持 UNKNOWN/PLAIN/GZ/LZO/BZ2/LZ4FRAME/DEFLATE/SNAPPYBLOCK。默认值为 UNKNOWN, 将会根据 uri 的后缀自动推断类型。

下面 6 个参数是用于 JSON 格式的导入,具体使用方法可以参照:Json Load

  • read_json_by_line: (选填) 默认为 "true"
  • strip_outer_array: (选填) 默认为 "false"
  • json_root: (选填) 默认为空
  • jsonpaths: (选填) 默认为空
  • num_as_string: (选填) 默认为 false
  • fuzzy_parse: (选填) 默认为 false

下面 2 个参数是用于 CSV 格式的导入

  • trim_double_quotes:布尔类型,选填,默认值为 false,为 true 时表示裁剪掉 CSV 文件每个字段最外层的双引号
  • skip_lines:整数类型,选填,默认值为 0,含义为跳过 CSV 文件的前几行。当设置 format 设置为 csv_with_namescsv_with_names_and_types 时,该参数会失效

其他参数:

  • path_partition_keys:(选填)指定文件路径中携带的分区列名,例如 /path/to/city=beijing/date="2023-07-09", 则填写 path_partition_keys="city,date",将会自动从路径中读取相应列名和列值进行导入。
  • resource:(选填)指定 Resource 名,S3 TVF 可以利用已有的 S3 Resource 来直接访问 S3。创建 S3 Resource 的方法可以参照 CREATE-RESOURCE。该功能自 2.1.4 版本开始支持。

S3 - 图1注意

直接查询 TVF 或基于该 TVF 创建 View ,需要拥有该 Resource 的 USAGE 权限,查询基于 TVF 创建的 View ,只需要该 View 的 SELECT 权限。

Example

读取并访问 S3 兼容的对象存储上的 CSV 格式文件

  1. select * from s3("uri" = "http://127.0.0.1:9312/test2/student1.csv",
  2. "s3.access_key"= "minioadmin",
  3. "s3.secret_key" = "minioadmin",
  4. "s3.endpoint" = "http://127.0.0.1:9312",
  5. "s3.region" = "us-east-1",
  6. "format" = "csv",
  7. "use_path_style" = "true") order by c1;

可以配合 desc function 使用

  1. MySQL [(none)]> Desc function s3("uri" = "http://127.0.0.1:9312/test2/student1.csv",
  2. "s3.access_key"= "minioadmin",
  3. "s3.secret_key" = "minioadmin",
  4. "s3.endpoint" = "http://127.0.0.1:9312",
  5. "s3.region" = "us-east-1",
  6. "format" = "csv",
  7. "use_path_style" = "true");

Keywords

  1. S3, table-valued-function, TVF

Best Practice

不同 url schema 的写法 http:// 、https:// 使用示例:

  1. // 注意URI Bucket写法以及`use_path_style`参数设置,HTTP 同理。
  2. // 由于设置了 `"use_path_style"="true"`, 所以将采用 Path Style 的方式访问 S3。
  3. select * from s3(
  4. "uri" = "https://endpoint/bucket/file/student.csv",
  5. "s3.access_key"= "ak",
  6. "s3.secret_key" = "sk",
  7. "s3.endpoint" = "endpoint",
  8. "s3.region" = "region",
  9. "format" = "csv",
  10. "use_path_style"="true");
  11. // 注意 URI Bucket写法以及use_path_style参数设置,http同理。
  12. // 由于设置了 `"use_path_style"="false"`, 所以将采用 Virtual-hosted Style 方式访问 S3。
  13. select * from s3(
  14. "uri" = "https://bucket.endpoint/bucket/file/student.csv",
  15. "s3.access_key"= "ak",
  16. "s3.secret_key" = "sk",
  17. "s3.endpoint" = "endpoint",
  18. "s3.region" = "region",
  19. "format" = "csv",
  20. "use_path_style"="false");
  21. // 阿里云 OSS 和腾讯云 COS 采用 Virtual-hosted Style 方式访问 S3。
  22. // OSS
  23. select * from s3(
  24. "uri" = "http://example-bucket.oss-cn-beijing.aliyuncs.com/your-folder/file.parquet",
  25. "s3.access_key"= "ak",
  26. "s3.secret_key" = "sk",
  27. "s3.endpoint" = "oss-cn-beijing.aliyuncs.com",
  28. "s3.region" = "oss-cn-beijing",
  29. "format" = "parquet",
  30. "use_path_style" = "false");
  31. // COS
  32. select * from s3(
  33. "uri" = "https://example-bucket.cos.ap-hongkong.myqcloud.com/your-folder/file.parquet",
  34. "s3.access_key"= "ak",
  35. "s3.secret_key" = "sk",
  36. "s3.endpoint" = "cos.ap-hongkong.myqcloud.com",
  37. "s3.region" = "ap-hongkong",
  38. "format" = "parquet",
  39. "use_path_style" = "false");
  40. // MinIO
  41. select * from s3(
  42. "uri" = "s3://bucket/file.csv",
  43. "s3.endpoint" = "http://172.21.0.101:9000",
  44. "s3.access_key"= "ak",
  45. "s3.secret_key" = "sk",
  46. "s3.region" = "us-east-1",
  47. "format" = "csv"
  48. );
  49. // 百度云 BOS 采用兼容 S3 协议的 Virtual-hosted Style 方式访问 S3。
  50. // BOS
  51. select * from s3(
  52. "uri" = "https://example-bucket.s3.bj.bcebos.com/your-folder/file.parquet",
  53. "s3.access_key"= "ak",
  54. "s3.secret_key" = "sk",
  55. "s3.region" = "bj",
  56. "s3.endpoint" = "http://bj.bcebos.com",
  57. "format" = "parquet",
  58. "use_path_style" = "false");

s3:// 使用示例:

  1. // 注意 URI Bucket 写法, 无需设置 `use_path_style` 参数。
  2. // 将采用 Virtual-hosted Style 方式访问 S3。
  3. select * from s3(
  4. "uri" = "s3://bucket/file/student.csv",
  5. "s3.endpoint"= "endpont",
  6. "s3.region"= "region",
  7. "s3.access_key"= "ak",
  8. "s3.secret_key" = "sk",
  9. "format" = "csv");

其它支持的 URI 风格示例:

  1. // Virtual Host AWS Client (Hadoop S3) Mixed Style。通过设置 `use_path_style = false` 以及 `force_parsing_by_standard_uri = true` 来使用。
  2. select * from s3(
  3. "URI" = "s3://my-bucket.s3.us-west-1.amazonaws.com/resources/doc.txt?versionId=abc123&partNumber=77&partNumber=88",
  4. "s3.access_key"= "ak",
  5. "s3.secret_key" = "sk",
  6. "s3.endpoint"= "endpont",
  7. "s3.region"= "region",
  8. "format" = "csv",
  9. "use_path_style"="false",
  10. "force_parsing_by_standard_uri"="true");
  11. // Path AWS Client (Hadoop S3) Mixed Style。通过设置 `use_path_style = true` 以及 `force_parsing_by_standard_uri = true` 来使用。
  12. select * from s3(
  13. "URI" = "s3://s3.us-west-1.amazonaws.com/my-bucket/resources/doc.txt?versionId=abc123&partNumber=77&partNumber=88",
  14. "s3.access_key"= "ak",
  15. "s3.secret_key" = "sk",
  16. "s3.endpoint"= "endpont",
  17. "s3.region"= "region",
  18. "format" = "csv",
  19. "use_path_style"="true",
  20. "force_parsing_by_standard_uri"="true");

CSV format 由于 S3 table-valued-function 事先并不知道 Table Schema,所以会先读一遍文件来解析出 Table Schema。

csv 格式:S3 table-valued-function 读取 S3 上的文件并当作 CSV 文件来处理,读取文件中的第一行用于解析 Table Schema。文件第一行的列个数 n 将作为 Table Schema 的列个数,Table Schema 的列名则自动取名为 c1, c2, ..., cn ,列类型都设置为 String, 举例:

student1.csv 文件内容为:

  1. 1,ftw,12
  2. 2,zs,18
  3. 3,ww,20

使用 S3 TVF

  1. MySQL [(none)]> select * from s3("uri" = "http://127.0.0.1:9312/test2/student1.csv",
  2. -> "s3.access_key"= "minioadmin",
  3. -> "s3.secret_key" = "minioadmin",
  4. -> "s3.endpoint" = "http://127.0.0.1:9312",
  5. -> "s3.region" = "us-east-1",
  6. -> "format" = "csv",
  7. -> "use_path_style" = "true") order by c1;
  8. +------+------+------+
  9. | c1 | c2 | c3 |
  10. +------+------+------+
  11. | 1 | ftw | 12 |
  12. | 2 | zs | 18 |
  13. | 3 | ww | 20 |
  14. +------+------+------+

可以配合 desc function S3() 来查看 Table Schema

  1. MySQL [(none)]> Desc function s3("uri" = "http://127.0.0.1:9312/test2/student1.csv",
  2. -> "s3.access_key"= "minioadmin",
  3. -> "s3.secret_key" = "minioadmin",
  4. -> "s3.endpoint" = "http://127.0.0.1:9312",
  5. -> "s3.region" = "us-east-1",
  6. -> "format" = "csv",
  7. -> "use_path_style" = "true");
  8. +-------+------+------+-------+---------+-------+
  9. | Field | Type | Null | Key | Default | Extra |
  10. +-------+------+------+-------+---------+-------+
  11. | c1 | TEXT | Yes | false | NULL | NONE |
  12. | c2 | TEXT | Yes | false | NULL | NONE |
  13. | c3 | TEXT | Yes | false | NULL | NONE |
  14. +-------+------+------+-------+---------+-------+

csv_with_names format csv_with_names 格式:解析文件的第一行作为 Table Schema 的列个数和列名,列类型则都设置为 String, 举例:

student_with_names.csv 文件内容为

  1. id,name,age
  2. 1,ftw,12
  3. 2,zs,18
  4. 3,ww,20

使用 S3 tvf

  1. MySQL [(none)]> select * from s3("uri" = "http://127.0.0.1:9312/test2/student_with_names.csv",
  2. -> "s3.access_key"= "minioadmin",
  3. -> "s3.secret_key" = "minioadmin",
  4. -> "s3.endpoint" = "http://127.0.0.1:9312",
  5. -> "s3.region" = "us-east-1",
  6. -> "format" = "csv_with_names",
  7. -> "use_path_style" = "true") order by id;
  8. +------+------+------+
  9. | id | name | age |
  10. +------+------+------+
  11. | 1 | ftw | 12 |
  12. | 2 | zs | 18 |
  13. | 3 | ww | 20 |
  14. +------+------+------+

同样配合 desc function S3() 可查看 Table Schema

  1. MySQL [(none)]> Desc function s3("uri" = "http://127.0.0.1:9312/test2/student_with_names.csv",
  2. -> "s3.access_key"= "minioadmin",
  3. -> "s3.secret_key" = "minioadmin",
  4. -> "s3.endpoint" = "http://127.0.0.1:9312",
  5. -> "s3.region" = "us-east-1",
  6. -> "format" = "csv_with_names",
  7. -> "use_path_style" = "true");
  8. +-------+------+------+-------+---------+-------+
  9. | Field | Type | Null | Key | Default | Extra |
  10. +-------+------+------+-------+---------+-------+
  11. | id | TEXT | Yes | false | NULL | NONE |
  12. | name | TEXT | Yes | false | NULL | NONE |
  13. | age | TEXT | Yes | false | NULL | NONE |
  14. +-------+------+------+-------+---------+-------+

csv_with_names_and_types foramt

csv_with_names_and_types 格式:目前暂不支持从 CSV 文件中解析出 Column Type。使用该 Format 时,S3 TVF 会解析文件的第一行作为 Table Schema 的列个数和列名,列类型则都设置为 String,同时将忽略该文件的第二行。

student_with_names_and_types.csv 文件内容为

  1. id,name,age
  2. INT,STRING,INT
  3. 1,ftw,12
  4. 2,zs,18
  5. 3,ww,20

使用 S3 TVF

  1. MySQL [(none)]> select * from s3("uri" = "http://127.0.0.1:9312/test2/student_with_names_and_types.csv",
  2. -> "s3.access_key"= "minioadmin",
  3. -> "s3.secret_key" = "minioadmin",
  4. -> "s3.endpoint" = "http://127.0.0.1:9312",
  5. -> "s3.region" = "us-east-1",
  6. -> "format" = "csv_with_names_and_types",
  7. -> "use_path_style" = "true") order by id;
  8. +------+------+------+
  9. | id | name | age |
  10. +------+------+------+
  11. | 1 | ftw | 12 |
  12. | 2 | zs | 18 |
  13. | 3 | ww | 20 |
  14. +------+------+------+

同样配合 desc function S3() 可查看 Table Schema

  1. MySQL [(none)]> Desc function s3("uri" = "http://127.0.0.1:9312/test2/student_with_names_and_types.csv",
  2. -> "s3.access_key"= "minioadmin",
  3. -> "s3.secret_key" = "minioadmin",
  4. -> "s3.endpoint" = "http://127.0.0.1:9312",
  5. -> "s3.region" = "us-east-1",
  6. -> "format" = "csv_with_names_and_types",
  7. -> "use_path_style" = "true");
  8. +-------+------+------+-------+---------+-------+
  9. | Field | Type | Null | Key | Default | Extra |
  10. +-------+------+------+-------+---------+-------+
  11. | id | TEXT | Yes | false | NULL | NONE |
  12. | name | TEXT | Yes | false | NULL | NONE |
  13. | age | TEXT | Yes | false | NULL | NONE |
  14. +-------+------+------+-------+---------+-------+

JSON format

json 格式:JSON 格式涉及到较多的可选参数,各个参数的意义可以参考:Json Load。S3 TVF 查询 JSON 格式文件时根据 json_rootjsonpaths 参数定位到一个 JSON 对象,将该对象的中的 key 作为 Table Schema 的列名,列类型都设置为 String。举例:

data.json 文件

  1. [{"id":1, "name":"ftw", "age":18}]
  2. [{"id":2, "name":"xxx", "age":17}]
  3. [{"id":3, "name":"yyy", "age":19}]

使用 S3 TVF 查询

  1. MySQL [(none)]> select * from s3(
  2. "uri" = "http://127.0.0.1:9312/test2/data.json",
  3. "s3.access_key"= "minioadmin",
  4. "s3.secret_key" = "minioadmin",
  5. "s3.endpoint" = "http://127.0.0.1:9312",
  6. "s3.region" = "us-east-1",
  7. "format" = "json",
  8. "strip_outer_array" = "true",
  9. "read_json_by_line" = "true",
  10. "use_path_style"="true");
  11. +------+------+------+
  12. | id | name | age |
  13. +------+------+------+
  14. | 1 | ftw | 18 |
  15. | 2 | xxx | 17 |
  16. | 3 | yyy | 19 |
  17. +------+------+------+
  18. MySQL [(none)]> select * from s3(
  19. "uri" = "http://127.0.0.1:9312/test2/data.json",
  20. "s3.access_key"= "minioadmin",
  21. "s3.secret_key" = "minioadmin",
  22. "s3.endpoint" = "http://127.0.0.1:9312",
  23. "s3.region" = "us-east-1",
  24. "format" = "json",
  25. "strip_outer_array" = "true",
  26. "jsonpaths" = "[\"$.id\", \"$.age\"]",
  27. "use_path_style"="true");
  28. +------+------+
  29. | id | age |
  30. +------+------+
  31. | 1 | 18 |
  32. | 2 | 17 |
  33. | 3 | 19 |
  34. +------+------+

Parquet format

parquet 格式:S3 TVF 支持从 Parquet 文件中解析出 Table Schema 的列名、列类型。举例:

  1. MySQL [(none)]> select * from s3(
  2. "uri" = "http://127.0.0.1:9312/test2/test.snappy.parquet",
  3. "s3.access_key"= "minioadmin",
  4. "s3.secret_key" = "minioadmin",
  5. "s3.endpoint" = "http://127.0.0.1:9312",
  6. "s3.region" = "us-east-1",
  7. "format" = "parquet",
  8. "use_path_style"="true") limit 5;
  9. +-----------+------------------------------------------+----------------+----------+-------------------------+--------+-------------+---------------+---------------------+
  10. | p_partkey | p_name | p_mfgr | p_brand | p_type | p_size | p_container | p_retailprice | p_comment |
  11. +-----------+------------------------------------------+----------------+----------+-------------------------+--------+-------------+---------------+---------------------+
  12. | 1 | goldenrod lavender spring chocolate lace | Manufacturer#1 | Brand#13 | PROMO BURNISHED COPPER | 7 | JUMBO PKG | 901 | ly. slyly ironi |
  13. | 2 | blush thistle blue yellow saddle | Manufacturer#1 | Brand#13 | LARGE BRUSHED BRASS | 1 | LG CASE | 902 | lar accounts amo |
  14. | 3 | spring green yellow purple cornsilk | Manufacturer#4 | Brand#42 | STANDARD POLISHED BRASS | 21 | WRAP CASE | 903 | egular deposits hag |
  15. | 4 | cornflower chocolate smoke green pink | Manufacturer#3 | Brand#34 | SMALL PLATED BRASS | 14 | MED DRUM | 904 | p furiously r |
  16. | 5 | forest brown coral puff cream | Manufacturer#3 | Brand#32 | STANDARD POLISHED TIN | 15 | SM PKG | 905 | wake carefully |
  17. +-----------+------------------------------------------+----------------+----------+-------------------------+--------+-------------+---------------+---------------------+
  1. MySQL [(none)]> desc function s3(
  2. "uri" = "http://127.0.0.1:9312/test2/test.snappy.parquet",
  3. "s3.access_key"= "minioadmin",
  4. "s3.secret_key" = "minioadmin",
  5. "s3.endpoint" = "http://127.0.0.1:9312",
  6. "s3.region" = "us-east-1",
  7. "format" = "parquet",
  8. "use_path_style"="true");
  9. +---------------+--------------+------+-------+---------+-------+
  10. | Field | Type | Null | Key | Default | Extra |
  11. +---------------+--------------+------+-------+---------+-------+
  12. | p_partkey | INT | Yes | false | NULL | NONE |
  13. | p_name | TEXT | Yes | false | NULL | NONE |
  14. | p_mfgr | TEXT | Yes | false | NULL | NONE |
  15. | p_brand | TEXT | Yes | false | NULL | NONE |
  16. | p_type | TEXT | Yes | false | NULL | NONE |
  17. | p_size | INT | Yes | false | NULL | NONE |
  18. | p_container | TEXT | Yes | false | NULL | NONE |
  19. | p_retailprice | DECIMAL(9,0) | Yes | false | NULL | NONE |
  20. | p_comment | TEXT | Yes | false | NULL | NONE |
  21. +---------------+--------------+------+-------+---------+-------+

orc format

orc 格式:和 parquet format 使用方法一致,将 format 参数设置为 orc

  1. MySQL [(none)]> select * from s3(
  2. "uri" = "http://127.0.0.1:9312/test2/test.snappy.orc",
  3. "s3.access_key"= "minioadmin",
  4. "s3.secret_key" = "minioadmin",
  5. "s3.endpoint" = "http://127.0.0.1:9312",
  6. "s3.region" = "us-east-1",
  7. "format" = "orc",
  8. "use_path_style"="true") limit 5;
  9. +-----------+------------------------------------------+----------------+----------+-------------------------+--------+-------------+---------------+---------------------+
  10. | p_partkey | p_name | p_mfgr | p_brand | p_type | p_size | p_container | p_retailprice | p_comment |
  11. +-----------+------------------------------------------+----------------+----------+-------------------------+--------+-------------+---------------+---------------------+
  12. | 1 | goldenrod lavender spring chocolate lace | Manufacturer#1 | Brand#13 | PROMO BURNISHED COPPER | 7 | JUMBO PKG | 901 | ly. slyly ironi |
  13. | 2 | blush thistle blue yellow saddle | Manufacturer#1 | Brand#13 | LARGE BRUSHED BRASS | 1 | LG CASE | 902 | lar accounts amo |
  14. | 3 | spring green yellow purple cornsilk | Manufacturer#4 | Brand#42 | STANDARD POLISHED BRASS | 21 | WRAP CASE | 903 | egular deposits hag |
  15. | 4 | cornflower chocolate smoke green pink | Manufacturer#3 | Brand#34 | SMALL PLATED BRASS | 14 | MED DRUM | 904 | p furiously r |
  16. | 5 | forest brown coral puff cream | Manufacturer#3 | Brand#32 | STANDARD POLISHED TIN | 15 | SM PKG | 905 | wake carefully |
  17. +-----------+------------------------------------------+----------------+----------+-------------------------+--------+-------------+---------------+---------------------+

avro format

avro 格式:S3 TVF 支持从 avro 文件中解析出 Table Schema 的列名、列类型。举例:

  1. select * from s3(
  2. "uri" = "http://127.0.0.1:9312/test2/person.avro",
  3. "ACCESS_KEY" = "ak",
  4. "SECRET_KEY" = "sk",
  5. "s3.endpoint" = "http://127.0.0.1:9312",
  6. "s3.region" = "us-east-1",
  7. "FORMAT" = "avro");
  8. +--------+--------------+-------------+-----------------+
  9. | name | boolean_type | double_type | long_type |
  10. +--------+--------------+-------------+-----------------+
  11. | Alyssa | 1 | 10.0012 | 100000000221133 |
  12. | Ben | 0 | 5555.999 | 4009990000 |
  13. | lisi | 0 | 5992225.999 | 9099933330 |
  14. +--------+--------------+-------------+-----------------+

URI 包含通配符

URI 可以使用通配符来读取多个文件。注意:如果使用通配符要保证各个文件的格式是一致的 (尤其是 csv/csv_with_names/csv_with_names_and_types 算做不同的格式),S3 TVF 用第一个文件来解析出 Table Schema。 如下两个 CSV 文件:

  1. // file1.csv
  2. 1,aaa,18
  3. 2,qqq,20
  4. 3,qwe,19
  5. // file2.csv
  6. 5,cyx,19
  7. 6,ftw,21

可以在 URI 上使用通配符来导入。

  1. MySQL [(none)]> select * from s3(
  2. "uri" = "http://127.0.0.1:9312/test2/file*.csv",
  3. "s3.access_key"= "minioadmin",
  4. "s3.secret_key" = "minioadmin",
  5. "s3.endpoint" = "http://127.0.0.1:9312",
  6. "s3.region" = "us-east-1",
  7. "format" = "csv",
  8. "use_path_style"="true");
  9. +------+------+------+
  10. | c1 | c2 | c3 |
  11. +------+------+------+
  12. | 1 | aaa | 18 |
  13. | 2 | qqq | 20 |
  14. | 3 | qwe | 19 |
  15. | 5 | cyx | 19 |
  16. | 6 | ftw | 21 |
  17. +------+------+------+

配合 insert intocast 使用 S3 TVF

  1. // 创建 Doris 内部表
  2. CREATE TABLE IF NOT EXISTS ${testTable}
  3. (
  4. id int,
  5. name varchar(50),
  6. age int
  7. )
  8. COMMENT "my first table"
  9. DISTRIBUTED BY HASH(id) BUCKETS 32
  10. PROPERTIES("replication_num" = "1");
  11. // 使用 S3 插入数据
  12. insert into ${testTable} (id,name,age)
  13. select cast (id as INT) as id, name, cast (age as INT) as age
  14. from s3(
  15. "uri" = "${uri}",
  16. "s3.access_key"= "${ak}",
  17. "s3.secret_key" = "${sk}",
  18. "s3.endpoint" = "http://127.0.0.1:9312",
  19. "s3.region" = "us-east-1",
  20. "format" = "${format}",
  21. "strip_outer_array" = "true",
  22. "read_json_by_line" = "true",
  23. "use_path_style" = "true");