You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在从S3读取CSV时为Dynamic Frame配置编码选项?

解决Glue Dynamic Frame读取CSV编码配置问题

你当前代码的问题在于encoding参数的配置逻辑不符合AWS Glue的要求,以下是正确的配置方式及排查要点:

正确编码配置方案

方案1:标准格式配置(适配Glue 3.0+)

对于Glue 3.0及以上版本,CSV编码参数需放在format_options中,同时要使用Glue支持的标准编码标识符:

csv_dynamicframe = glueContext.create_dynamic_frame.from_options(
    connection_type="s3",
    connection_options={
        "paths": [root_path]
    },
    format="csv",
    format_options={
        "withHeader": True,
        "separator": ",",
        "encoding": "utf-8"  # 使用Glue支持的编码字符串,如"gbk"、"iso-8859-1"等
    },
    transformation_ctx="csv_dynamicframe",
    schema=dynamic_frame_catalog.schema()
)

方案2:连接参数传递编码(兼容旧版Glue)

如果上述配置无效,可尝试将编码参数移至connection_options中,适配部分旧版Glue或特殊存储场景:

csv_dynamicframe = glueContext.create_dynamic_frame.from_options(
    connection_type="s3",
    connection_options={
        "paths": [root_path],
        "encoding": "utf-8"
    },
    format="csv",
    format_options={
        "withHeader": True,
        "separator": ","
    },
    transformation_ctx="csv_dynamicframe",
    schema=dynamic_frame_catalog.schema()
)

额外排查要点

  • 确认文件实际编码:如果CSV不是UTF-8格式(比如GBK、ISO-8859-1),需替换为对应编码标识符
  • 移除schema测试:先不指定schema参数,让Glue自动推断,排查是否是schema与编码不兼容导致的问题
  • 检查Glue版本:Glue 2.0及以下版本对部分编码支持有限,建议升级至3.0+版本

内容的提问来源于stack exchange,提问作者adk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 00:32:09