spark unix_timestamp 数据类型不匹配 [英] spark unix_timestamp data type mismatch

查看:41
本文介绍了spark unix_timestamp 数据类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助指导我需要提交 from_unixtime 什么数据类型或格式才能使 spark from_unixtime() 函数工作吗?

Could someone help guide me in what data type or format I need to submit from_unixtime for the spark from_unixtime() function to work?

当我尝试以下操作时,它可以工作,但不响应 current_timestamp.

When I try the following it works, but responds not with current_timestamp.

from_unixtime(current_timestamp())

回复如下:

fromunixtime(currenttimestamp(),yyyy-MM-dd HH:mm:ss)

当我尝试输入时

from_unixtime(1392394861,"yyyy-MM-dd HH:mm:ss.SSSS")

以上只是因为类型不匹配而失败:

The above simply fails with a type mismatch:

错误:类型不匹配;找到:整数(1392394861)需要:org.apache.spark.sql.Columnfrom_unixtime(1392394861,"yyyy-MM-dd HH:mm:ss.SSSS")

error: type mismatch; found : Int(1392394861) required: org.apache.spark.sql.Column from_unixtime(1392394861,"yyyy-MM-dd HH:mm:ss.SSSS")

我错过了什么?我尝试了许多不同的方法,并尝试阅读有关在 spark 中使用日期/时间的文档,但我尝试过的每个示例都因类型不匹配而失败.

What am I missing? I've tried a number of different things and tried reading documentation on using date/time in spark and every example I've tried fails with type mismatches.

推荐答案

使用 lit() 创建一列文字值,如下所示:

Use lit() to create a column of literal value, like this:

from_unixtime(lit(1392394861), "yyyy-MM-dd HH:mm:ss.SSSS")

或者,正如 zero323 提到的:

or, as zero323 mentioned:

from_unixtime(current_timestamp().cast("long")) 

这篇关于spark unix_timestamp 数据类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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