GoogleSheets
GoogleSheets 源连接器
描述
用于通过 Google Sheets API 从 Google 表格中读取数据。连接器使用 Google Cloud 服务账号凭据读取指定 范围内的内容,并根据用户定义的 schema 把每一行转换为 SeaTunnel 记录。
支持的引擎
Spark
Flink
SeaTunnel Zeta
关键特性
数据类型映射
Google Sheets API 不会返回单元格本身的数据类型 —— 每个单元格读取的都是一个无类型的原始值。连接器
会按照用户声明的 schema 选项对单元格进行类型转换,因此最终输出的 SeaTunnel 类型完全由 schema 决定,
与表格中单元格的原生类型无关。单元格值无法转换为目标 schema 类型时,对应行会失败。
| Google Sheets 单元格 | SeaTunnel 数据类型(按 schema 转换后) |
|---|---|
| string | string / 数值 / boolean / 日期 |
| number | int / long / float / double |
| boolean | boolean |
| date | date / time / timestamp |
源选项
| 名称 | 类型 | 必需 | 默认值 | 描述 |
|---|---|---|---|---|
| service_account_key | string | 是 | - | Google Cloud 服务账号凭据,必须使用 Base64 编码后的 JSON 字符串。 |
| sheet_id | string | 是 | - | Google 表格的 id,即表格 URL 中 /d/ 与 /edit 之间的长字符串。 |
| sheet_name | string | 是 | - | 要读取的工作表(标签页)名称,例如 Sheet1。 |
| range | string | 是 | - | 要读取的 A1 表示法范围,例如 A1:C3 或 Sheet1!A1:D100。 |
| schema | config | 否 | - | 上游数据的字段定义,详见 Schema 特性。 |
service_account_key [string]
Google Cloud 服务账号密钥 JSON 文件经过 Base64 编码后的内容。服务账号必须有目标 Google 表格的访问 权限(请将服务账号邮箱加入表格的共享列表)。
sheet_id [string]
要读取的 Google 表格 id,即表格 URL 中 /d/ 与 /edit 之间的长字符串。
sheet_name [string]
要读取的工作表(标签页)名称,例如 Sheet1。
range [string]
要读取的 A1 表示法范围,例如 A1:C3 用于读取固定区域,或 Sheet1!A:D 用于读取整列。
schema [config]
fields [config]
上游数据的字段定义。连接器会把每个单元格作为字符串读取,然后按声明的类型进行转换。可用的类型请参考 Schema 特性。
任务示例
简单示例
source {
GoogleSheets {
service_account_key = "seatunnel-test"
sheet_id = "1VI0DvyZK-NIdssSdsDSsSSSC-_-rYMi7ppJiI_jhE"
sheet_name = "sheets01"
range = "A1:C3"
schema = {
fields {
a = int
b = string
c = string
}
}
}
}
配合下游接收器
读取一个工作表并通过 Console 接收器打印读取的行数据。
env {
parallelism = 1
job.mode = "BATCH"
}
source {
GoogleSheets {
service_account_key = "seatunnel-test"
sheet_id = "1VI0DvyZK-NIdssSdsDSsSSSC-_-rYMi7ppJiI_jhE"
sheet_name = "sheets01"
range = "A1:C100"
schema = {
fields {
a = int
b = string
c = string
}
}
}
}
sink {
Console {
}
}
变更日志
Change Log
| Change | Commit | Version |
|---|---|---|
| [improve] google sheets options (#8922) | https://github.com/apache/seatunnel/commit/48ede612dc | 2.3.10 |
| [Improve] restruct connector common options (#8634) | https://github.com/apache/seatunnel/commit/f3499a6eeb | 2.3.10 |
| [Improve][API] Make sure the table name in TablePath not be null (#7252) | https://github.com/apache/seatunnel/commit/764d8b0bc8 | 2.3.7 |
| [Feature][Kafka] Support multi-table source read (#5992) | https://github.com/apache/seatunnel/commit/60104602d1 | 2.3.6 |
| [Improve][Connector-V2] Replace CommonErrorCodeDeprecated.JSON_OPERATION_FAILED (#5978) | https://github.com/apache/seatunnel/commit/456cd17714 | 2.3.4 |
| [Improve][Common] Introduce new error define rule (#5793) | https://github.com/apache/seatunnel/commit/9d1b2582b2 | 2.3.4 |
| Support config column/primaryKey/constraintKey in schema (#5564) | https://github.com/apache/seatunnel/commit/eac76b4e50 | 2.3.4 |
| Merge branch 'dev' into merge/cdc | https://github.com/apache/seatunnel/commit/4324ee1912 | 2.3.1 |
| [Improve][Project] Code format with spotless plugin. | https://github.com/apache/seatunnel/commit/423b583038 | 2.3.1 |
| [improve][api] Refactoring schema parse (#4157) | https://github.com/apache/seatunnel/commit/b2f573a13e | 2.3.1 |
| [Improve][build] Give the maven module a human readable name (#4114) | https://github.com/apache/seatunnel/commit/d7cd601051 | 2.3.1 |
| [Improve][Project] Code format with spotless plugin. (#4101) | https://github.com/apache/seatunnel/commit/a2ab166561 | 2.3.1 |
| [Feature][shade][Jackson] Add seatunnel-jackson module (#3947) | https://github.com/apache/seatunnel/commit/5d8862ec9c | 2.3.1 |
| [Feature][Connector] add get source method to all source connector (#3846) | https://github.com/apache/seatunnel/commit/417178fb84 | 2.3.1 |
| [Hotfix][OptionRule] Fix option rule about all connectors (#3592) | https://github.com/apache/seatunnel/commit/226dc6a119 | 2.3.0 |
| [Improve][Connector-V2][GoogleSheets] Unified exception for GoogleSheets source connector (#3524) | https://github.com/apache/seatunnel/commit/eb42d629ad | 2.3.0 |
| [Feature][Connector-V2][Google Sheets] Add Google Sheets option rules (#3364) | https://github.com/apache/seatunnel/commit/da33f730ca | 2.3.0 |
| fix: schema get error (#3361) | https://github.com/apache/seatunnel/commit/fdaa85ed24 | 2.3.0 |
| [Feature][Connector-V2][GoogleSheets] Support GoogleSheets Source (#3185) | https://github.com/apache/seatunnel/commit/60ecc6428b | 2.3.0 |