AWS胶 - 从时间戳字段创建日期分区
字段
时间戳 | 框 | 的 |
---|---|---|
具有 | 具有 | 数据 |
| | |
代码>应用绘制将数据保存到新的S3位置。目前,我已经添加了 id 和版本通过在Visual编辑器中选择这些字段,并使用以下结构保存我的数据: id = 1/version = 2/
我想解析时间戳并提取日期值,以便文件系统结构为 id = 1/version = 2/dt = 2022-01-01-01/
。但是,在视觉编辑器中,我只能选择时间戳,并且无法在现场执行任何操纵。我猜我需要更改代码,但是我不确定如何。
代码:
import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job
args = getResolvedOptions(sys.argv, ["JOB_NAME"])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args["JOB_NAME"], args)
# Script generated for node S3 bucket
S3bucket_node1 = glueContext.create_dynamic_frame.from_options(
format_options={},
connection_type="s3",
format="parquet",
connection_options={"paths": ["s3://my-data"], "recurse": True},
transformation_ctx="S3bucket_node1",
)
# Script generated for node ApplyMapping
ApplyMapping_node2 = ApplyMapping.apply(
frame=S3bucket_node1,
mappings=[
("timestamp", "timestamp", "timestamp", "timestamp"),
("id", "string", "id", "string"),
("version", "string", "version", "string"),
],
transformation_ctx="ApplyMapping_node2",
)
# Script generated for node S3 bucket
S3bucket_node3 = glueContext.write_dynamic_frame.from_options(
frame=ApplyMapping_node2,
connection_type="s3",
format="glueparquet",
connection_options={
"path": "s3://target-data",
"partitionKeys": ["id", "version"],
},
format_options={"compression": "gzip"},
transformation_ctx="S3bucket_node3",
)
job.commit()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用。
将此方法添加到您的脚本中,
在
ApplyMapping
步骤之后插入地图变换。将写入更新为S3步骤,请注意更改为
frame
和PartitionKeys
。Use the Map Class.
Add this method to your script
Insert the Map Transform after the
ApplyMapping
step.Update the write to S3 step, notice the change to
frame
andpartitionKeys
.