mock数据,尽量随机,采用中间表的方式实现
开发平台上的sql不能超过1000行,而为了插入尽可能随机的数据,sql比较长---插入一行数据就需要执行80行sql,因此执行insert into mall_data.dtw_mall2_tmp values(***),(***)...这样格式数据插入,每次最多插入10条数据(800行sql)。如果要插入1000行数据,就得执行100次插入。太麻烦!!! 解决思路
在自己电脑上,创建表(textfile格式存储),通过本地hive一次性插入1000条数据(80000行sql,本地电脑上执行一次执行80000行sql),导出数据到本地文件f
在公司开发平台上创建一张表tb1(textfile格式存储),将本地文件f上传到该表tb1,再创建表tb2(根据要求,存储格式为parquet),从tb1获取数据,插入tb2
注意:无法将本地电脑textfile格式存储的表导出的数据直接上传到parquet格式存储的tb2!!!(https://www.cnblogs.com/wooluwalker/p/9193961.html) 1 创建本地表
create table if not exists mall_data.dtw_mall2_tmp(
mac_addr string comment 'Mac地址',
customer_id string comment '客户ID',
name string comment '姓名',
gender string comment '性别',
age string comment '年龄',
phone string comment '手机',
email string comment '邮箱',
birthday string comment '生日',
city string comment '省份城市',
has_car string comment '是否有车',
member_id string comment '会员号',
member_point string comment '会员积分',
member_status string comment '会员状态',
member_activate_time string comment '激活时间',
customer_type string comment '客户类型',
customer_life_cycle string comment '生命周期',
customer_new_old string comment '新老客户',
customer_level string comment '客户等级',
worth_consume_level string comment '消费层级',
shopping_feature string comment '购物特征',
character_all string comment '性格特征',
food_style string comment '偏好菜系',
food_price string comment '偏好用餐价位',
food_taste string comment '偏好口味',
food_time string comment '偏好用餐时间',
food_type string comment '偏好餐饮类型',
mall_visit_times_all string comment '到访次数',
mall_stay_time_all string comment '总停留时长',
mall_stay_time_avg string comment '平均停留时长',
shop_visit_num string comment '到访店铺数',
shop_stay_time_avg string comment '到店平均停留时长',
mall_last_visit_time string comment '上次到访时间',
pay_mall_all string comment '交易总额',
pay_num_mall_all string comment '交易笔数',
pay_per_deal_avg string comment '平均每笔交易金额',
pay_shop_num_all string comment '成交店铺数',
pay_per_shop_avg string comment '成交店铺平均单价',
pay_commodity_num_all string comment '成交商品数',
pay_commodity_per_unit_avg string comment '成交商品平均单价',
pay_last_time string comment '上次交易时间'
)
comment '用户表'
partitioned by (ds string comment '分区', tenantId int comment '租户id' , mallName string comment '商场名称')
stored as textfile; 2 插入数据
insert into mall_data.dtw_mall2_tmp
partition(ds='20180615', tenantid=1, mallname='big')
select
cast(rand()*1000000 as int)+1000000,
cast(rand()*1000000 as int)+1000000,
concat(
split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)]
),
split('m f notclear',' ')[cast((rand()*3) as int)],
cast((rand()*40) as int)+10,
13344455666,
'dtw123@dtw-inc.com',
concat(concat(199,split('0 1 2 3 4 5 6 7 8 9',' ')[cast(rand()*10 as int)]),
split('01 02 03 04 05 06 07 08 09 10 11 12',' ')[cast(rand()*12 as int)],
concat(split('0 1 2',' ')[cast(rand()*3 as int)],split('1 2 3 4 5 6 7 8',' ')[cast(rand()*8 as int)])
),
split('北京 上海 广州 深圳 杭州 厦门 福州 济南 青岛 烟台 济宁 临沂 莱芜 曲阜 平壤 太原 阜阳 合肥 嵊州 平度 拉萨 昆明 沈阳 长春 哈尔滨',' ')[cast(rand()*25 as int)],
split('有 无 不确定',' ')[cast((rand()*3) as int)],
cast(rand()*1000000 as int)+1000000,
cast(rand()*100000 as int),
split('未激活 已激活',' ')[cast(rand()*2 as int)],
concat(concat(201,split('0 1 2 3 4 5 6 7',' ')[cast(rand()*8 as int)]),
split('01 02 03 04 05 06 07 08 09 10 11 12',' ')[cast(rand()*12 as int)],
concat(split('0 1 2',' ')[cast(rand()*3 as int)],split('1 2 3 4 5 6 7 8',' ')[cast(rand()*8 as int)])
),
split('到访客户 成交客户 会员客户',' ')[cast(rand()*3 as int)],
split('新客 活跃客户 忠诚客户 流失客户 回头客',' ')[cast(rand()*5 as int)],
split('新客户 老客户',' ')[cast(rand()*2 as int)],
split('初级访客 中级访客 高级访客 初级会员 中级会员 高级会员',' ')[cast(rand()*6 as int)],
split('低 中 高',' ')[cast(rand()*3 as int)],
concat(
'{',
split('花卉一族 摄影一族 健美一族 果粉 电影派 阅读者 舞林人士 乐器迷 爱听音乐 童心未泯',' ')[cast(rand()*10 as int)],
',',
split('御宅族 白富美 高帅富 呼朋唤友 休闲大咖 装修一族 甜蜜新人 户外一族 网络一族 酒品人生',' ')[cast(rand()*10 as int)],
',',
split('有型潮男 拜金主义 数码达人 家有儿女 养生专家 运动一族 车友派 家有宠物 游戏人生 爱家人士',' ')[cast(rand()*10 as int)],
'}'
),
concat(
'{',
split('明确果断 犹豫再三 喜新厌旧 货比三家',' ')[cast(rand()*4 as int)],
',',
split('只逛不买 虚荣型 忠诚型',' ')[cast(rand()*3 as int)],
',',
split('挑剔型 将就型 跟风型',' ')[cast(rand()*3 as int)],
'}'
),
split('川菜 粤菜 淮扬菜 浙菜 湘菜 徽菜 闽菜 日本菜 台湾菜 韩国菜',' ')[cast(rand()*10 as int)],
split('低 中 高',' ')[cast(rand()*3 as int)],
split('油 清淡 辣 麻 咸',' ')[cast(rand()*5 as int)],
split('上午 中午 下午 黄昏 傍晚 晚上',' ')[cast(rand()*6 as int)],
split('中餐 西餐 自助餐 小吃快餐 饮品店 面包甜点 火锅 特色菜 烧烤',' ')[cast(rand()*9 as int)],
cast(rand()*50 as int),
round(rand()*50,1)+5,
round(rand()*5,1),
cast(rand()*10 as int),
round(rand()*5,1)+1,
concat(concat(201,split('6 7 8',' ')[cast(rand()*3 as int)]),
split('01 02 03 04 05 06 07 08 09 10 11 12',' ')[cast(rand()*12 as int)],
concat(split('0 1 2',' ')[cast(rand()*3 as int)],split('1 2 3 4 5 6 7 8',' ')[cast(rand()*8 as int)])
),
round(rand()*5000,1)+5000,
cast(rand()*50 as int),
round(rand()*1000,1)+500,
cast(rand()*20 as int),
round(rand()*500,1)+50,
cast(rand()*20 as int),
round(rand()*100,1)+50,
concat(concat(201,split('6 7 8',' ')[cast(rand()*3 as int)]),
split('01 02 03 04 05 06 07 08 09 10 11 12',' ')[cast(rand()*12 as int)],
concat(split('0 1 2',' ')[cast(rand()*3 as int)],split('1 2 3 4 5 6 7 8',' ')[cast(rand()*8 as int)])
); 3 导出数据
insert overwrite local directory '/Users/wooluwalker/Desktop/export' row format delimited fields terminated by '\t' select * from mall_data.dtw_mall2_tmp; 4 公司开发平台新建textfile格式存储的表 和 parquet格式存储的表 5 上传导出数据到textfile格式存储的表 6 将数据从textfile格式存储的表
mock数据,尽量随机,采用中间表的方式实现的更多相关文章
- 一种可以避免数据迁移的分库分表scale-out扩容方式
原文地址:http://jm-blog.aliapp.com/?p=590 目前绝大多数应用采取的两种分库分表规则 mod方式 dayofweek系列日期方式(所有星期1的数据在一个库/表,或所有?月 ...
- json-server mock数据
前言: 项目开发中,影响项目进程的常常是由于在前后端数据交互的开发流程中停滞,前端完成静态页面的开发后,后端迟迟未给到接口.而现在,我们就可以通过根据后端接口字段,建立一个REST风格的API接口,进 ...
- [转]一种可以避免数据迁移的分库分表scale-out扩容方式
原文地址:http://jm-blog.aliapp.com/?p=590 目前绝大多数应用采取的两种分库分表规则 mod方式 dayofweek系列日期方式(所有星期1的数据在一个库/表,或所有?月 ...
- 一种可以避免数据迁移的分库分表scale-out扩容模式
转自: http://jm.taobao.org/ 一种可以避免数据迁移的分库分表scale-out扩容方式 目前绝大多数应用采取的两种分库分表规则 mod方式 dayofweek系列日期方式(所有星 ...
- Hive 表操作(HIVE的数据存储、数据库、表、分区、分桶)
1.Hive的数据存储 Hive的数据存储基于Hadoop HDFS Hive没有专门的数据存储格式 存储结构主要包括:数据库.文件.表.试图 Hive默认可以直接加载文本文件(TextFile),还 ...
- 关于ORALCE一个表空间的数据导入到另一个表空间的方法(原创)
用户: whnaproject 所属表空间: whnaproject 新用户 : wniec 所属新表空间: wniec 要求:将用户whnaproject中的数 ...
- 【ASP.NET Web API教程】5.2 发送HTML表单数据:URL编码的表单数据
原文:[ASP.NET Web API教程]5.2 发送HTML表单数据:URL编码的表单数据 注:本文是[ASP.NET Web API系列教程]的一部分,如果您是第一次看本系列教程,请先看前面的内 ...
- 数据的随机抽取 及 jQuery补充效果(菜单、移动)
一.数据的随机抽取 都见过那种考试题从很多题中随机抽取几道的试卷吧,现在就要做这样的一个例子:从数据库中随机抽取几条数据出来显示(例如:一百中随机挑选50条) 随机挑选是要有提交数据的,所以肯定是要有 ...
- 在Tomcat中采用基于表单的安全验证
.概述 (1)基于表单的验证 基于From的安全认证可以通过TomcatServer对Form表单中所提供的数据进行验证,基于表单的验证使系统开发者可以自定义用户的登陆页面和报错页面.这种验证方法 ...
随机推荐
- flask基础---第三篇
flask中request的一些方法 首先from flask import request 1.request.path 2.request.host 3.request.host_url from ...
- Delphi下 Winsock 函数
用于初始化Winsock[声明]int WSAStarup(WORD wVersionRequested,LPWSADATA lpWSAData);[参数]wVersionRequested - 要求 ...
- 举例跟踪linux内核系统调用
学号351+ 原创作品转载请注明出处 + 中科大孟宁老师的linux操作系统分析: https://github.com/mengning/linuxkernel/ 实验要求: 编译内核5.0 qem ...
- EFCore Lazy Loading + Inheritance = 干净的数据表 (一) 【献给处女座的DB First程序猿】
前言 α角 与 β角 关于α角 与 β角的介绍,请见上文 如何用EFCore Lazy Loading实现Entity Split. 本篇会继续有关于β角的彩蛋在等着大家去发掘./斜眼笑 其他 本篇的 ...
- VM虚拟机拍摄快照时出错或者克隆失败解决办法
在换了固态硬盘后,下载好VM,装虚拟机,结果克隆虚拟机和拍摄快照时出问题了. 拍摄快照时出错或者隆失败出现参数错误如图: 所提供的参数中有一个无效参数 解决办法 出现这个问题一般是在机械硬盘的电脑上面 ...
- apk的api级别不要低于26
谷歌要求 api级别 最低26, 在用 xbuliber打包app的时候,可以在 manifest.json增加下面的代码. "plus": { "distribute& ...
- MySQL【数值处理函数】的使用方法
数值处理函数 下边列举一些数学上常用到的函数,在我们的业务中有数学计算时会很有用的: 名称 调用示例 示例结果 描述 ABS ABS(-1) 1 取绝对值 PI PI() 3.131593 返回圆周率 ...
- 第1次作业—— 熟悉 MoocTest环境
2.1 Mooctest 使用心得 Mooctest很方便,可以即时测评自己写的测试代码,获得覆盖率和报告,不需要自己安装配置环境 而且安装配置插件的环境也很简单,可以专注于测试本身 2.2 Juni ...
- 查询数据库:models.Books.objects.all()[10: 20]与models.Books.objects.filter(id__gt=10, id__lt=20).values() 的区别
1. models.Books.objects.all()[10: 20] (10:20 之间是冒号,不是逗号.)查出的是 QuerySet对象,如需进行操作,得进一步进行剥皮. 查询代码: 查询结 ...
- APP测试报告
招标手机APP测试总结报告 作 者: 日 期: 2016-03-10 文档编号: 002 版 本: Ver 1.0 目 录 1.测试概述 1 1.1. 编写目的 1 1. ...