1.数据库中随机抽取数据
Hive: select * from 表名 order by rand() limit 条数;
Mysql: select * from 表名 order by rand() limit 条数;
Oracle:select * from (select * from tableName order by dbms_random.value) where rownum < N
2.Hive中使用python脚本处理数据
Hive中可以直接使用python脚本处理数据,而不用写MapReduce程序或者Spark程序处理。因为python是脚本语言,无需编译,可以在hive中直接使用。
Hive会以输出流的形式将数据交给python脚本,python脚本以输入流的形式来接受数据,接受来数据以后,在python中就可以一行行做一系列的数据处理,处理完毕后,又以输出流的形式交给Hive,交给了hive就说明了就处理后的数据成功保存到hive表中了。
Hive中添加python脚本:
Hive中使用python脚本:
3.将Hive中的数据导入到本地
insert overwrite local directory '/root/test/traindata' row format delimited fields terminated by '\t' select * from dw_rcm_hitop_prepare2train_dm; |