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

二级域名网站如何申请吗百度排行榜风云

二级域名网站如何申请吗,百度排行榜风云,商务中国域名注册,世界军事使用Spark处理数据文件 检查数据 检查$DATA_EXERCISE/activations里的数据&#xff0c;每个XML文件包含了客户在指定月份活跃的设备数据。 拷贝数据到HDFS的/dw目录 样本数据示例&#xff1a; <activations><activation timestamp"1225499258" type&qu…

使用Spark处理数据文件

检查数据

检查$DATA_EXERCISE/activations里的数据,每个XML文件包含了客户在指定月份活跃的设备数据。

拷贝数据到HDFS的/dw目录

样本数据示例:

<activations><activation timestamp="1225499258" type="phone"><account-number>316</account-number><device-id>d61b6971-33e1-42f0-bb15-aa2ae3cd8680</device-id><phone-number>5108307062</phone-number><model>iFruit 1</model></activation>…
</activations>

处理文件

读取XML文件并抽取账户号和设备型号,把结果保存到/dw/account-models,格式为account_number:model

输出示例:

1234:iFruit 1
987:Sorrento F00L
4566:iFruit 1
…

提供了解析XML的函数如下:

// Stub code to copy into Spark Shellimport scala.xml._// Given a string containing XML, parse the string, and 
// return an iterator of activation XML records (Nodes) contained in the stringdef getActivations(xmlstring: String): Iterator[Node] = {val nodes = XML.loadString(xmlstring) \\ "activation"nodes.toIterator
}// Given an activation record (XML Node), return the model name
def getModel(activation: Node): String = {(activation \ "model").text
}// Given an activation record (XML Node), return the account number
def getAccount(activation: Node): String = {(activation \ "account-number").text
}

上传数据

# 1. 检查并创建HDFS目录
hdfs dfs -mkdir -p /dw# 2. 将本地数据上传到HDFS(替换$DATA_EXERCISE为实际路径)
hdfs dfs -put $DATA_EXERCISE/activations /dw/# 3. 检查文件是否上传成功
hdfs dfs -ls /dw/activations
定义题目提供的解析函数
def getActivations(xmlstring: String): Iterator[Node] = {(XML.loadString(xmlstring) \\ "activation").toIterator
}def getModel(activation: Node): String = (activation \ "model").text
def getAccount(activation: Node): String = (activation \ "account-number").text
读取数据(像处理日志一样)
val xmlRDD = sc.wholeTextFiles("/dw/activations/*.xml")
测试解析(查看第一条记录)
val firstRecord = getActivations(xmlRDD.first()._2).next()
println(s"测试解析结果: ${getAccount(firstRecord)}:${getModel(firstRecord)}")

处理全部数据
val resultRDD = xmlRDD.flatMap { case (_, xml) => getActivations(xml).map(act => s"${getAccount(act)}:${getModel(act)}")
}
查看结果样例(10条)
resultRDD.take(10).foreach(println)
保存结果(先清理旧数据)
import org.apache.hadoop.fs._
val outputPath = "/dw/account-models"
val fs = FileSystem.get(sc.hadoopConfiguration)
if (fs.exists(new Path(outputPath))) fs.delete(new Path(outputPath), true)resultRDD.saveAsTextFile(outputPath)
println(s"结果已保存到 hdfs://$outputPath")

验证结果(在Linux终端执行)

# 查看输出结果
hdfs dfs -cat /dw/account-models/part-* | head -n 10# 如果需要合并结果到单个文件
hdfs dfs -getmerge /dw/account-models ./account_models.txt
head account_models.txt

http://www.dtcms.com/wzjs/171945.html

相关文章:

  • 做网站的硬件和软件环境成都网站建设公司排名
  • 建站工具的优点地推公司
  • 展厅设计图片seo工作是什么意思
  • 乐陵森洁新能源有限公司电话优化师是做什么的
  • 怎么在网上卖产品青岛seo整站优化哪家专业
  • 建筑木模板尺寸seo高手是怎样炼成的
  • 网站设置的参数百度网络推广怎么收费
  • 设计婚纱网站汕头seo网站推广
  • 做网站要求app拉新平台有哪些
  • 做网站最简单的千川推广官网
  • 做企业网站收费多少百度top风云榜
  • aspnet动态网站开发百度推广客户端app下载
  • 学校网站建设好么友情链接源码
  • 网站空间在哪买好网络推广常见的方法
  • 班级网站做哪些方面seo策略是什么意思
  • 扬州公司做网站游戏推广怎么做挣钱
  • 做一个app大概需要多少费用seo网站优化详解
  • 网站是怎么做新手引导跨境电商培训
  • 网站设置合理的内链机制磁力搜索器kitty
  • 做外贸用什么视频网站宁德市人民医院
  • 做网站能接到模具单吗百度seo快速排名优化软件
  • 商务服饰网站建设推广如何做网上引流
  • 网站建设 政府案例广州网站建设公司
  • 如何配置网站服务器网络营销工具包括
  • 做旅游海报的软件或是网站nba最新排名东西部
  • 邯郸信息港最新招聘信息2023谷歌seo教程
  • 武汉做网站找哪家好广告安装接单app
  • 保定哪家做网站好海外网站
  • 网站建设字体颜色代码百度网盘官网下载
  • 专门做品牌折扣的网站有哪些学习软件的网站