AWS 粘合作业将字符串映射到日期和时间格式,同时从 csv 转换为镶木地板 [英] AWS glue job to map string to date and time format while converting from csv to parquet

查看:33
本文介绍了AWS 粘合作业将字符串映射到日期和时间格式,同时从 csv 转换为镶木地板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在从 csv 转换为 parquet 时,使用 AWS 胶水 ETL 作业跟随 csv 中的映射字段读取为字符串到日期和时间类型.这是实际的 csv 文件

while converting from csv to parquet, using AWS glue ETL job following mapped fields in csv read as string to date and time type. this is the actual csv file

映射和转换后,日期字段为空,时间与今天的日期连接

after mapping and converting, date filed is empty and time is concatenated with today's date

如何以正确的日期和时间格式进行转换?

How to convert with proper date and time format?

推荐答案

它使用 presto 数据类型,因此数据应该采用正确的格式

It uses presto datatypes so data should be in correct format

DATE 日历日期(年、月、日).

DATE Calendar date (year, month, day).

示例:日期'2001-08-22'

Example: DATE '2001-08-22'

TIME 没有时间的时间(小时、分钟、秒、毫秒)区.这种类型的值在会话时间被解析和呈现区域.

TIME Time of day (hour, minute, second, millisecond) without a time zone. Values of this type are parsed and rendered in the session time zone.

示例:TIME '01:02:03.456'

Example: TIME '01:02:03.456'

TIMESTAMP 即时时间,包括日期和时间没有时区.这种类型的值被解析并呈现在会话时区.

TIMESTAMP Instant in time that includes the date and time of day without a time zone. Values of this type are parsed and rendered in the session time zone.

示例:TIMESTAMP '2001-08-22 03:04:05.321'

Example: TIMESTAMP '2001-08-22 03:04:05.321'

您可以使用:

from pyspark.sql.functions import to_timestamp, to_date, date_format

df = df.withColumn(col, to_timestamp(col, 'dd-MM-yyyy HH:mm'))
df = df.withColumn(col, to_date(col, 'dd-MM-yyyy'))
df = df.withColumn(col, date_format(col, 'HH:mm:ss'))

这篇关于AWS 粘合作业将字符串映射到日期和时间格式,同时从 csv 转换为镶木地板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