Last active
November 25, 2019 06:49
-
-
Save Jiezhi/7331b001ab897c068efb1d84ec0c59c9 to your computer and use it in GitHub Desktop.
[Hive]Create Date Dim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE IF NOT EXISTS common_ods; | |
CREATE TABLE IF NOT EXISTS common_ods.dim_date AS WITH dates AS | |
(SELECT date_add("${start_day}", a.pos) AS d | |
FROM | |
(SELECT posexplode(split(repeat("o", datediff("${end_day}", "${start_day}")), "o"))) a) | |
SELECT row_number() OVER ( | |
ORDER BY d) date_sk, | |
d AS d, | |
year(d) AS YEAR, | |
month(d) AS MONTH, | |
day(d) AS DAY, | |
date_format(d, | |
'u') AS daynumber_of_week, | |
date_format(d, | |
'EEEE') AS dayname_of_week, | |
date_format(d, | |
'D') AS daynumber_of_year | |
FROM dates | |
SORT BY d ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment