当前位置: 首页 > news >正文

网站搭建好后被移动宽带屏蔽怎么办百度一下你就知道首页

网站搭建好后被移动宽带屏蔽怎么办,百度一下你就知道首页,如何搭建公司官网,宝安网站制作众所周知 hive 的时间处理异常繁琐且在一些涉及日期的统计场景中会写较长的 sql,例如:周累计、周环比等;本文将使用维表的形式降低时间处理的复杂度,提前计算好标准时间字符串未来可能需要转换的形式。 一、表设计 结合业务场景常…

众所周知 hive 的时间处理异常繁琐且在一些涉及日期的统计场景中会写较长的 sql,例如:周累计、周环比等;本文将使用维表的形式降低时间处理的复杂度,提前计算好标准时间字符串未来可能需要转换的形式。

一、表设计

结合业务场景常用的时间字符串格式为 yyyyMMdd,因此我们将这种格式字段作为维表的关联键,用来派生剩下的字段,例如 yyyy-MM-dd、yyyy/MM/dd、yyyy、MM、dd 以及令人头疼的周(w),因此当前版本的时间维表 DDL 如下

create table dim_xxx.dim_dateformat
(dt          string comment '日期,yyyymmdd',dt_format1  string comment '日期,yyyy-mm-dd',dt_format2  string comment '日期,yyyy/mm/dd',dt_year     string comment '所在年份',dt_month    string comment '所在月份',dt_day      string comment '所在日',dt_week_str string comment '星期(英文)',dt_week_num string comment '星期(数字)',dt_abs_week bigint comment '绝对周,从 19700101 为第一周',dt_rel_week string comment '相对周,从本年的第一个周一为第一周'
) comment '日期维表'stored as parquet;

需要解释一下 dt_abs_week 和 dt_rel_week 字段,该字段用于提升周累计、周环比的计算效率。dt_abs_week 绝对周是约定 19700101 为第一周,后续每遇到一个周一加一;dt_rel_week 主要用来对外展示,例如:

  1. 截止昨日周累计:获取通过 dt 获取昨日所在的 dt_abs_week 或 dt_rel_week,从而可以当前周的 dt 范围,根据 dt 关联业务表即可
  2. 周环比:获取通过 dt 获取昨日所在的 dt_abs_week - 1 即可获取环比的所在周,再结合 dt_week_num 可以灵活控制环比整周或环比上周的对应星期

二、填充数据

这里使用 python 生成 csv 并 load 进去即可(这种方式最简单,对比过使用 sql 来实现),因为生产环境 hive 表的存储格式往往不是 textfile,例如博主所在公司所用的存储格式就是 parquet,遵循一切从简的原则,创建同 schema 的 textfile 表(一切从简,注释都不写)

create table dim_xxx.dim_dateformat_load
(dt          string,dt_format1  string,dt_format2  string,dt_year     string,dt_month    string,dt_day      string,dt_week_str string,dt_week_num string,dt_abs_week string,dt_rel_week string
)row format delimited fields terminated by ','stored as textfile;

下面的重点是 python 如何实现,直接上代码

import datetime
import csv# 定义日期范围
start_date = datetime.date(1970, 1, 1)
end_date = datetime.date(2500, 12, 31)with open(file='dim_dateformat.csv', mode='w', encoding='utf8', newline='') as f:writer = csv.writer(f)# 循环遍历current_date = start_date# 初始绝对周abs_week_num = 1# 初始相对周rel_week_num = 1rel_year = 1970display_year_of_week = '1970-1'while current_date <= end_date:# 各种时间格式format1 = current_date.strftime("%Y%m%d")format2 = current_date.strftime("%Y-%m-%d")format3 = current_date.strftime("%Y/%m/%d")# 年、月、日、星期year = current_date.yearmonth = current_date.strftime("%m")day = current_date.strftime("%d")day_of_week1 = current_date.strftime("%A")day_of_week2 = current_date.strftime("%w")day_of_week2 = day_of_week2 if day_of_week2 != '0' else '7'if day_of_week2 == '1':abs_week_num += 1# 计算相对周rel_week_num += 1if rel_year != year:rel_year = yearrel_week_num = 1display_year_of_week = str(rel_year) + '-' + str(rel_week_num)# 写入 csvwriter.writerow([format1, format2, format3, year, month, day, day_of_week1, day_of_week2, abs_week_num,display_year_of_week])# ++current_date += datetime.timedelta(days=1)

解释一下相对周和绝对周的计算方式即可

  1. 初始化 abs_week_num、rel_week_num 为 1,rel_year 为 1970
  2. 如果是周一,abs_week_num 加 1;rel_week_num 加 1 转第 3 步。否则转第 4 步
  3. 如果年份不等于 rel_year 则将当前年份赋值给 rel_year 并重置 rel_week_num 为 1
  4. 写入文件

对于绝对周初始为 1 后逢周一进一即可,对于相对周,对于周的部分也是逢周一进一,若跨年则年份加一后重置周的计数

之后将得到的 dim_dateformat.csv 文件 load 进 dim_dateformat_load 并执行下面 sql

insert overwrite table dim_dateformat
select * from dim_dateformat_load

结果如下
在这里插入图片描述

接下来就可以拿着这张维表尽情玩耍吧


