如何在胶粘作业中添加当前时间戳(额外的列),以便输出数据具有额外的列 [英] How to I add a current timestamp (extra column) in the glue job so that the output data has an extra column
本文介绍了如何在胶粘作业中添加当前时间戳(额外的列),以便输出数据具有额外的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在胶粘作业中添加当前时间戳(额外的列),以便输出数据具有额外的列.在这种情况下:
How to I add a current timestamp (extra column) in the glue job so that the output data has an extra column. In this case:
模式源表: Col1,Col2
Schema Source Table: Col1, Col2
上胶后.
目标架构: Col1,Col2,Update_Date(当前时间戳记)
Schema of Destination: Col1, Col2, Update_Date(Current Timestamp)
推荐答案
我不确定是否可以使用DynamicFrame
进行粘合,但是您可以轻松地转换为Spark Dataframe,然后使用withColumn
方法.您需要使用lit
函数将文字值放入新列中,如下所示.
I'm not sure if there's a glue native way to do this with the DynamicFrame
, but you can easily convert to a Spark Dataframe and then use the withColumn
method. You will need to use the lit
function to put literal values into a new column, as below.
from pyspark.sql.functions import lit
glue_df = glueContext.create_dynamic_frame.from_catalog(...)
spark_df = glue_df.toDF()
spark_df = spark_df.withColumn('some_date', lit(datetime.now()))
一些参考文献:
- Glue DynamicFrame toDF()
- Spark Dataframe withColumn()
这篇关于如何在胶粘作业中添加当前时间戳(额外的列),以便输出数据具有额外的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文