简短介绍
大家好,一年一度的双十一又到了。准备好剁手了吗?反正我是看透了套路,什么时候买都差不多(好吧,其实咱穷^_^,求个心理安慰)。今天给大家分享个日期维度表的工具类。
大家好,一年一度的双十一又到了。准备好剁手了吗?反正我是看透了套路,什么时候买都差不多(好吧,其实咱穷^_^,求个心理安慰)。今天给大家分享个日期维度表的工具类。
01
—
为什么要日期维度表
日期维度在数仓中有着很重要的作用。举个栗子:我们展示全年每天商品交易量。如果某天某个商品没有交易量,但是这个日期又得显示出来。那我们要怎么处理呢?此时日期维度表就起到作用了,我们只要用日期维度表做查询主表,就可以很方便的展示每天是否有交易量的数据了。02
—
创建日期维度表
-- dim_dateCREATE TABLE dim_date( id string COMMENT '自增主键id', day_code string COMMENT '日代码', day_long_desc string COMMENT '日完整名称', day_medium_desc string COMMENT '日中等长度名', day_short_desc string COMMENT '日短名', week_code string COMMENT '周代码', week_long_desc string COMMENT '周完整名称', week_medium_desc string COMMENT '周中等长度名', week_short_desc string COMMENT '周短名', week_name string COMMENT '周名称', ten_day_code string COMMENT '旬代码', ten_day_long_desc string COMMENT '旬完整名称', ten_day_medium_desc string COMMENT '旬中等长度名', ten_day_short_desc string COMMENT '旬短名', month_code string COMMENT '月代码', month_long_desc string COMMENT '月完整名称', month_medium_desc string COMMENT '月中等长度名', month_short_desc string COMMENT '月短名', quarter_code string COMMENT '季代码', quarter_long_desc string COMMENT '季完整名称', quarter_medium_desc string COMMENT '季中等长度名', quarter_short_desc string COMMENT '季短名', half_year_code string COMMENT '半年代码', half_long_desc string COMMENT '半年完整名称', half_medium_desc string COMMENT '半年中等长度名', half_short_desc string COMMENT '半年短名', year_code string COMMENT '年代码', year_long_desc string COMMENT '年完整名称', year_medium_desc string COMMENT '年中等长度名', year_short_desc string COMMENT '年短名', all_time_code string COMMENT '全部时间代码', all_time_desc string COMMENT '全部时间名称', day_timespan string COMMENT '日时间跨天', day_end_date string COMMENT '结束日期', week_timespan string COMMENT '周跨天数', week_end_date string COMMENT '周结束日期', ten_day_timespan string COMMENT '旬跨天数', ten_day_end_date string COMMENT '旬结束日期', month_timespan string COMMENT '月跨天数', month_end_date string COMMENT '月结束日期', quarter_timespan string COMMENT '季跨天数', quarter_end_date string COMMENT '季结束日期', half_year_timespan string COMMENT '半年跨天数', half_year_end_date string COMMENT '半年结束日期', year_timespan string COMMENT '年跨天数', year_end_date string COMMENT '年结束日期', week_start_date string COMMENT '周开始日期', month_start_date string COMMENT '月开始时间', quarter_start_date string COMMENT '季度开始时间', workday_flag string COMMENT '是否工作日:1.是 0.否', weekend_flag string COMMENT '是否周末:1.是 0.否', holiday_flag string COMMENT '是否为节假日 1:是,0:否', holiday_name string COMMENT '节假日名称', is_workday string COMMENT '是否上班 1:是,0:否', last_week_day string COMMENT '周的最后一天', last_month_day string COMMENT '月的最后一天', load_time string COMMENT '加载时间')COMMENT '日期维度表'ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' STORED AS TEXTFILE;
03
—
使用Java生成日期维度数据
import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.io.PrintWriter;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class DateDimUtil { /** * 当前日期 + 1天 * 返回:yyyymmdd */ public static String getNowDate(String specifiedDay) { Calendar c = Calendar.getInstance(); Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } c.setTime(date); int day = c.get(Calendar.DATE); c.set(Calendar.DATE, day + 1); return new SimpleDateFormat("yyyyMMdd").format(c.getTime()); } /** * 当前日期,是星期几 */ public static int getWeekDay(String specifiedDay) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); int week_of_year = c.get(Calendar.DAY_OF_WEEK); week_of_year = week_of_year - 1; if (week_of_year == 0) { week_of_year = 7; } return week_of_year; } /** * 当前日期,属于年的第几周 */ public static int getWeekofYear(String specifiedDay) { Calendar c = Calendar.getInstance(); Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } c.setTime(date); c.setFirstDayOfWeek(Calendar.MONDAY); int week = c.get(Calendar.WEEK_OF_YEAR); return week; } /** * 当前日期,格式化转换 */ public static String yyyymmdd(String specifiedDay,String patten) throws ParseException{ Date date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); return new SimpleDateFormat(patten).format(date); } /** * 当前日期,所属月多少天 */ public static int getMDaycnt(String specifiedDay) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); int i = c.get(Calendar.DAY_OF_MONTH); return i; } /** * 当前日期,所属月旬数 * 三旬: 上旬1-10日 中旬11-20日 下旬21-31日 * 返回: 1\2\3 */ public static int getTenDay(String specifiedDay) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); int i = c.get(Calendar.DAY_OF_MONTH); if (i < 11) return 1; else if (i < 21) return 2; else return 3; } /** * 当前日期,所属月旬数 * 三旬: 上旬1-10日 中旬11-20日 下旬21-31日 * 返回: 1\2\3 */ public static String getTenDays(String specifiedDay) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); int i = c.get(Calendar.DAY_OF_MONTH); if (i < 11) return "上旬"; else if (i < 21) return "中旬"; else return "下旬"; } /** * 当前日期,所属月,三旬: 每旬多少天 */ public static int getTenDayscnt(String specifiedDay) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); int i = c.get(Calendar.DAY_OF_MONTH); if (i < 11){ return 10; } else if (i < 21) { return 10; }else{ return Integer.parseInt(getMonthEndTime(specifiedDay).substring(6,8)) - 20; } } /** * 当前日期,所属季度 */ public static int getQuarter(String specifiedDay) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); int currentMonth = c.get(Calendar.MONTH) + 1; int dt = 0; try { if (currentMonth <= 3) dt = 1; else if (currentMonth <= 6) dt = 2; else if (currentMonth <= 9) dt = 3; else if (currentMonth <= 12) dt = 4; } catch (Exception e) { e.printStackTrace(); } return dt; } /** * 当前日期,所属季度天数 */ public static int getQuarterCntday(String specifiedDay) { int cnt_d = 0; int q = getQuarter(specifiedDay); if (q == 1) { specifiedDay = specifiedDay.substring(0,4); specifiedDay = getMonthEndTime(specifiedDay + "0201"); cnt_d = getMDaycnt(specifiedDay); cnt_d = 31 + cnt_d + 31; }else if (q == 2) { cnt_d = 30 + 31 + 30; }else if (q == 3) { cnt_d = 31 + 31 + 30; }else if (q == 4) { cnt_d = 31 + 30 + 31; } return cnt_d; } /** * 当前日期,所属年多少天 */ public static int getYearCntday(String specifiedDay) { int cnt_d; specifiedDay = specifiedDay.substring(0,4); specifiedDay = getMonthEndTime(specifiedDay + "0201"); cnt_d = getMDaycnt(specifiedDay); cnt_d = 31 + cnt_d + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31; return cnt_d; } /** * 当前日期,所属前半年 或 后半年 天数据 */ public static int getHyearCntday(String specifiedDay) { int cnt_d = 0; int q = getHalfYear(specifiedDay); if (q == 1) { specifiedDay = specifiedDay.substring(0,4); specifiedDay = getMonthEndTime(specifiedDay + "0201"); cnt_d = getMDaycnt(specifiedDay); cnt_d = 31 + cnt_d + 31 + 30 + 31 + 30; }else if (q == 2) { cnt_d = 31 + 31 + 30 + 31 + 30 + 31; } return cnt_d; } /** * 当前日期,所属前半年 或 后半年 * 返回:1\2 */ public static int getHalfYear(String specifiedDay) { int dt = getQuarter(specifiedDay); if (dt <= 2) { dt = 1; }else { dt = 2; } return dt; } /** * 当前日期,所属前半年 或 后半年 * 返回:上半年\下半年 */ public static String getHalfYears(String specifiedDay) { int dt = getQuarter(specifiedDay); if (dt<=2) { return "上半年"; } return "下半年"; } /** * 当前日期,所属月的开始时间 */ public static String getMonthStartTime(String specifiedDay) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); String dt = ""; try { c.set(Calendar.DATE, 1); dt = new SimpleDateFormat("yyyyMMdd").format(c.getTime()); } catch (Exception e) { e.printStackTrace(); } return dt; } /** * 当前日期,所属月的结束时间 */ public static String getMonthEndTime(String specifiedDay) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); String dt = ""; try { c.set(Calendar.DATE, 1); c.add(Calendar.MONTH, 1); c.add(Calendar.DATE, -1); dt = new SimpleDateFormat("yyyyMMdd").format(c.getTime()); } catch (Exception e) { e.printStackTrace(); } return dt; } /** * 当前日期,所属周的第一天(周一),的日期 */ public static String getWeekStartTime(String specifiedDay,String pattern) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); try { SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); int weekday = c.get(Calendar.DAY_OF_WEEK) - 2; c.add(Calendar.DATE, -weekday); c.setTime(longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00.000")); } catch (Exception e) { e.printStackTrace(); } return new SimpleDateFormat(pattern).format(c.getTime()); } /** * 当前日期,所属周的最后一天(周日),的日期 */ public static String getWeekEndTime(String specifiedDay,String pattern) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); try { SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); int weekday = c.get(Calendar.DAY_OF_WEEK); c.add(Calendar.DATE, 8 - weekday); c.setTime(longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59.999")); } catch (Exception e) { e.printStackTrace(); } return new SimpleDateFormat(pattern).format(c.getTime()); } /** * 当前日期,所属旬结束时间 */ public static String getTenDayEndTime(String specifiedDay) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } int ten = getTenDay(specifiedDay); if (ten == 1) { SimpleDateFormat df = new SimpleDateFormat("yyyyMM10"); return df.format(date); } else if (ten == 2) { SimpleDateFormat df = new SimpleDateFormat("yyyyMM20"); return df.format(date); } else { return getMonthEndTime(specifiedDay); } } /** * 当前日期,所属季度的开始时间 */ public static String getQuarterStartTime(String specifiedDay) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); int currentMonth = c.get(Calendar.MONTH) + 1; String dt = ""; try { if (currentMonth <= 3) c.set(Calendar.MONTH, 0); else if (currentMonth <= 6) c.set(Calendar.MONTH, 3); else if (currentMonth <= 9) c.set(Calendar.MONTH, 6); else if (currentMonth <= 12) c.set(Calendar.MONTH, 9); c.set(Calendar.DATE, 1); dt = new SimpleDateFormat("yyyyMMdd").format(c.getTime()); } catch (Exception e) { e.printStackTrace(); } return dt; } /** * 当前日期,所属季度的结束时间 */ public static String getQuarterEndTime(String specifiedDay) { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } Calendar c = Calendar.getInstance(); c.setTime(date); int currentMonth = c.get(Calendar.MONTH) + 1; String dt = ""; try { if (currentMonth <= 3) { c.set(Calendar.MONTH, 2); c.set(Calendar.DATE, 31); } else if (currentMonth <= 6) { c.set(Calendar.MONTH, 5); c.set(Calendar.DATE, 30); } else if (currentMonth <= 9) { c.set(Calendar.MONTH, 8); c.set(Calendar.DATE, 30); } else if (currentMonth <= 12) { c.set(Calendar.MONTH, 11); c.set(Calendar.DATE, 31); } dt = new SimpleDateFormat("yyyyMMdd").format(c.getTime()); } catch (Exception e) { e.printStackTrace(); } return dt; } /** * 当前日期,是否节假日 * */ public static int getJjr(String specifiedDay,String j) { String[] f = { "0101" , "0405" , "0501" , "1001" }; String sub = specifiedDay.substring(4,8); if (!"2".equals(j)) {//0工作日、1周末、2节日、3调休 for (String s : f) { if (s.equals(sub)) { return 1; } } return 0; }else{ return 1; } } /** * 当前日期,节假日名称 * http://timor.tech/api/holiday?date=20190505 */ public static String getJjrname(String specifiedDay) { String[] f = { "0101" , "0405" , "0501" , "1001" }; String[] f1 = { "元旦节" , "清明节" , "劳动节" , "国庆节" }; String sub = specifiedDay.substring(4,8); for (int k = 0 ; k < f.length ; k++ ) { if(f[k].equals(sub)){ return f1[k]; } } return "-"; } /** * 当前日期,是否上班 */ public static int iswork(String specifiedDay,String j) { String[] f = { "0101" , "0405" , "0501" , "1001" }; String sub = specifiedDay.substring(4,8); //0工作日、1周末、2节日、3调休 if ("0".equals(j) || "3".equals(j)) { for (String s : f) { if (s.equals(sub)) { return 0; } } return 1; } else { return 0; } } /** * 循环计算 */ public static void anyDate(String start_day, String end_day, int i) throws Exception { while (true) { start_day = getNowDate(start_day); if (start_day.equals(end_day)) { break; } else { System.out.println(start_day); StringBuffer rel = new StringBuffer(); String year_s = start_day.substring(0, 4); String month_s = start_day.substring(4, 6); String day_long_desc = yyyymmdd(start_day,"yyyy年MM月dd日");// 日完整名称 yyyy年MM月dd日 String day_medium_desc = yyyymmdd(start_day,"dd日");// 日中等长度名 dd日 String day_short_desc = yyyymmdd(start_day,"yyyy-MM-dd");// 日短名 yyyy-MM-dd int ws = getWeekofYear(start_day); String n_year = year_s; if (ws == 1 && "12".equals(month_s)){ n_year = (Integer.parseInt(year_s) + 1) + ""; } String week_code = n_year + "W" + ws;// 周代码 2019W02 String week_long_desc = n_year + "年第" + ws + "周"; //周完整名称String 2019年第02周 String week_medium_desc = "第" + ws + "周"; //周中等长度名String 第02周 String week_short_desc = n_year + "-W" + ws ; //周短名String String week_name = yyyymmdd(start_day,"EEEE"); //旬代码String String ten_day_code =year_s + month_s + "X" + getTenDay(start_day); //旬完整名称String String ten_day_long_desc = year_s +"年"+ month_s + "月" + getTenDays(start_day); //旬中等长度名String String ten_day_medium_desc = getTenDays(start_day); //旬短名String String ten_day_short_desc = year_s +"-"+ month_s + "-X" + getTenDay(start_day); //月代码String String month_code = year_s + month_s; //月完整名称String String month_long_desc = year_s + "年" + month_s + "月"; //月中等长度名String String month_medium_desc = month_s + "月"; //月短名String String month_short_desc = year_s + "-" + month_s; //季代码String String qu=getQuarter(start_day)+ ""; String quarter_code = year_s + "Q"+ qu; //季完整名称String String quarter_long_desc = year_s + "年第" + qu + "季度"; //季中等长度名String String quarter_medium_desc = "第" + qu + "季度"; //季短名String String quarter_short_desc = year_s + "-Q" + qu; //半年代码String String half_year_code =year_s + "H" + getHalfYear(start_day); //半年完整名称String String half_long_desc = year_s + "年" +getHalfYears(start_day); //半年中等长度名String String half_medium_desc = getHalfYears(start_day); //半年短名String String half_short_desc = year_s + "-H" + getHalfYear(start_day); //年完整名称String String year_long_desc = year_s + "年"; //年中等长度名String String year_medium_desc = year_s + "年"; //年短名String //全部时间代码String String all_time_code = "ALL"; //全部时间名称String String all_time_desc = "ALL_TIME"; //日时间跨天String String day_timespan = "1"; //周跨天数String String week_timespan = "7"; //周结束日期String String week_end_date = getWeekEndTime(start_day,"yyyy-MM-dd");; //旬跨天数String String ten_day_timespan = getTenDayscnt(start_day)+""; //旬结束日期String String ten_day_end_date = getTenDayEndTime(start_day); //月跨天数String String month_timespan = getMonthEndTime(start_day).substring(6,8)+""; //月结束日期String String month_end_date = getMonthEndTime(start_day); //季跨天数String String quarter_timespan = getQuarterCntday(start_day)+""; //季结束日期String String quarter_end_date = getQuarterEndTime(start_day); //半年跨天数String String half_year_timespan = getHyearCntday(start_day)+""; //半年结束日期String String half_year_end_date = year_s + "0630"; //年跨天数String String year_timespan = getYearCntday(start_day)+""; //年结束日期String String year_end_date = year_s + "1231"; //周开始日期String String week_start_date = getWeekStartTime(start_day,"yyyyMMdd"); //月开始时间String String month_start_date = getMonthStartTime(start_day); //季度开始时间String String quarter_start_date = getQuarterStartTime(start_day); //是否工作日:1.是 0.否 String workday_flag = getWeekDay(start_day) <= 5 ? "1" : "0" ; //是否周末:1.是 0.否 String weekend_flag = getWeekDay(start_day) > 5 ? "1" : "0"; //是否为节假日 1:是,0:否 -: 未知 String holiday_flag = "-";//暂时默认未知,或者调用接口处理 //节假日名称String String holiday_name = getJjrname(start_day); //是否上班 1:是,0:否 -: 未知 String is_workday = "-";//暂时默认未知,或者调用接口处理 String last_week_day = getWeekEndTime(start_day,"yyyy-MM-dd"); //周的最后一天String String last_month_day = yyyymmdd(getMonthEndTime(start_day),"yyyy-MM-dd"); //月的最后一天String Date d = new Date(); String load_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d);//加载时间 rel.append(i).append("\t"); rel.append(start_day).append("\t"); rel.append(day_long_desc).append("\t"); rel.append(day_medium_desc).append("\t"); rel.append(day_short_desc).append("\t"); rel.append(week_code).append("\t"); rel.append(week_long_desc).append("\t"); rel.append(week_medium_desc).append("\t"); rel.append(week_short_desc).append("\t"); rel.append(week_name).append("\t"); rel.append(ten_day_code).append("\t"); rel.append(ten_day_long_desc).append("\t"); rel.append(ten_day_medium_desc).append("\t"); rel.append(ten_day_short_desc).append("\t"); rel.append(month_code).append("\t"); rel.append(month_long_desc).append("\t"); rel.append(month_medium_desc).append("\t"); rel.append(month_short_desc).append("\t"); rel.append(quarter_code).append("\t"); rel.append(quarter_long_desc).append("\t"); rel.append(quarter_medium_desc).append("\t"); rel.append(quarter_short_desc).append("\t"); rel.append(half_year_code).append("\t"); rel.append(half_long_desc).append("\t"); rel.append(half_medium_desc).append("\t"); rel.append(half_short_desc).append("\t"); rel.append(year_s).append("\t"); rel.append(year_long_desc).append("\t"); rel.append(year_medium_desc).append("\t"); rel.append(year_s).append("\t"); rel.append(all_time_code).append("\t"); rel.append(all_time_desc).append("\t"); rel.append(day_timespan).append("\t"); rel.append(start_day).append("\t"); rel.append(week_timespan).append("\t"); rel.append(week_end_date).append("\t"); rel.append(ten_day_timespan).append("\t"); rel.append(ten_day_end_date).append("\t"); rel.append(month_timespan).append("\t"); rel.append(month_end_date).append("\t"); rel.append(quarter_timespan).append("\t"); rel.append(quarter_end_date).append("\t"); rel.append(half_year_timespan).append("\t"); rel.append(half_year_end_date).append("\t"); rel.append(year_timespan).append("\t"); rel.append(year_end_date).append("\t"); rel.append(week_start_date).append("\t"); rel.append(month_start_date).append("\t"); rel.append(quarter_start_date).append("\t"); rel.append(workday_flag).append("\t"); rel.append(weekend_flag).append("\t"); rel.append(holiday_flag).append("\t"); rel.append(holiday_name).append("\t"); rel.append(is_workday).append("\t"); rel.append(last_week_day).append("\t"); rel.append(last_month_day).append("\t"); rel.append(load_time); writeFile(rel); } i++ ; } } // 写入文件(增量写入,不会覆盖原有内容) public static void writeFile(StringBuffer rel) { // 本地存放路径 String file_path = "d:/date_dim.txt" ; FileWriter fw_s = null; PrintWriter pw_s = null; try { File f_hive = new File(file_path);/* 生成路径 */ fw_s = new FileWriter(f_hive, true); pw_s = new PrintWriter(fw_s); pw_s.println(rel); pw_s.flush(); fw_s.flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (pw_s != null) pw_s.close(); if (fw_s != null) { try { fw_s.close(); } catch (IOException e) { e.printStackTrace(); } } } } // 测试 public static void main(String[] args) throws Exception { String start_day = "20191031";/*开始日期*/ String end_day = "20201231";/*结束日期*/ anyDate(start_day,end_day,1);//开始时间-结束时间-续跑ID(便于后续增量生成) System.out.println("success !"); }}
说明:最后将生成的数据文件导入至创建的hive日期维度表中即可。记得验证下数据哦^_^
04
—
小结
其实生成日期维度表是很简单的。可以通过很多编程语言来实现,sql\python\java...等等都可以。大家可以根据各自的习惯来处理。有好的建议,可以留言告知下哦,相互学习嘛。如果大家喜欢可关注公众号,感谢!