欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

SparkSQL的代碼示例分析

這篇文章跟大家分析一下“Spark SQL的代碼示例分析”。內(nèi)容詳細(xì)易懂,對(duì)“Spark SQL的代碼示例分析”感興趣的朋友可以跟著小編的思路慢慢深入來(lái)閱讀一下,希望閱讀后能夠?qū)Υ蠹矣兴鶐椭?。下面跟著小編一起深入學(xué)習(xí)“Spark SQL的代碼示例分析”的知識(shí)吧。

萊西網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),萊西網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為萊西數(shù)千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢(qián),請(qǐng)找那個(gè)售后服務(wù)好的萊西做網(wǎng)站的公司定做!

參考官網(wǎng)Spark SQL的例子,自己寫(xiě)了一個(gè)腳本:

val sqlContext = new org.apache.spark.sql.SQLContext(sc)
import sqlContext.createSchemaRDD

case class UserLog(userid: String, time1: String, platform: String, ip: String, openplatform: String, appid: String)

// Create an RDD of Person objects and register it as a table.
val user = sc.textFile("/user/hive/warehouse/api_db_user_log/dt=20150517/*").map(_.split("\\^")).map(u => UserLog(u(0), u(1), u(2), u(3), u(4), u(5)))
user.registerTempTable("user_log")

// SQL statements can be run by using the sql methods provided by sqlContext.
val allusers = sqlContext.sql("SELECT * FROM user_log")

// The results of SQL queries are SchemaRDDs and support all the normal RDD operations.
// The columns of a row in the result can be accessed by ordinal.
allusers.map(t => "UserId:" + t(0)).collect().foreach(println)

結(jié)果執(zhí)行出錯(cuò):

org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 50.0 failed 1 times, most recent failure: Lost task 1.0 in stage 50.0 (TID 73, localhost): java.lang.ArrayIndexOutOfBoundsException: 5
        at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$anonfun$2.apply(<console>:30)
        at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$anonfun$2.apply(<console>:30)
        at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
        at org.apache.spark.util.Utils$.getIteratorSize(Utils.scala:1319)
        at org.apache.spark.rdd.RDD$$anonfun$count$1.apply(RDD.scala:910)
        at org.apache.spark.rdd.RDD$$anonfun$count$1.apply(RDD.scala:910)
        at org.apache.spark.SparkContext$$anonfun$runJob$4.apply(SparkContext.scala:1319)
        at org.apache.spark.SparkContext$$anonfun$runJob$4.apply(SparkContext.scala:1319)
        at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:61)
        at org.apache.spark.scheduler.Task.run(Task.scala:56)
        at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:196)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

從日志可以看出,是數(shù)組越界了。

用命令

sc.textFile("/user/hive/warehouse/api_db_user_log/dt=20150517/*").map(_.split("\\^")).foreach(x => println(x.size))

發(fā)現(xiàn)有一行記錄split出來(lái)的大小是“5”

6
6
6
6
6
6
6
6
6
6
15/05/21 20:47:37 INFO Executor: Finished task 0.0 in stage 2.0 (TID 4). 1774 bytes result sent to driver
6
6
6
6
6
6
5
6
15/05/21 20:47:37 INFO Executor: Finished task 1.0 in stage 2.0 (TID 5). 1774 bytes result sent to driver

原因是這行記錄有空值“44671799^2015-03-27 20:56:05^2^117.93.193.238^0^^”

網(wǎng)上找到了解決辦法——使用split(str,int)函數(shù)。修改后代碼:

val sqlContext = new org.apache.spark.sql.SQLContext(sc)
import sqlContext.createSchemaRDD

case class UserLog(userid: String, time1: String, platform: String, ip: String, openplatform: String, appid: String)

// Create an RDD of Person objects and register it as a table.
val user = sc.textFile("/user/hive/warehouse/api_db_user_log/dt=20150517/*").map(_.split("\\^", -1)).map(u => UserLog(u(0), u(1), u(2), u(3), u(4), u(5)))
user.registerTempTable("user_log")

// SQL statements can be run by using the sql methods provided by sqlContext.
val allusers = sqlContext.sql("SELECT * FROM user_log")

// The results of SQL queries are SchemaRDDs and support all the normal RDD operations.
// The columns of a row in the result can be accessed by ordinal.
allusers.map(t => "UserId:" + t(0)).collect().foreach(println)

關(guān)于Spark SQL的代碼示例分析就分享到這里啦,希望上述內(nèi)容能夠讓大家有所提升。如果想要學(xué)習(xí)更多知識(shí),請(qǐng)大家多多留意小編的更新。謝謝大家關(guān)注一下創(chuàng)新互聯(lián)網(wǎng)站!

分享題目:SparkSQL的代碼示例分析
當(dāng)前URL:http://www.aaarwkj.com/article6/gdgsog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、Google、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、網(wǎng)站制作定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司
日本激情精品在线观看| 国产中文字幕乱码中文| 日本乱码中文字幕在线观看| 精品国产av一区二区三广区| 久草视频亚洲免费在线| 国产三级黄色片免费看| 台湾三级一区二区三区| 国产成人综合在线观看网站| 国产一级内射在线视频| 蜜桃视频在线观看视频免费| 日韩精品一区高清视频| 日韩av有码在线播放| 亚洲国产精品自拍视频| 国产日韩欧美亚洲中文| 久久这里只有精品热免费| 亚洲熟妇亚洲熟妇亚洲熟妇| 最近最新免费成人在线视频| 欧美日本午夜福利在线观看| 在线一区免费视频播放| 剧情av一区二区在线| 声入人心第一季在线观看| 激情欧美精品桃桃激情| 日本一区二区三区免费不卡视频| 亚洲国产成人精品女人久久久′| 视频在线观看亚洲午夜福利| 欧美日韩国产一下老妇| 国产福利在线观看午夜| 人妻鲁丝一区二区三区| 国内揄拍国内精品少妇国| 中国成熟女人毛茸茸视频| 精品熟女少妇av免费观看| 欧美一级纯黄电影视频| 日本久久久精品福利视频| 欧美精品一区二区久久| 日韩精品免费一区二区三区| 国产精品熟女一区二区三区| 日本一区二区三区高清| 91午夜精品亚洲一区二区三区| 国产毛片一区二区三区二区| 丝袜亚洲激情欧美日韩偷拍| 日韩国产一区二区在线观看|