amazon-web-services - 在 AWS Glue 中读取分区的 Avro 文件
问题描述
例如,我有一个存储桶,它在 Avro 中有大量数据以“蜂巢”样式分区
s3://my-bucket/year=2018/month=03/day=25/file-name.avro
我试图在 Glue 中访问这些数据:
val predicate = "year=2018 and month=03"
val opts = JsonOptions("""{ "paths": ["s3://my-bucket/"], "recurse": true }""")
val src = glueContext.getSource(connectionType = "s3"
, connectionOptions = opts
, pushDownPredicate = predicate
).withFormat("avro")
但是这个表达式失败了,但有一个例外:
com.amazonaws.services.glue.util.NonFatalException: User's pushdown predicate: year=2018 and month=03 can not be resolved against partition columns: []
我尝试过这样的事情:
val predicate = "year=2018 and month=3"
val opts = JsonOptions("""{ "paths": ["s3://my-bucket/"], "recurse": true }""")
val src = glueContext.getSourceWithFormat(connectionType = "s3", format="avro", options = opts, pushDownPredicate = predicate)
但它根本不接受下推谓词:
error: unknown parameter name: pushDownPredicate
我也尝试添加
"partitionKeys": ["year", "month", "day"]
到JsonOptions
,也没有成功。
如何在没有爬虫的情况下在 Glue 中读取配置单元分区的 Avro 序列化数据?
解决方案
目前不可能使用下推谓词getSource()
,getSourceWithFormat()
因为它在内部验证表达式中的字段是否实际上是分区。它从getCatalogSource()
Glue Catalog 加载此信息并传递给验证器。因为getSource()
并且getSourceWithFormat()
不可能传递要用于验证的数据分区的自定义列表,因此不可能使用下推谓词。
作为一种解决方法,您可以生成包含数据分区的路径并将其getSourceWithFormat()
通过options
. 例如,如果你想加载数据,year=2018 and (month=03 or month=04)
那么你的代码应该是这样的:
val paths = Array(
"s3://bucket/data/year=2018/month=03",
"s3://bucket/data/year=2018/month=04"
)
val source = glueContext.getSourceWithFormat(
connectionType = "s3",
format = "avro",
options = JsonOptions(Map(
"paths" -> paths,
"recurse": true
))).getDynamicFrame()
请注意,source
DynamicFrame 不包含分区列year
,month
因此您可能需要手动添加它们。
推荐阅读
- discord.py - discord py 赋予特定用户 id 角色
- python-3.x - 如何从具有各种嘈杂文本和数字的图像中提取文本?
- uwp - 如何在 Uno 平台中将 RadialGradientBrush 与 Storyboard 一起使用
- rest - Moodle Rest API 上的 invalid_parameter_exception
- eslint - eslint 错误:解析错误:保留关键字“export”
- azure - 在 Azure 中配置站点-站点 VPN 时,为什么没有本地网络网关不能配置 vpn 网关?
- sql - 查询返回不同的结果(是索引问题吗?)
- python - 如果列表包含数字序列,则返回 true
- swift - PBKDF2 密钥派生耗时太长
- html - 如何添加带有 hr 标签的边框底部