首页 > 解决方案 > Spark错误地将整数转换为`struct`

问题描述

在火花工作中,我正在使用

.withColumn("year", year(to_timestamp(lit(col("timestamp")))))

该代码曾经有效。但现在我得到了错误:

"cannot resolve 'CAST(`timestamp` AS TIMESTAMP)' due to data type mismatch: cannot cast struct<int:int,long:bigint> to timestamp;"

我看起来像 spark 正在将我的时间戳列读取为 astruct<int:int,long:bigint>而不是 aint

我怎样才能防止这种情况?

上下文初始数据在 jsonline 中。我使用 AWS GLUE 阅读它glueContext.create_dynamic_frame.from_catalog。在 GLUE 目录中,时间戳列是键入的int

标签: apache-sparkpysparkaws-glue

解决方案


最后我以这种方式解决了它:

GF_resolved = ResolveChoice.apply(
    frame=GF_raw,
    specs=[("timestamp", "cast:int")],
    transformation_ctx="resolve timestamp type",
)

ResolveChoice 是 AWS Glue DynamicFrame 上可用的方法


推荐阅读