蜂巢日期函数来实现星期 [英] Hive date function to achieve day of week

查看:164
本文介绍了蜂巢日期函数来实现星期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个解决办法或蜂房日期功能,它允许星期,

I'm looking for a workaround or hive date functions that gives day of the week ,

周日 - 1
周一 - 2
周二 - 3
周三 - 4
周四 - 5
周五 - 6
周六 - 7

Sunday - 1 Monday - 2 Tuesday - 3 Wednesday - 4 Thursday - 5 Friday - 6 Saturday - 7

要求在细节:我正在寻找这需要日期(年月日)作为输入和输出星期按上表中的函数

Requirement in detail : I'm looking for a function that takes date string (YYYYMMDD) as input and outputs the day of the week as per the above table.

推荐答案

正如我所说的,你需要写一个UDF,将接受一个字符串作为参数,并返回一个字符串。
在UDF中你需要做以下步骤:

As I said you need to write a UDF which will accept a string as parameter and return a string. Inside the UDF you need to do these steps:

1)使用解析输入字符串的的SimpleDateFormat(年月日)

1.) Parse the input string using SimpleDateFormat(YYYYMMDD)

2)使用下面code拿到星期:

2.) Use the Below code to get the day of week:

Calendar c = Calendar.getInstance();
c.setTime(yourDate);
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);

3)。在 case语句使用该一周中的某天让你平日字符串,返回该字符串。

3.) Use this dayOfWeek value in a case statement to get your weekday String and return that string.

希望这有助于...!

这篇关于蜂巢日期函数来实现星期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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