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

AWS Glue写入DynamicFrame自动添加双引号,如何禁用?

如何禁用AWS Glue写入CSV时自动添加的双引号?

我用以下代码将DynamicFrame写入S3,但包含空格的记录被自动加上了双引号,想禁用这个行为:

format_options = {"optimizePerformance": True, "separator": "\t"}
glueContext.write_dynamic_frame.from_options(
    frame=dyf_frame.coalesce(1),
    connection_type="s3",
    connection_options={
        "path": outpath,
        "compression": "gzip",
        "groupFiles": "inPartition",
    },
    format="csv",
    format_options=format_options,
)

当前输出(output.txt.gz):

name
NAME1
"NAME2 NAME2SURNAME"
NAME3
"NAME4 NAME4"
"NAME5 NAME5"

期望输出:

name
NAME1
NAME2 NAME2SURNAME
NAME3
NAME4 NAME4
NAME5 NAME5

这些文件要通过Redshift COPY命令加载,命令如下:

copy staging.table(
    name
    )
from 's3://output.txt.gz'
iam_role 'arn:aws:iam::693485840050:role/test'
delimiter '\t'  gzip
IGNOREBLANKLINES
IGNOREHEADER 1
COMPUPDATE ON
NULL AS '\000000000000000000';

解决方案

在format_options中添加"quoteChar": ""参数,强制禁用引号包裹逻辑:

format_options = {
    "optimizePerformance": True,
    "separator": "\t",
    "quoteChar": ""
}
glueContext.write_dynamic_frame.from_options(
    frame=dyf_frame.coalesce(1),
    connection_type="s3",
    connection_options={
        "path": outpath,
        "compression": "gzip",
        "groupFiles": "inPartition",
    },
    format="csv",
    format_options=format_options,
)

这个参数会告诉Glue的CSV写入器不要对包含空格或特殊字符的字段添加引号。因为你的分隔符是制表符,字段内的空格不会影响分隔逻辑,设置空引号字符后就能得到无引号的输出。

如果开启optimizePerformance后上述参数不生效,可以尝试添加"disableQuoteChar": True参数,同样能达到禁用引号的效果。

内容的提问来源于stack exchange,提问作者D.E. Veloper

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 06:05:05