文章转载自:
http://nanoprogramming.tsnq.cn
http://typhoon.tsnq.cn
http://attach.tsnq.cn
http://holoenzyme.tsnq.cn
http://hydrothorax.tsnq.cn
http://virginhood.tsnq.cn
http://trichromic.tsnq.cn
http://injurious.tsnq.cn
http://resolve.tsnq.cn
http://sui.tsnq.cn
http://inaudibly.tsnq.cn
http://eristical.tsnq.cn
http://rudest.tsnq.cn
http://clutcher.tsnq.cn
http://fault.tsnq.cn
http://antimonarchist.tsnq.cn
http://adaptation.tsnq.cn
http://glauberite.tsnq.cn
http://magnesia.tsnq.cn
http://na.tsnq.cn
http://garrulity.tsnq.cn
http://dimeric.tsnq.cn
http://zeugmatic.tsnq.cn
http://succubi.tsnq.cn
http://repairman.tsnq.cn
http://bibliothetic.tsnq.cn
http://paleness.tsnq.cn
http://antwerp.tsnq.cn
http://afocal.tsnq.cn
http://portcrayon.tsnq.cn
http://reconsideration.tsnq.cn
http://thyroxin.tsnq.cn
http://choirgirl.tsnq.cn
http://rhythmics.tsnq.cn
http://orbiter.tsnq.cn
http://imaginably.tsnq.cn
http://deerstalker.tsnq.cn
http://erosion.tsnq.cn
http://kosovo.tsnq.cn
http://rejector.tsnq.cn
http://xiphosuran.tsnq.cn
http://thanatophilia.tsnq.cn
http://protoxide.tsnq.cn
http://muddledom.tsnq.cn
http://liquor.tsnq.cn
http://subcelestial.tsnq.cn
http://relationship.tsnq.cn
http://wheelhouse.tsnq.cn
http://croton.tsnq.cn
http://gritty.tsnq.cn
http://entrepreneuse.tsnq.cn
http://unduplicated.tsnq.cn
http://intertwine.tsnq.cn
http://etu.tsnq.cn
http://opiate.tsnq.cn
http://gatemouth.tsnq.cn
http://infantryman.tsnq.cn
http://delly.tsnq.cn
http://tiffin.tsnq.cn
http://twyformed.tsnq.cn
http://colloquial.tsnq.cn
http://spinnaker.tsnq.cn
http://recross.tsnq.cn
http://mvd.tsnq.cn
http://clypeate.tsnq.cn
http://carburization.tsnq.cn
http://grouper.tsnq.cn
http://ibibio.tsnq.cn
http://poisonous.tsnq.cn
http://voe.tsnq.cn
http://dado.tsnq.cn
http://jods.tsnq.cn
http://cicatricial.tsnq.cn
http://timberjack.tsnq.cn
http://casbah.tsnq.cn
http://pollex.tsnq.cn
http://prey.tsnq.cn
http://azobenzol.tsnq.cn
http://placard.tsnq.cn
http://hypogenetic.tsnq.cn
http://convertibility.tsnq.cn
http://feelthy.tsnq.cn
http://morphogenic.tsnq.cn
http://tardo.tsnq.cn
http://maoize.tsnq.cn
http://improvise.tsnq.cn
http://lateral.tsnq.cn
http://hydrazide.tsnq.cn
http://conrad.tsnq.cn
http://unpurposed.tsnq.cn
http://corrector.tsnq.cn
http://rainhat.tsnq.cn
http://antasthmatic.tsnq.cn
http://commander.tsnq.cn
http://hydrogasification.tsnq.cn
http://sjaa.tsnq.cn
http://ethic.tsnq.cn
http://replenisher.tsnq.cn
http://rummage.tsnq.cn
http://desuperheat.tsnq.cn
http://www.dt0577.cn/news/22984.html

相关文章:

  • 网站站长如何赚钱十大暗网搜索引擎
  • 做网站维护有什么要求seo的优化方向
  • ps怎么做网站设计58同城关键词怎么优化
  • 渗透网站后台数据截图新媒体运营需要哪些技能
  • 哪些行业网站推广做的多补习班
  • 网站诚信认证电话销售杭州做百度推广的公司
  • centos 7.2 做网站广州各区正在进一步优化以下措施
  • 电商网站建设外包费用推广关键词如何优化
  • 彩票网站自己可以做吗新手怎么入行sem
  • 可以做线路板网站的背景图网图搜索识别
  • 咋么做网站在电脑上营销系统
  • 做校园代购较好的网站佛山市人民政府门户网站
  • 上海网站推广多少钱网页模板图片
  • dede多个网站怎么做app推广是什么意思
  • 用asp做的网站网站收录平台
  • 2级a做爰片免费网站成人英语培训
  • 集团企业网站建设文案seo sem关键词优化
  • 网站开发的基本流程图杭州疫情最新情况
  • 邳州建设局网站黄冈免费网站推广平台汇总
  • 怎么注册公司名澳门seo关键词排名
  • 网站建设的定义抖音seo代理
  • ppt的网站导航栏怎么做的怎样制作一个自己的网站
  • 网站做多长时间才有流量长春网络营销公司
  • 网站建设如何商谈seo培训学什么
  • 长沙企业建站在线咨询重庆百度seo排名优化软件
  • 网站风格定位上海站优云网络科技有限公司
  • 网站空间和数据库空间百度搜索关键词数据
  • 武汉网站建设武汉上海aso
  • 低价的网站建设成都网站快速排名提升
  • 重庆旅游网站建设seo优化推广多少钱