【问题标题】:Converting hive Timestamp functions to Redshift syntax将 hive Timestamp 函数转换为 Redshift 语法
【发布时间】:2022-01-12 08:27:19
【问题描述】:

我需要将用 hive-SQL 编写的脚本转换为 Redshift 的 SQL。
我被以下部分卡住了:

select date_format(date_add(date_sub(current_date,cast(from_unixtime(unix_timestamp(current_date, 'yyyy-MM-dd'),'u') as int)),7), 'dd MMM')

没有使用 hive-sql 的时间戳功能的经验,我无法在 redshift 中重写这一行。
`current_date` 实际上是一个时间戳列,在此列上完成了一些计算。
请提供一些见解/建议。这将非常有帮助。

【问题讨论】:

    标签: hive amazon-redshift hiveql unix-timestamp amazon-redshift-spectrum


    【解决方案1】:

    您的 Hive 查询返回下周日,如果我没记错的话,如果是周日,则返回当前日期。您可以使用 date_part 来检查哪一天是星期几,使用 next_day 来检查下周日。像这样的东西(未经测试,没有 Redshift):

    to_char(case when date_part(dow,current_date) = 0 then current_date 
                  else next_day(current_date ,'Sunday')
             end, 'DD MON')
    

    【讨论】:

    • 非常感谢@leftjoin。现在我很清楚蜂巢查询本质上在做什么。您的查询运行良好。
    猜你喜欢
    • 2014-12-24
    • 2015-06-18
    • 1970-01-01
    • 2019-12-10
    • 1970-01-01
    • 2021-11-15
    • 2020-12-15
    • 2022-01-02
    • 1970-01-01
    相关资源
    最近更新 更多