我正在使用胶水工作。 Glue 作业将输入读取为清单文件,其中包含 JSON 数据文件。将其读取到数据帧后,我们应用某种处理/转换,然后 Glue 作业将数据以 Parquet 格式写入不同的 S3 位置。但是镶木地板文件列的数据类型正在映射到对象而不是字符串。
这是我尝试过的代码:
df = df.withColumn("my_column", col("my_column").cast("string"))
And I am using below code to write it on s3
write_to_s3 = GLUE_CONTEXT.write_dynamic_frame.from_options(
frame=transformed_with_contracts,
connection_type='s3',
format='parquet',
connection_options={
'path': f's3://{destination_s3_bucket}/{destination_s3_path}'
},
format_options={},
transformation_ctx='write_to_s3',
)
镶木地板文件列的数据类型被映射到对象而不是字符串,这是不期望的。有什么想法吗?
从上面的评论中我可以得出结论,问题不在于 Glue 作业,而是按预期写入镶木地板文件
在 Pandas 中,由于字符串数据类型具有可变长度,因此默认情况下存储为对象数据类型。请参阅以下解决方法
使用 awswrangler 模块对其进行测试,该模块将列视为字符串而不是对象。
import awswrangler as wr
df = wr.s3.read_parquet(path="s3://<bucket>/<path>/<file>.parquet")
df.to_parquet("s3://<bucket>/path>/<file>.parquet")
df.info()
尝试用这个代替!