处理如此的字符串:
time^B1493534543940^Aid^B02CD^Aasr^B叫爸爸^Anlp^B{"domain":"com.abc.system.chat","intent":"chat","slots":{"tts":"爸爸","asr":"叫爸爸"},"voice":"叫爸爸","confidence":1.0,"cloud":false,"posStart":0,"posEnd":0}^Adomain^Bcom.abc.chat^Aintent^Bchat python版spark代码如下 from operator import add
import time def getInfo(str, sep1, sep2):
thedate = 'today'
sn = 'default'
if str is not None:
fields = str.split(sep1)
if len(fields) > 1:
for field in fields:
if field is not None:
kv = field.split(sep2)
if len(kv) == 2:
if kv[0] == 'time':
timestamp = int(kv[1]) / 1000
time_local = time.localtime(timestamp)
thedate = time.strftime("%Y-%m-%d", time_local)
if kv[0] == 'id':
sn = kv[1]
if thedate is not None and sn is not None:
res = thedate + "|" + sn
return res rdd1 = sc.textFile("/Users/zhangzhenghai/example.log")
rdd2 = rdd1.map(lambda x: (getInfo(x,'\u0001','\u0002'),1))
rdd3 = rdd2.reduceByKey(add)
rdd4 = rdd3.map(lambda x: (x[1],x[0]))
rdd5 = rdd4.sortByKey(False)
rdd6 = rdd5.map(lambda x:(x[1],x[0]))
rdd6.collect()

以上仅供学习参考

最新文章

  1. SSH中Action的单例与多例
  2. jquery图片轮播效果(unslider)
  3. JdbcTemplae使用入门&&Spring三种连接池配置&&Spring配置文件引用外部properties文件
  4. HDU-4669 Mutiples on a circle 环形DP
  5. 使用Genymotion作Android开发模拟器:安装Genymotion、部署Genymotion Vitrue Device、安装Genymotion eclipse插件
  6. Centos 6.8下安装LBP2900打印机驱动
  7. 央视公然诽谤Linux操作系统,谁报告?
  8. baidu 200兆SVN代码服务器
  9. Springboot项目启动后访问不到Controller
  10. DateTime?,也是一种类型,代表DateTime或NULL两种类型,在处理空时间时比较有用
  11. Java 文件类 File
  12. 2《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)——操作文件
  13. [ 转载 ] Http详解
  14. iOS全局变量的声明和使用
  15. Effective C++ 条款08:别让异常逃离析构函数
  16. 百度地图Api进阶教程-基础地图示例1.html
  17. react 修改循环列表的当前单个子项状态:思路 拿原始state数据更改,再做请求
  18. Home Assistant系列 -- 基于树莓派安装并设置自启动
  19. Mac通过wifi连接 Android设备
  20. PHP之文件大小的转换函数

热门文章

  1. 怎样让CodeBlocks支持C99
  2. 【Oracle】函数
  3. C#:Use Form as Subform
  4. 微信小程序独家秘笈之抽奖大转盘
  5. IDEA的maven项目中静态文件编译的路径问题(未测试)
  6. JAvaScript:JS数组元素去重的方法
  7. ajax操作登录
  8. 转:造HTTP请求Header实现“伪造来源IP”
  9. if else和switch的效率
  10. RGB(FFFFFF)转255:255:255