1,---导入mds_imei_month_info

set hive.exec.max.dynamic.partitions= 100000; //最大的动态分区表
set hive.support.concurrency=false; //是否支持并发
set hive.exec.max.dynamic.partitions.pernode= 100000; //each mapper or reducer可以创建的最大动态分区数
set hive.exec.dynamic.partition.mode=nonstrict;  //strict是避免全分区字段是动态的,必须有至少一个分区字段是指定有值的
insert into table mds_imei_month_info partition(month)
select imei_p,dt,cnt ,month from
(
select  imei_p ,month,dt,cnt from (select imei_p,'201705' as month,sum(pow(2,(dt-1))) as dt,sum(cnt) cnt //将自下面取出的dt进行指数的转换,pow(2,(dt-1))表示2的dt-1次方,cnt表示imei在这个月出现的次数(select imei_p,cast(substring(dt,7,2) as int) as dt,count(*) cnt from mds_engine_basic where dt>=20170501 and dt<=20170531 and length(dt)=8 group by imei_p,dt //dt一共8位数,从第7位数开始的2位数取出,既01到31) a group by imei_p)a where length(imei_p)>=14 and regexp_extract(imei_p,'([a-z,,.,A-Z,0-9,_,\\-]*)',0)=imei_p  //这是对imei进行正则匹配
)a;

2,---导入mds_ip_month_info

set hive.exec.max.dynamic.partitions= 100000;
set hive.support.concurrency=false;
set hive.exec.max.dynamic.partitions.pernode= 100000;
set hive.exec.dynamic.partition.mode=nonstrict;
insert into table mds_ip_month_info partition(month)
select user_ip,country,province,city,longtitude,latitude,isp,dt,cnt ,month from
(
select  user_ip ,month,dt,cnt,country,city,province,latitude,longtitude,isp from
(select user_ip,'201705' as month,sum(pow(2,(dt-1))) as dt,sum(cnt) cnt,country,city,province,latitude,longtitude,isp
from(
select user_ip,cast(substring(dt,7,2) as int) as dt,count(*) cnt,ipaddressquery(2,user_ip) country,
ipaddressquery(3,user_ip) province,ipaddressquery(1,user_ip) city, split(ipaddressquery(5,user_ip),',')[1]  longtitude ,
split(ipaddressquery(5,user_ip),',')[0]  latitude,
ipaddressquery(4,user_ip) isp  from mds_engine_basic where dt>=20170501 and dt<=20170531 and length(dt)=8 and user_ip not like '%,%'
and      split(user_ip,',')[0]  like '%.%.%' and regexp_extract( split(user_ip,',')[0],'\.([0-9]{0,7})\.([0-9]{0,7})\.([0-9]{0,7})\.([0-9]{0,7})',0)= split(user_ip,',')[0]  and split(user_ip,'\\.')[0]<300
group by user_ip,dt,ipaddressquery(2,user_ip) ,
ipaddressquery(3,user_ip) ,ipaddressquery(1,user_ip) , split(ipaddressquery(5,user_ip),',')[1]   ,
split(ipaddressquery(5,user_ip),',')[0]  ,
ipaddressquery(4,user_ip)) a group by user_ip,country,city,province,latitude,longtitude,isp)a
)a ;

3,---导入mds_id_month_info

set hive.exec.max.dynamic.partitions= 100000;
set hive.support.concurrency=false;
set hive.exec.max.dynamic.partitions.pernode= 100000;
set hive.exec.dynamic.partition.mode=nonstrict;
insert into table mds_id_month_info partition(month)
select id,dt,cnt ,month from
(
select  id ,month,dt,cnt from (select id,'201705' as month,sum(pow(2,(dt-1))) as dt,sum(cnt) cntfrom(select id,cast(substring(dt,7,2) as int) as dt,count(*) cnt from mds_engine_basic where dt>=20170501 and dt<=20170531 and length(dt)=8 group by id,dt) a group by id)a where length(id)=16 and regexp_extract(id,'([a-z,,.,A-Z,0-9,_,\\-]*)',0)=id
)a;

4,---导入mds_bssid_month_info

set hive.exec.max.dynamic.partitions= 100000;
set hive.support.concurrency=false;
set hive.exec.max.dynamic.partitions.pernode= 100000;
set hive.exec.dynamic.partition.mode=nonstrict;
insert into table mds_bssid_month_info partition(month)
select bssid,dt,cnt ,month from
(
select  bssid ,month,dt,cnt from (select bssid,'201709' as month,sum(pow(2,(dt-1))) as dt,sum(cnt) cntfrom(select bssid,cast(substring(dt,7,2) as int) as dt,count(*) cnt from mds_engine_wifi where dt>=20170901 and dt<=20170930 and length(dt)=8 group by bssid,dt) a group by bssid)a where length(bssid)>=14
)a;

转载于:https://www.cnblogs.com/huxinga/p/7647219.html

hive向表格中插入数据并分析语句相关推荐

  1. 用SQL语句向表格中插入数据

    向表格中插入数据 SQL语言使用insert语句向数据库表格中插入或添加新的数据行.Insert语句的使用格式如下: insert into tablename (first_column,...la ...

  2. 向MySQL数据库中插入数据,sql语句没问题,但插入失败也不报错?

             这几天在做一个Javaweb的图书商城项目,在操作数据库的过程中,遇到一个问题? 向数据库中的order数据表中插入数据时,一直插入数据失败.没有报SQL语句语法错误,Eclipse ...

  3. python分析pdf年报 货币现金_如何用Python从大量pdf 中提取表格中的数据进行分析?...

    根据一楼答案@森林的建议 说说我的处理经验 我也是借助开源项目tabula,不得不说tabula的功能确实很强大. 我是用Python来处理数据,但是没有用tabula-py,因为表格跨列跨行等情况比 ...

  4. mysql教程中插入语句_mysql中插入数据Insert into语句用法

    在mysql中要向数据库中保存数据我们最常用的一种方法就是直接使用Insert into语句来实现了,下面我来给大家详细介绍Insert into语句用法 INSERT用于向一个已有的表中插入新行.I ...

  5. 在表中插入数据的SQL语句

    1.插入数据:insert  into 表名  values(值列表)[,(值列表)];       可以一次性插入多条数据. 2.给部分字段插入数据:insert into 表名  (字段列表) v ...

  6. 存在的hive插入数据_往hive表中插入数据以及导出数据

    转载:https://blog.csdn.net/qq_26442553/article/details/80380590 转载:https://blog.csdn.net/weixin_436817 ...

  7. POI:从Excel文件中读取数据,向Excel文件中写入数据,将Excel表格中的数据插入数据库,将数据库中的数据添加到Excel表

    POI 简介: POI是Apache软件基金会用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程序对Microsoft Office格式档案读和写的功能. ...

  8. Hadoop+hive+flask+echarts大数据可视化项目之hive环境搭建与系统数据的分析思路

    Hadoop+hive+flask+echarts大数据可视化项目(四) --------------hive环境搭建与系统数据的分析思路---------------- 关注过Hadoop+hive ...

  9. 计算机表格中如何计算数据透视表,Excel表格中在数据透视表中添加计算字段的方法...

    计算字段是使用数据透视表中的字段同其他内容经过计算后得到的,如果用户需要在数据透视表中自定义计算公式以计算数据,可以通过添加计算字段来实现,下面介绍Excel表格中在数据透视表中添加计算字段的具体操作 ...

最新文章

  1. 批量注册、模拟登陆很难吗?一个Python爬虫案例告诉你答案!
  2. 打开IT运维外包的“黑盒”
  3. maven2学习总结(3,maven2在淘宝项目的应用)
  4. python简易木马(一)
  5. 【测试点分析】1081 检查密码 (15分)
  6. SSH(Secure Shell Protocol)命令之 grep
  7. [推荐]VMware Workstation 6.5虚拟机(汉化补丁+注册机+原版安装文件)
  8. java的string访问某个元素_架构师必懂的——RBAC基于角色的访问权限设计
  9. c# xls 复制一行_c# – 将excel工作簿中的第一行复制到新的Excel工作簿
  10. 微软版UnityVs横空出世,究竟是谁成就了谁?
  11. 计算机键盘换挡键,电脑键盘上的换挡键是哪个
  12. c++语言取整为什么要加0.5_C/C++之取整函数
  13. el-form-item 如何限制只能输入数字_中教云数字课程教材云平台操作答疑
  14. PKUWC2018 5/6
  15. 为什么阿里巴巴禁止在foreach里进行元素的remove/add操作
  16. 2018 Multi-University Training Contest 10 hdu 6432 Problem G. Cyclic(oeis题)
  17. WinForm中的NotifyIcon控件的使用
  18. MyBatis 自定义插件
  19. 如何快速设计《数字电路》的JK触发器、T触发器描述的驱动方程对应的次态K图——异或卡诺图法
  20. 企业微信sdk调用,通过手机号或微信好友添加客户

热门文章

  1. EXT3与EXT4的主要区别
  2. linux下的重要服务dns
  3. centos8编译openssl-1.0.2u、openssl-1.1.1k
  4. javascript网络_没有JavaScript的网络外观
  5. 【廖雪峰Python学习笔记】面向对象编程OOP
  6. 安卓环境搭建 SDK emulator directory is missing
  7. 四种JOIN简单实例
  8. 讲座记录:从码农到架构师(精简版)
  9. 21个UI设计必会的设计技巧
  10. 零基础学Java需要做哪些准备