【问题标题】:Reading Dynamic DataTpes from S3 with AWS Glue使用 AWS Glue 从 S3 读取动态 DataTpes
【发布时间】:2021-11-22 22:25:36
【问题描述】:

我将 json 存储在 S3 中。有时units 存储为字符串,有时存储为整数。不幸的是,这是一个错误,我现在在源 json 中有数十亿条数据类型混合匹配的记录。

示例:

{
  "other_stuff": "stuff"
  "units": 2,
{
{
  "other_stuff": "stuff"
  "units": "2",
{

我想动态判断它是否为字符串/整数,然后将其作为整数定位到 AWS Redshift。

如果我的映射是:("units", "string", "units", "int"),则只有“字符串”值会被正确转换。如果我这样做 ("units", "int", "units", "int") 则相反,只有“整数”才能工作。

如何动态转换源记录,并始终将其作为整数加载到 Redshift。您可以假设,所有值都是数字,而不是 null,并且该属性保证存在。

【问题讨论】:

  • 也许有一些想法here。还有相关问题here.

标签: python amazon-web-services pyspark aws-glue


【解决方案1】:

您可以使用 Glue 中的 ResolveChoices 函数。

resolved_choices = df.resolveChoice(
    specs=[
        ('units', 'cast:int')
    ]
)

【讨论】:

  • 你是在应用映射之前还是之后这样做?
  • 你需要先做。
  • 谢谢,这成功了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-28
  • 2021-10-06
  • 1970-01-01
  • 2018-06-29
相关资源
最近更新 更多