【发布时间】:2019-09-10 05:04:03
【问题描述】:
我有一列是整数 201908。我需要将其作为 2019 年 8 月。
我知道在 SQl 中,这很容易做到:如果 salesmonth 是列的名称
UPPER(FORMAT(cast(cast(salesmonth as varchar(10)) + '01' as date),'MMM-yyyy'))
如何在 Hive 中执行此操作?
我将 salesmonth 转换为 varchar 并添加 01 使其成为 20190801。我尝试将 date_parse 转换为 %MMM-%yy,但我很确定我做得不对。
select salesmonth, concat(cast(salesmonthas varchar(10)),'01') as t1
,date_format(concat(cast(salesmonth as varchar(10)),'01'),'%MMM-%yyyy') as t2
from ${db['PL_SALES']} where salesmonth= 201908 limit 10
预计产出:8 月 19 日
错误:Invalid_Function_Argument。无效格式:20190801
编辑:
使用 Case 语句更容易处理 - 但我希望避免使用大小写并寻找与 SQL 类似的格式。
【问题讨论】:
-
问题的标记有些含糊。您查询的是基于 Presto 的 Hive 还是 Athena? (我假设后者回答。)
标签: presto amazon-athena