输入源
输入源定义了在 Apache® Druid 原生批量摄取中,索引任务从哪里读取数据。只有原生并行任务和简单任务支持输入源。
有关原生批量索引和并行任务索引的一般信息,请参阅原生批量摄取。
S3 输入源
:::info[必需的扩展] 要使用 S3 输入源,请在 common.runtime.properties 文件中加载扩展 druid-s3-extensions。 :::
S3 输入源直接从 S3 读取对象。你可以指定以下任意一种:
- S3 URI 字符串列表
- S3 位置前缀列表,Druid 会尝试列出这些位置下的内容,并摄取其中包含的所有对象。
S3 输入源是可拆分的,因此可以与并行任务一起使用。index_parallel 的每个 worker 任务会读取一个或多个对象。
规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "s3",
"objectGlob": "**.json",
"uris": ["s3://foo/bar/file.json", "s3://bar/foo/file2.json"]
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "s3",
"objectGlob": "**.parquet",
"prefixes": ["s3://foo/bar/", "s3://bar/foo/"]
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "s3",
"objectGlob": "**.json",
"objects": [
{ "bucket": "foo", "path": "bar/file1.json"},
{ "bucket": "bar", "path": "foo/file2.json"}
]
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "s3",
"objectGlob": "**.json",
"uris": ["s3://foo/bar/file.json", "s3://bar/foo/file2.json"],
"properties": {
"accessKeyId": "KLJ78979SDFdS2",
"secretAccessKey": "KLS89s98sKJHKJKJH8721lljkd"
}
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "s3",
"objectGlob": "**.json",
"uris": ["s3://foo/bar/file.json", "s3://bar/foo/file2.json"],
"properties": {
"accessKeyId": "KLJ78979SDFdS2",
"secretAccessKey": "KLS89s98sKJHKJKJH8721lljkd",
"assumeRoleArn": "arn:aws:iam::2981002874992:role/role-s3"
}
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "s3",
"uris": ["s3://foo/bar/file.json", "s3://bar/foo/file2.json"],
"endpointConfig": {
"url" : "s3-store.aws.com",
"signingRegion" : "us-west-2"
},
"clientConfig": {
"protocol" : "http",
"disableChunkedEncoding" : true,
"enablePathStyleAccess" : true,
"crossRegionAccessEnabled" : false
},
"proxyConfig": {
"host" : "proxy-s3.aws.com",
"port" : 8888,
"username" : "admin",
"password" : "admin"
},
"properties": {
"accessKeyId": "KLJ78979SDFdS2",
"secretAccessKey": "KLS89s98sKJHKJKJH8721lljkd",
"assumeRoleArn": "arn:aws:iam::2981002874992:role/role-s3"
}
},
"inputFormat": {
"type": "json"
},
...
},
...| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将值设置为 s3。 | 无 | 是 |
| uris | 待摄取 S3 对象所在位置的 URI 组成的 JSON 数组。 | 无 | 必须设置 uris、prefixes 或 objects 之一 |
| prefixes | 待摄取 S3 对象所在位置的 URI 前缀组成的 JSON 数组。以给定前缀之一开头的空对象会被跳过。 | 无 | 必须设置 uris、prefixes 或 objects 之一 |
| objects | 待摄取的 S3 对象组成的 JSON 数组。 | 无 | 必须设置 uris、prefixes 或 objects 之一 |
| objectGlob | 用于匹配 S3 URI 中对象部分的 glob。对于 URI s3://foo/bar/file.json,glob 会应用于 bar/file.json。glob 必须匹配整个对象部分,而不仅仅是文件名。例如,glob *.json 不会匹配 s3://foo/bar/file.json,因为对象部分是 bar/file.json,而 * 不匹配斜杠。要匹配所有以 .json 结尾的对象,请改用 **.json。更多信息请参阅 FileSystem#getPathMatcher 的文档。 | 无 | 否 |
| systemFields | 作为输入行的一部分返回的系统字段组成的 JSON 数组。可选值:__file_uri(以 s3:// 开头的 S3 URI)、__file_bucket(S3 存储桶)和 __file_path(S3 对象键)。 | 无 | 否 |
| endpointConfig | 用于覆盖默认 S3 端点和签名区域的配置,从而可以从其他 S3 存储中摄取数据。更多信息请参阅 S3 配置。 | 无 | 否(未指定时使用默认值) |
| clientConfig | 被覆盖的 S3 端点所使用的 S3 客户端属性,与 endPointConfig 配合使用。更多信息请参阅 S3 配置。 | 无 | 否(未指定时使用默认值) |
| proxyConfig | 为被覆盖的 S3 端点指定代理信息的属性,与 clientConfig 配合使用。更多信息请参阅 S3 配置。 | 无 | 否(未指定时使用默认值) |
| properties | 用于覆盖默认 S3 配置的 Properties 对象。详见下文。 | 无 | 否(未指定时使用默认值) |
注意,只有在指定了 prefixes 时,S3 输入源才会跳过所有空对象。
S3 对象:
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| bucket | S3 存储桶名称 | 无 | 是 |
| path | 数据所在的路径。 | 无 | 是 |
Properties 对象:
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| accessKeyId | 该 S3 输入源访问密钥的 Password Provider 或纯文本字符串 | 无 | 如果指定了 secretAccessKey 或 sessionToken,则为是。 |
| secretAccessKey | 该 S3 输入源私有密钥的 Password Provider 或纯文本字符串 | 无 | 如果指定了 accessKeyId 或 sessionToken,则为是。 |
| sessionToken | 该 S3 输入源会话令牌的 Password Provider 或纯文本字符串 | 无 | 否 |
| assumeRoleArn | 要承担的角色的 AWS ARN,参见。assumeRoleArn 既可以与摄取规范中的 AWS 凭证一起使用,也可以与默认 S3 凭证一起使用 | 无 | 否 |
| assumeRoleExternalId | 在另一个账户中承担角色时可能需要的唯一标识符,参见 | 无 | 否 |
INFO
如果未指定 accessKeyId 和 secretAccessKey,则使用默认的 S3 凭证提供程序链。
Google Cloud Storage 输入源
:::info[必需的扩展] 要使用 Google Cloud Storage 输入源,请在 common.runtime.properties 文件中加载扩展 druid-google-extensions。 :::
Google Cloud Storage 输入源用于直接从 Google Cloud Storage 读取对象。对象可以指定为 Google Cloud Storage URI 字符串列表。Google Cloud Storage 输入源是可拆分的,可以由并行任务使用,index_parallel 的每个 worker 任务会读取一个或多个对象。
规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "google",
"objectGlob": "**.json",
"uris": ["gs://foo/bar/file.json", "gs://bar/foo/file2.json"]
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "google",
"objectGlob": "**.parquet",
"prefixes": ["gs://foo/bar/", "gs://bar/foo/"]
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "google",
"objectGlob": "**.json",
"objects": [
{ "bucket": "foo", "path": "bar/file1.json"},
{ "bucket": "bar", "path": "foo/file2.json"}
]
},
"inputFormat": {
"type": "json"
},
...
},
...| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将值设置为 google。 | 无 | 是 |
| uris | 待摄取 Google Cloud Storage 对象所在位置的 URI 组成的 JSON 数组。 | 无 | 必须设置 uris、prefixes 或 objects 之一 |
| prefixes | 待摄取 Google Cloud Storage 对象所在位置的 URI 前缀组成的 JSON 数组。以给定前缀之一开头的空对象会被跳过。 | 无 | 必须设置 uris、prefixes 或 objects 之一 |
| objects | 待摄取的 Google Cloud Storage 对象组成的 JSON 数组。 | 无 | 必须设置 uris、prefixes 或 objects 之一 |
| objectGlob | 用于匹配 S3 URI 中对象部分的 glob。对于 URI s3://foo/bar/file.json,glob 会应用于 bar/file.json。glob 必须匹配整个对象部分,而不仅仅是文件名。例如,glob *.json 不会匹配 s3://foo/bar/file.json,因为对象部分是 bar/file.json,而 * 不匹配斜杠。要匹配所有以 .json 结尾的对象,请改用 **.json。更多信息请参阅 FileSystem#getPathMatcher 的文档。 | 无 | 否 |
注意,只有在指定了 prefixes 时,Google Cloud Storage 输入源才会跳过所有空对象。
Google Cloud Storage 对象:
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| bucket | Google Cloud Storage 存储桶名称 | 无 | 是 |
| path | 数据所在的路径。 | 无 | 是 |
| systemFields | 作为输入行的一部分返回的系统字段组成的 JSON 数组。可选值:__file_uri(以 gs:// 开头的 Google Cloud Storage URI)、__file_bucket(GCS 存储桶)和 __file_path(GCS 键)。 | 无 | 否 |
Azure 输入源
:::info[必需的扩展] 要使用 Azure 输入源,请在 common.runtime.properties 文件中加载扩展 druid-azure-extensions。 :::
Azure 输入源(类型为 azureStorage)直接从 Azure Blob 存储或 Azure Data Lake 源读取对象。你可以将对象指定为文件 URI 字符串列表或前缀列表。Azure 输入源可以拆分后用于并行任务索引,每个 worker 任务读取拆分数据中的一块。
azureStorage 输入源是 Azure 输入源的新 schema,允许你指定从哪个存储账户摄取文件。建议将所有使用旧版 azure schema 的规范更新为使用新的 azureStorage schema。新 schema 比旧的 azure schema 提供更多功能。
规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "azureStorage",
"objectGlob": "**.json",
"uris": ["azureStorage://storageAccount/container/prefix1/file.json", "azureStorage://storageAccount/container/prefix2/file2.json"]
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "azureStorage",
"objectGlob": "**.parquet",
"prefixes": ["azureStorage://storageAccount/container/prefix1/", "azureStorage://storageAccount/container/prefix2/"]
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "azureStorage",
"objectGlob": "**.json",
"objects": [
{ "bucket": "storageAccount", "path": "container/prefix1/file1.json"},
{ "bucket": "storageAccount", "path": "container/prefix2/file2.json"}
],
"properties": {
"sharedAccessStorageToken": "?sv=...<storage token secret>...",
}
},
"inputFormat": {
"type": "json"
},
...
},
...| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将值设置为 azureStorage。 | 无 | 是 |
| uris | 待摄取 Azure 对象所在位置的 URI 组成的 JSON 数组。使用以下格式:azureStorage://STORAGE_ACCOUNT/CONTAINER/PATH_TO_FILE | 无 | 必须设置以下其中之一:uris、prefixes 或 objects。 |
| prefixes | 待摄取 Azure 对象所在位置的 URI 前缀组成的 JSON 数组。使用以下格式:azureStorage://STORAGE_ACCOUNT/CONTAINER/PREFIX。以任一给定前缀开头的空对象会被跳过。 | 无 | 必须设置以下其中之一:uris、prefixes 或 objects。 |
| objects | 待摄取的 Azure 对象组成的 JSON 数组。 | 无 | 必须设置以下其中之一:uris、prefixes 或 objects。 |
| objectGlob | 用于匹配 Azure URI 中对象部分的 glob。对于 URI azureStorage://foo/bar/file.json,glob 会应用于 bar/file.json。glob 必须匹配整个对象部分,而不仅仅是文件名。例如,glob *.json 不会匹配 azureStorage://foo/bar/file.json,因为对象部分是 bar/file.json,而 * 不匹配斜杠。要匹配所有以 .json 结尾的对象,请改用 **.json。更多信息请参阅 FileSystem#getPathMatcher 的文档。 | 无 | 否 |
| systemFields | 作为输入行的一部分返回的系统字段组成的 JSON 数组。可选值:__file_uri(以 azureStorage:// 开头的 Azure blob URI)、__file_bucket(Azure 存储桶)和 __file_path(Azure 对象路径)。 | 无 | 否 |
| properties | 用于覆盖默认 Azure 配置的 Properties 对象。详见下文。 | 无 | 否(未指定时使用默认值) |
注意,只有在指定了 prefixes 时,Azure 输入源才会跳过所有空对象。
objects 属性可以是以下内容之一:
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| bucket | Azure Blob Storage 或 Azure Data Lake 存储账户的名称 | 无 | 是 |
| path | 数据所在的容器和路径。 | 无 | 是 |
properties 属性可以是以下内容之一:
sharedAccessStorageTokenkeyappRegistrationClientId,appRegistrationClientSecret, andtenantId- 空
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| sharedAccessStorageToken | 该 Azure Blob Storage 共享访问令牌的纯文本字符串 | 无 | 否 |
| key | Azure Blob Storage 账户的根密钥 | 无 | 否 |
| appRegistrationClientId | 用于身份验证的 Azure 应用注册的客户端 ID | 无 | 否 |
| appRegistrationClientSecret | 用于身份验证的 Azure 应用注册的客户端密钥 | 无 | 如果提供了 appRegistrationClientId,则为是 |
| tenantId | 用于身份验证的 Azure 应用注册的租户 ID | 无 | 如果提供了 appRegistrationClientId,则为是 |
旧版 azure 输入源
类型为 azure 的 Azure 输入源是 Azure 输入类型的旧版本,不建议使用。它不支持指定从哪个存储账户摄取数据。建议改用 azureStorage 输入源 schema,因为它提供了更多功能。
规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "azure",
"objectGlob": "**.json",
"uris": ["azure://container/prefix1/file.json", "azure://container/prefix2/file2.json"]
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "azure",
"objectGlob": "**.parquet",
"prefixes": ["azure://container/prefix1/", "azure://container/prefix2/"]
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "azure",
"objectGlob": "**.json",
"objects": [
{ "bucket": "container", "path": "prefix1/file1.json"},
{ "bucket": "container", "path": "prefix2/file2.json"}
]
},
"inputFormat": {
"type": "json"
},
...
},
...| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将值设置为 azure。 | 无 | 是 |
| uris | 待摄取 Azure 对象所在位置的 URI 组成的 JSON 数组,格式为 azure://<container>/<path-to-file> | 无 | 必须设置 uris、prefixes 或 objects 之一 |
| prefixes | 待摄取 Azure 对象所在位置的 URI 前缀组成的 JSON 数组,格式为 azure://<container>/<prefix>。以给定前缀之一开头的空对象会被跳过。 | 无 | 必须设置 uris、prefixes 或 objects 之一 |
| objects | 待摄取的 Azure 对象组成的 JSON 数组。 | 无 | 必须设置 uris、prefixes 或 objects 之一 |
| objectGlob | 用于匹配 Azure URI 中对象部分的 glob。对于 URI azure://foo/bar/file.json,glob 会应用于 bar/file.json。glob 必须匹配整个对象部分,而不仅仅是文件名。例如,glob *.json 不会匹配 azure://foo/bar/file.json,因为对象部分是 bar/file.json,而 * 不匹配斜杠。要匹配所有以 .json 结尾的对象,请改用 **.json。更多信息请参阅 FileSystem#getPathMatcher 的文档。 | 无 | 否 |
| systemFields | 作为输入行的一部分返回的系统字段组成的 JSON 数组。可选值:__file_uri(以 azure:// 开头的 Azure blob URI)、__file_bucket(Azure 存储桶)和 __file_path(Azure 对象路径)。 | 无 | 否 |
注意,只有在指定了 prefixes 时,Azure 输入源才会跳过所有空对象。
objects 属性如下:
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| bucket | Azure Blob Storage 或 Azure Data Lake 容器的名称 | 无 | 是 |
| path | 数据所在的路径。 | 无 | 是 |
HDFS 输入源
:::info[必需的扩展] 要使用 HDFS 输入源,请在 common.runtime.properties 文件中加载扩展 druid-hdfs-storage。 :::
HDFS 输入源用于直接从 HDFS 存储读取文件。文件路径可以指定为单个 HDFS URI 字符串或 HDFS URI 字符串列表。HDFS 输入源是可拆分的,可以由并行任务使用,index_parallel 的每个 worker 任务会读取一个或多个文件。
规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "hdfs",
"paths": "hdfs://namenode_host/foo/bar/", "hdfs://namenode_host/bar/foo"
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "hdfs",
"paths": "hdfs://namenode_host/foo/bar/", "hdfs://namenode_host/bar/foo"
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "hdfs",
"paths": "hdfs://namenode_host/foo/bar/file.json", "hdfs://namenode_host/bar/foo/file2.json"
},
"inputFormat": {
"type": "json"
},
...
},
......
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "hdfs",
"paths": ["hdfs://namenode_host/foo/bar/file.json", "hdfs://namenode_host/bar/foo/file2.json"]
},
"inputFormat": {
"type": "json"
},
...
},
...| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将值设置为 hdfs。 | 无 | 是 |
| paths | HDFS 路径。可以是 JSON 数组,也可以是以逗号分隔的路径字符串。这些路径支持 * 之类的通配符。位于给定路径之一下的空文件会被跳过。名称以 _ 或 . 开头的隐藏文件和目录会被自动排除。当路径指向一个目录时,只会列出该目录下的直接文件,不会遍历子目录。要摄取嵌套目录中的文件,请使用 glob 模式,例如 hdfs://namenode_host/data/**/*.json。 | 无 | 是 |
| systemFields | 作为输入行的一部分返回的系统字段组成的 JSON 数组。可选值:__file_uri(URI)和 __file_path(URI 的路径部分)。 | 无 | 否 |
如果 HDFS 客户端支持其他存储,你也可以使用 HDFS 输入源从这些存储中摄取数据。不过,如果要从云存储摄取数据,请考虑使用与你的数据存储服务对应的专用输入源。如果要在 HDFS 输入源中使用非 HDFS 协议,请将该协议加入 druid.ingestion.hdfs.allowedProtocols。更多详情请参阅 HDFS 输入源安全配置。
HTTP 输入源
HTTP 输入源用于通过 HTTP 直接从远程站点读取文件。
:::info[安全说明]
摄取任务运行在运行 Druid 进程(例如 Indexer、Middle Manager 和 Peon)的操作系统账户下。这意味着任何能够提交摄取任务的用户,都可以指定一个指向 Druid 进程可访问的任意位置的输入源。例如,借助 http 输入源,用户可能会访问到内部网络中的服务器。
http 输入源并不限于 HTTP 或 HTTPS 协议。它使用 Java URI 类,默认支持 HTTP、HTTPS、FTP、file 和 jar 协议。
:::
有关安全最佳实践的更多信息,请参阅安全概述。
HTTP 输入源是可拆分的,可以由并行任务使用,index_parallel 的每个 worker 任务只会读取一个文件。该输入源不支持 Split Hint Spec。
规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "http",
"uris": ["http://example.com/uri1", "http://example2.com/uri2"]
},
"inputFormat": {
"type": "json"
},
...
},
...使用 DefaultPassword 提供程序并带有身份验证字段的示例(这要求密码写在摄取规范中):
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "http",
"uris": ["http://example.com/uri1", "http://example2.com/uri2"],
"httpAuthenticationUsername": "username",
"httpAuthenticationPassword": "password123"
},
"inputFormat": {
"type": "json"
},
...
},
...你也可以使用其他现有的 Druid PasswordProvider。下面是一个使用 EnvironmentVariablePasswordProvider 的示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "http",
"uris": ["http://example.com/uri1", "http://example2.com/uri2"],
"httpAuthenticationUsername": "username",
"httpAuthenticationPassword": {
"type": "environment",
"variable": "HTTP_INPUT_SOURCE_PW"
}
},
"inputFormat": {
"type": "json"
},
...
},
...
}| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将值设置为 http。 | 无 | 是 |
| uris | 输入文件的 URI。URI 允许使用的协议见下文。 | 无 | 是 |
| httpAuthenticationUsername | 对指定 URI 进行身份验证时使用的用户名。如果规范中指定的 URI 需要 Basic Authentication Header,可以选择使用此项。 | 无 | 否 |
| httpAuthenticationPassword | 用于指定 URI 的 PasswordProvider。如果规范中指定的 URI 需要 Basic Authentication Header,可以选择使用此项。 | 无 | 否 |
| systemFields | 作为输入行的一部分返回的系统字段组成的 JSON 数组。可选值:__file_uri(包含 scheme 的 URI)和 __file_path(URI 的路径部分)。 | 无 | 否 |
只有 druid.ingestion.http.allowedProtocols 属性中列出的协议才能用于 HTTP 输入源。默认允许 http 和 https 协议。更多详情请参阅 HTTP 输入源安全配置。
Inline 输入源
Inline 输入源可用于读取内联在其自身规范中的数据,适用于演示或快速测试解析和 schema。
规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "inline",
"data": "0,values,formatted\n1,as,CSV"
},
"inputFormat": {
"type": "csv"
},
...
},
...| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将值设置为 inline。 | 是 |
| data | 要摄取的内联数据。 | 是 |
Local 输入源
Local 输入源用于直接从本地存储读取文件,主要用于概念验证测试。Local 输入源是可拆分的,可以由并行任务使用,index_parallel 的每个 worker 任务会读取一个或多个文件。
规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "local",
"filter" : "*.csv",
"baseDir": "/data/directory",
"files": ["/bar/foo", "/foo/bar"]
},
"inputFormat": {
"type": "csv"
},
...
},
...| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将值设置为 local。 | 是 |
| filter | 文件的通配符过滤器。更多信息请参阅这里。符合过滤条件的文件会被纳入摄取,不符合过滤条件的文件会被忽略。 | 如果指定了 baseDir,则为是 |
| baseDir | 递归搜索待摄取文件的目录。baseDir 下的空文件会被跳过。 | baseDir 和 files 至少需要指定一个 |
| files | 要摄取的文件路径。如果某些文件位于指定的 baseDir 下,可能会被忽略以避免重复摄取。空文件会被跳过。 | baseDir 和 files 至少需要指定一个 |
| systemFields | 作为输入行的一部分返回的系统字段组成的 JSON 数组。可选值:__file_uri(以 file: 开头的文件 URI)和 __file_path(文件路径)。 | 否 |
Druid 输入源
Druid 输入源用于直接从现有的 Druid 段读取数据,并可以使用新的 schema,修改段的名称、维度、指标、rollup 等。Druid 输入源是可拆分的,可以由并行任务使用。该输入源使用固定的输入格式读取 Druid 段;使用该输入源时,无需在摄取规范中指定 inputFormat 字段。
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将值设置为 druid。 | 是 |
| dataSource | 一个字符串,指定要从中获取行的 Druid 数据源 | 是 |
| interval | 一个表示 ISO-8601 时间间隔的字符串,定义获取数据的时间范围。 | 是 |
| filter | 参见过滤器。如果指定了过滤器,则只返回与之匹配的行。 | 否 |
Druid 输入源可用于多种用途,包括:
- 创建新的数据源,作为现有数据源经过 rollup 的副本。
- 更改数据源的分区或排序以提升性能。
- 使用
transformSpec更新或删除行。
使用 Druid 输入源时,时间戳列会显示为一个名为 __time 的数值字段,其值为自纪元(1970 年 1 月 1 日 00:00:00 UTC)以来的毫秒数。如果希望输出时间戳与输入时间戳相同,通常会在 timestampSpec 中使用该字段。此时,请将时间戳列设置为 __time,并将格式设置为 auto 或 millis。
输入数据源和输出数据源可以相同。在这种情况下,对于 granularitySpec 中指定的时间间隔,新生成的数据会覆盖之前的数据。一般来说,如果打算这样做,最好先写入一个单独的数据源来测试重新索引,然后再覆盖主数据源。或者,如果压缩(compaction)就能满足你的目标,可以考虑使用这种更简单的方法。
下面是一个任务规范示例。它从一个假设的原始数据源 wikipedia_raw 读取数据,并按小时、“countryName”和“page”分组,创建一个新的经过 rollup 的数据源 wikipedia_rollup。
{
"type": "index_parallel",
"spec": {
"dataSchema": {
"dataSource": "wikipedia_rollup",
"timestampSpec": {
"column": "__time",
"format": "millis"
},
"dimensionsSpec": {
"dimensions": [
"countryName",
"page"
]
},
"metricsSpec": [
{
"type": "count",
"name": "cnt"
}
],
"granularitySpec": {
"type": "uniform",
"queryGranularity": "HOUR",
"segmentGranularity": "DAY",
"intervals": ["2016-06-27/P1D"],
"rollup": true
}
},
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "druid",
"dataSource": "wikipedia_raw",
"interval": "2016-06-27/P1D"
}
},
"tuningConfig": {
"type": "index_parallel",
"partitionsSpec": {
"type": "hashed"
},
"forceGuaranteedRollup": true,
"maxNumConcurrentSubTasks": 1
}
}
}INFO
较早的版本(0.19 及更早)在使用 Druid 输入源时不遵循 timestampSpec。如果你的摄取规范依赖这一行为且无法改写,请将 druid.indexer.task.ignoreTimestampSpecForDruidInputSource 设置为 true,以启用忽略 timestampSpec 的兼容模式。
二级分区方法决定了使用 Combining 输入源完成摄取时所需并行运行的并发 worker 任务数。请根据二级分区方法,在 tuningConfig 的 maxNumConcurrentSubTasks 中设置该值:
range或single_dim分区:大于或等于 1hashed或dynamic分区:大于或等于 2
有关 maxNumConcurrentSubTasks 字段的更多信息,请参阅实现注意事项。
SQL 输入源
:::info[必需的扩展] 要使用 SQL 输入源,必须在 common.runtime.properties 文件中加载相应的扩展。
- 要连接 MySQL,请加载扩展
mysql-metadata-storage。 - 要连接 PostgreSQL,请加载扩展
postgresql-metadata-storage。
MySQL 扩展需要 JDBC 驱动。更多信息请参阅安装 MySQL 连接器库。 :::
SQL 输入源用于直接从 RDBMS 读取数据。你可以对 SQL 输入源的摄取任务进行拆分。使用并行任务类型时,每个 worker 任务会从查询列表中选取一条 SQL 查询来读取数据。该输入源不支持 Split Hint Spec。
SQL 输入源使用固定的输入格式读取事件。使用该输入源时不要指定 inputFormat。
使用该输入源之前,请先参阅推荐做法。
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将值设置为 sql。 | 是 |
| database | 指定数据库连接详情。数据库类型对应提供 connectorConfig 支持的扩展。你可以有选择地允许 connectURI 中的 JDBC 属性。更多详情请参阅 JDBC 连接安全配置。 | 是 |
| foldCase | 布尔值,用于开关数据库列名的大小写折叠。例如,要将名为 Entry_Date 的数据库列摄取为 entry_date,请将 foldCase 设置为 true,并在 dimensionsSpec 中包含 entry_date。 | 否 |
| sqls | SQL 查询列表,每条 SQL 查询用于检索待索引的数据。 | 是 |
下面是一个 SQL 输入源规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "sql",
"database": {
"type": "mysql",
"connectorConfig": {
"connectURI": "jdbc:mysql://host:port/schema",
"user": "user",
"password": "password"
}
},
"sqls": ["SELECT * FROM table1 WHERE timestamp BETWEEN '2013-01-01 00:00:00' AND '2013-01-01 11:59:59'", "SELECT * FROM table2 WHERE timestamp BETWEEN '2013-01-01 00:00:00' AND '2013-01-01 11:59:59'"]
}
},
...上述规范会通过两条独立的 SQL 读取时间间隔 2013-01-01/2013-01-02 内的所有事件。每条 SQL 查询都会在各自的子任务中运行,因此在上例中会有两个子任务。
推荐做法
与其他原生批量输入源相比,SQL 输入源在读取输入数据方面的行为有所不同。因此,在生产环境中使用该输入源之前,请考虑以下几点:
在索引过程中,每个子任务会执行其中一条 SQL 查询,并将结果存储在本地磁盘上。然后,子任务从这些本地输入文件中读取数据并生成段。目前对生成文件的大小没有任何限制,因此需要 Middle Manager 或 Indexer 根据待索引的数据量具备足够的磁盘容量。
根据
granularitySpec中指定的时间间隔对 SQL 查询进行过滤,可以避免索引子任务检索并在本地存储不需要的数据。例如,如果granularitySpec中指定的intervals为["2013-01-01/2013-01-02"],而 SQL 查询为SELECT * FROM table1,那么SqlInputSource会根据该查询读取table1的全部数据,尽管只有指定时间间隔内的数据会被索引到 Druid 中。可以对 SQL 查询使用分页,确保每条查询拉取的数据量相近,从而提高子任务的效率。
与基于文件的输入格式类似,对现有数据的任何更新都会替换
granularitySpec中指定时间间隔所对应段中的数据。
Combining 输入源
Combining 输入源允许你从多个输入源读取数据。它会识别各个委托输入源的拆分,并使用 worker 任务处理每个拆分。每个委托输入源都必须是可拆分的,并且与并行任务类型兼容。
与其他输入源类似,Combining 输入源只支持单个 inputFormat。需要 inputFormat 的委托输入源,其输入数据必须使用相同的格式。如果包含 Druid 输入源,时间戳列会存储在 __time 字段中。要将 Druid 输入源的数据与其他输入源正确合并,请确保其他委托输入源也将时间戳列存储在 __time 中。
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将值设置为 combining。 | 是 |
| delegates | 要从中读取数据的可拆分输入源列表。 | 是 |
下面是一个 Combining 输入源规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "combining",
"delegates" : [
{
"type": "local",
"filter" : "*.csv",
"baseDir": "/data/directory",
"files": ["/bar/foo", "/foo/bar"]
},
{
"type": "druid",
"dataSource": "wikipedia",
"interval": "2013-01-01/2013-01-02"
}
]
},
"inputFormat": {
"type": "csv"
},
...
},
...Iceberg 输入源
:::info[必需的扩展] 要使用 Iceberg 输入源,请在 common.runtime.properties 文件中加载扩展 druid-iceberg-extensions。 :::
你可以使用 Iceberg 输入源读取以 Iceberg 表格式存储的数据。对于给定的表,该输入源会从配置的 Hive catalog 中扫描到最新的 Iceberg 快照为止。Druid 使用现有的输入源格式摄取底层的活动数据文件。
Iceberg 输入源不能独立使用,因为它依赖现有的输入源来读取数据文件。例如,如果与 Iceberg catalog 关联的仓库位于 S3 上,还必须加载 druid-s3-extensions 扩展。
下面是一个 HDFS 仓库源的规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "iceberg",
"tableName": "iceberg_table",
"namespace": "iceberg_namespace",
"icebergCatalog": {
"type": "hive",
"warehousePath": "hdfs://warehouse/path",
"catalogUri": "thrift://hive-metastore.x.com:8970",
"catalogProperties": {
"hive.metastore.connect.retries": "1",
"hive.metastore.execute.setugi": "false",
"hive.metastore.kerberos.principal": "KRB_PRINCIPAL",
"hive.metastore.sasl.enabled": "true",
"metastore.catalog.default": "catalog_test",
"hadoop.security.authentication": "kerberos",
"hadoop.security.authorization": "true"
}
},
"icebergFilter": {
"type": "interval",
"filterColumn": "event_time",
"intervals": [
"2023-05-10T19:00:00.000Z/2023-05-10T20:00:00.000Z"
]
},
"warehouseSource": {
"type": "hdfs"
},
"snapshotTime": "2023-06-01T00:00:00.000Z",
},
"inputFormat": {
"type": "parquet"
}
},
...
},
...下面是一个 S3 仓库源的规范示例:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "iceberg",
"tableName": "iceberg_table",
"namespace": "iceberg_namespace",
"icebergCatalog": {
"type": "hive",
"warehousePath": "s3://warehouse/path",
"catalogUri": "thrift://hive-metastore.x.com:8970",
"catalogProperties": {
"hive.metastore.connect.retries": "1",
"hive.metastore.execute.setugi": "false",
"hive.metastore.kerberos.principal": "KRB_PRINCIPAL",
"hive.metastore.sasl.enabled": "true",
"metastore.catalog.default": "default_catalog",
"fs.s3a.access.key" : "S3_ACCESS_KEY",
"fs.s3a.secret.key" : "S3_SECRET_KEY",
"fs.s3a.endpoint" : "S3_API_ENDPOINT"
}
},
"icebergFilter": {
"type": "interval",
"filterColumn": "event_time",
"intervals": [
"2023-05-10T19:00:00.000Z/2023-05-10T20:00:00.000Z"
]
},
"warehouseSource": {
"type": "s3",
"endpointConfig": {
"url": "teststore.aws.com",
"signingRegion": "us-west-2a"
},
"clientConfig": {
"protocol": "http",
"disableChunkedEncoding": true,
"enablePathStyleAccess": true,
"forceGlobalBucketAccessEnabled": false
},
"properties": {
"accessKeyId": {
"type": "default",
"password": "foo"
},
"secretAccessKey": {
"type": "default",
"password": "bar"
}
},
}
},
"inputFormat": {
"type": "parquet"
}
},
...
},| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将值设置为 iceberg。 | 是 |
| tableName | 在 catalog 中配置的 Iceberg 表名。 | 是 |
| namespace | 与该表关联的 Iceberg 命名空间。 | 是 |
| icebergFilter | 用于过滤快照中数据文件的 JSON 对象。 | 否 |
| icebergCatalog | 用于定义管理所配置 Iceberg 表的 catalog 的 JSON 对象。 | 是 |
| warehouseSource | 定义从仓库读取数据文件所用原生输入源的 JSON 对象。 | 是 |
| snapshotTime | ISO8601 DateTime 格式的时间戳,用于获取截至该时间的最新快照。 | 否 |
| residualFilterMode | 控制过滤产生残留结果时如何处理残留过滤器。这通常发生在 Iceberg 过滤器作用于非分区列时:文件中可能包含不匹配过滤条件的行(残留行)。有效值为:ignore(默认,摄取所有行并记录一条警告)和 fail(使摄取作业失败)。如果 transformSpec 中没有过滤器,可使用 fail 来确保不会摄取多余的数据。 | 否 |
Catalog 对象
catalog 对象支持 rest、hive、glue 和 local 四种 catalog 类型。
下表列出了 local catalog 的属性:
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将该值设置为 local。 | 无 | 是 |
| warehousePath | 与该 catalog 关联的仓库位置。 | 无 | 是 |
| catalogProperties | 需要附加到 catalog 上的其他属性的映射。 | 无 | 否 |
| caseSensitive | 读取 Iceberg 表时,是否对列名区分大小写。 | true | 否 |
下表列出了 hive catalog 的属性:
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将该值设置为 hive。 | 无 | 是 |
| warehousePath | 与该 catalog 关联的仓库位置。 | 无 | 是 |
| catalogUri | 与该 Hive catalog 关联的 URI。 | 无 | 是 |
| catalogProperties | 需要附加到 catalog 上的其他属性的映射。 | 无 | 否 |
| caseSensitive | 读取 Iceberg 表时,是否对列名区分大小写。 | true | 否 |
下表列出了 rest catalog 的属性:
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将该值设置为 rest。 | 无 | 是 |
| catalogUri | 与该 catalog 的 HTTP 端点关联的 URI。 | 无 | 是 |
| catalogProperties | 需要附加到 catalog 上的其他属性的映射。 | 无 | 否 |
下表列出了 glue catalog 的属性:
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将该值设置为 glue。 | 无 | 是 |
| catalogProperties | 需要附加到 catalog 上的其他属性的映射。所有配置都应遵循 Iceberg Catalog 配置文档 | 无 | 是 |
示例:
...
"icebergCatalog":
{
"type": "glue",
"catalogProperties":
{
"warehouse": "s3a://bucket/warehouse",
"io-impl": "org.apache.iceberg.aws.s3.S3FileIO"
}
}
..Iceberg 过滤器对象
该输入源提供以下过滤器:and、equals、interval、timeWindow、range 和 or。你可以使用这些过滤器从快照中过滤掉数据文件,从而减少 Druid 需要摄取的文件数量。 强烈建议只在 Iceberg 分区列上应用过滤。在非分区列上过滤时,Iceberg 过滤器可能会返回不完全匹配表达式的行。为解决这一问题,可以在 transformSpec 中额外定义一个过滤器来移除残留行。
equals 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 equals。 | 是 |
| filterColumn | Iceberg 表 schema 中用于过滤的列名。 | 是 |
| filterValue | 要过滤的值。 | 是 |
interval 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 interval。 | 是 |
| filterColumn | Iceberg 表 schema 中作为过滤依据的列名 | 是 |
| intervals | 包含 ISO 8601 时间间隔字符串的 JSON 数组,定义要过滤的时间范围。起始时间包含在内,结束时间不包含在内。 | 是 |
and 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 and。 | 是 |
| filters | 需要进行 AND 运算的 Iceberg 过滤器列表 | 是 |
or 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 or。 | 是 |
| filters | 需要进行 OR 运算的 Iceberg 过滤器列表 | 是 |
not 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 not。 | 是 |
| filter | 要应用逻辑 NOT 的 Iceberg 过滤器 | 是 |
range 过滤器:
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将该值设置为 range。 | 无 | 是 |
| filterColumn | Iceberg 表 schema 中作为范围过滤依据的列名。 | 无 | 是 |
| lower | 要匹配的下界值。 | 无 | 否。lower 和 upper 至少有一个不能为 null。 |
| upper | 要匹配的上界值。 | 无 | 否。lower 和 upper 至少有一个不能为 null。 |
| lowerOpen | 布尔值,表示在范围所定义的值区间中下界是否为开区间(使用 > 而不是 >=)。 | false | 否 |
| upperOpen | 布尔值,表示在范围所定义的值区间中上界是否为开区间(使用 < 而不是 <=)。 | false | 否 |
timeWindow 过滤器:
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将该值设置为 timeWindow。 | 无 | 是 |
| filterColumn | Iceberg 表 schema 中作为过滤依据的列名。该过滤列在 Iceberg 中必须定义为 TimestampType。 | 无 | 是 |
| baseTime | 参考时间戳,以它为基准应用回看和前瞻时长来定义时间窗口。 | 当前 UTC 时间戳 | 否 |
| lookbackDuration | 定义过滤器相对于 baseTime 向前回溯多长时间来包含数据。 | P1D | 否 |
| lookaheadDuration | 定义过滤器相对于 baseTime 向后延伸多长时间来包含数据。 | 零 | 否 |
Delta Lake 输入源
:::info[必需的扩展] 要使用 Delta Lake 输入源,请在 common.runtime.properties 文件中加载扩展 druid-deltalake-extensions。 :::
你可以使用 Delta 输入源读取存储在 Delta Lake 表中的数据。对于给定的表,该输入源会扫描所配置表的最新快照。Druid 会摄取该表底层的 delta 文件。
| 属性 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
| type | 将该值设置为 delta。 | 无 | 是 |
| tablePath | Delta 表的位置。 | 无 | 是 |
| filter | 用于过滤快照中数据文件的 JSON 对象。 | 无 | 否 |
| snapshotVersion | 要从 Delta 表中读取的快照版本,必须指定为整数值。 | 最新版本 | 否 |
Delta 过滤器对象
你可以使用这些过滤器从快照中过滤掉数据文件,从而减少 Druid 需要从 Delta 表中摄取的文件数量。该输入源提供以下过滤器:and、or、not、=、>、>=、<、<=。
在非分区列上应用过滤器时,过滤只是尽力而为,因为 Delta Kernel 完全依赖于创建非分区表时收集的统计信息。在这种情况下,该 Druid 连接器可能会摄取不匹配过滤条件的数据。为确保 Delta Kernel 剪除不必要的列值,请只在分区列上使用过滤器。
and 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 and。 | 是 |
| filters | Delta 过滤谓词列表,使用逻辑 AND 求值,所有条件都必须为真。and 过滤器需要两个过滤谓词。 | 是 |
or 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 or。 | 是 |
| filters | Delta 过滤谓词列表,使用逻辑 OR 求值,只需一个条件为真即可。or 过滤器需要两个过滤谓词。 | 是 |
not 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 not。 | 是 |
| filter | 使用逻辑 NOT 求值的 Delta 过滤谓词。not 过滤器需要一个过滤谓词。 | 是 |
= 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 =。 | 是 |
| column | 要应用过滤器的表列。 | 是 |
| value | 过滤器中使用的值。 | 是 |
> 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 >。 | 是 |
| column | 要应用过滤器的表列。 | 是 |
| value | 过滤器中使用的值。 | 是 |
>= 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 >=。 | 是 |
| column | 要应用过滤器的表列。 | 是 |
| value | 过滤器中使用的值。 | 是 |
< 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 <。 | 是 |
| column | 要应用过滤器的表列。 | 是 |
| value | 过滤器中使用的值。 | 是 |
<= 过滤器:
| 属性 | 描述 | 是否必需 |
|---|---|---|
| type | 将该值设置为 <=。 | 是 |
| column | 要应用过滤器的表列。 | 是 |
| value | 过滤器中使用的值。 | 是 |
下面的规范示例从 Delta 表 /delta-table/foo 的最新快照中读取所有记录:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "delta",
"tablePath": "/delta-table/foo"
},
}下面的规范示例从 Delta 表 /delta-table/foo 的快照版本 3 中读取记录,筛选出满足 name = 'Employee4' and age >= 30 的记录:
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "delta",
"tablePath": "/delta-table/foo",
"filter": {
"type": "and",
"filters": [
{
"type": "=",
"column": "name",
"value": "Employee4"
},
{
"type": ">=",
"column": "age",
"value": "30"
}
]
},
"snapshotVersion": 3
},
}