日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Spark:如何替换sc.parallelize(List(item1,item2)).collect().foreach(row={})为并行?

發(fā)布時(shí)間:2025/3/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spark:如何替换sc.parallelize(List(item1,item2)).collect().foreach(row={})为并行? 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

代碼場景:

1)設(shè)定的幾種數(shù)據(jù)場景,遍歷所有場景:依次統(tǒng)計(jì)滿足每種場景條件下的數(shù)據(jù),并把統(tǒng)計(jì)結(jié)果存入hive;

2)已有代碼如下:

case class IndoorOTTCalibrateBuildingVecotrLegend(oid: Int, minHeight: Int, maxHeight: Int, minGridIDCount: Int, maxGridIDCount: Int, heightType: Int) extends Serializable // 實(shí)例化建筑物區(qū)間段:按照柵格的個(gè)數(shù)(面積)、樓的高度(商場等場景)來劃分場景val buildingHeightLegends = List(IndoorOTTCalibrateBuildingVecotrLegend(1, 1, 30, 1, 21, BuildingCalibrateHeightType.HeightType1.toString.toInt),IndoorOTTCalibrateBuildingVecotrLegend(2, 1, 30, 21, 45, BuildingCalibrateHeightType.HeightType2.toString.toInt),IndoorOTTCalibrateBuildingVecotrLegend(3, 1, 30, 45, 100, BuildingCalibrateHeightType.HeightType3.toString.toInt),IndoorOTTCalibrateBuildingVecotrLegend(4, 30, 50, 1, 21, BuildingCalibrateHeightType.HeightType4.toString.toInt),IndoorOTTCalibrateBuildingVecotrLegend(5, 30, 50, 21, 45, BuildingCalibrateHeightType.HeightType5.toString.toInt),IndoorOTTCalibrateBuildingVecotrLegend(6, 30, 50, 45, 100, BuildingCalibrateHeightType.HeightType6.toString.toInt),IndoorOTTCalibrateBuildingVecotrLegend(7, 50, 5000, 1, 100, BuildingCalibrateHeightType.HeightType7.toString.toInt))spark.sparkContext.parallelize(buildingHeightLegends).collect().foreach(buildingHeightLegend => {generateSampleBySenceType(spark, p_city, p_hour_start, p_hour_end, p_fpb_day, p_day_sample, linkLossCalibrateParameter, buildingHeightLegend)})

備注:

在generateSampleBySenceType()函數(shù)內(nèi)部包含有:

spark.sql(s"""
|xxx |where t10.heihgt>=${buildingHieghtLegend.MinHeight} and t10.height<${buildingHieghtLegend.MaxHeight} |and t10.gridcount<=${buildingHieghtLegend.MinGridIDCount} and t10.gridcount>${buildingHieghtLegend.MaxGridIDCount}
|""".stripMargin)

如果把代碼修改:

val buildingHeightLegends_df = spark.sqlContext.createDataFrame(buildingHeightLegends)buildingHeightLegends_df.createOrReplaceTempView("temp_buildingheightlegends")sql(s"""|select * from temp_buildingheightlegends""".stripMargin).repartition(buildingHeightLegends.length).foreachPartition(rows => {for (row <- rows) {val buildingHeightLegend = new IndoorOTTCalibrateBuildingVecotrLegend(row.getAs[Int]("oid"),row.getAs[Int]("minheight"),row.getAs[Int]("maxheight"),row.getAs[Int]("mingrididcount"),row.getAs[Int]("maxgrididcount"),row.getAs[Int]("heighttype"))generateSampleBySenceType(spark, p_city, p_hour_start, p_hour_end, p_fpb_day, p_day_sample, linkLossCalibrateParameter, buildingHeightLegend)}})

則會(huì)提示:generateSampleBySenceType()內(nèi)部sql代碼位置拋出SparkSession為NULL的異常。

修改方案:

把buildingHeightLegends注冊(cè)為臨時(shí)表temp_buildingHeightLegends,去掉外層的foreach,之后在generateSampleBySenceType()內(nèi)部把temp_buildingHeightLegends與其他結(jié)果集合進(jìn)行cross join:

測試代碼如下:

-- 場景表 CREATE TABLE [dbo].[test_senceitems]([sencetype] [int] NULL,[minheight] [int] NULL,[maxheight] [int] NULL,[mingridcount] [int] NULL,[maxgridcount] [int] NULL ) INSERT [dbo].[test_senceitems] ([sencetype], [minheight], [maxheight], [mingridcount], [maxgridcount]) VALUES (1, 1, 30, 1, 21) INSERT [dbo].[test_senceitems] ([sencetype], [minheight], [maxheight], [mingridcount], [maxgridcount]) VALUES (2, 1, 30, 21, 45) INSERT [dbo].[test_senceitems] ([sencetype], [minheight], [maxheight], [mingridcount], [maxgridcount]) VALUES (3, 1, 30, 45, 100) INSERT [dbo].[test_senceitems] ([sencetype], [minheight], [maxheight], [mingridcount], [maxgridcount]) VALUES (4, 30, 50, 1, 21) INSERT [dbo].[test_senceitems] ([sencetype], [minheight], [maxheight], [mingridcount], [maxgridcount]) VALUES (5, 30, 50, 21, 45) INSERT [dbo].[test_senceitems] ([sencetype], [minheight], [maxheight], [mingridcount], [maxgridcount]) VALUES (6, 30, 50, 45, 100) INSERT [dbo].[test_senceitems] ([sencetype], [minheight], [maxheight], [mingridcount], [maxgridcount]) VALUES (7, 50, 5000, 1, 100)-- 業(yè)務(wù)過濾統(tǒng)計(jì)表 CREATE TABLE [dbo].[test_grid]([gridid] [nvarchar](50) NULL,[height] [int] NULL,[gridcount] [int] NULL ) INSERT [dbo].[test_grid] ([gridid], [height], [gridcount]) VALUES (N'g1', 8, 23) INSERT [dbo].[test_grid] ([gridid], [height], [gridcount]) VALUES (N'g2', 3, 87) INSERT [dbo].[test_grid] ([gridid], [height], [gridcount]) VALUES (N'g3', 4, 34) INSERT [dbo].[test_grid] ([gridid], [height], [gridcount]) VALUES (N'g4', 30, 54) INSERT [dbo].[test_grid] ([gridid], [height], [gridcount]) VALUES (N'g5', 32, 32) INSERT [dbo].[test_grid] ([gridid], [height], [gridcount]) VALUES (N'g6', 32, 20) INSERT [dbo].[test_grid] ([gridid], [height], [gridcount]) VALUES (N'g7', 120, 34) INSERT [dbo].[test_grid] ([gridid], [height], [gridcount]) VALUES (N'g8', 89, 54) INSERT [dbo].[test_grid] ([gridid], [height], [gridcount]) VALUES (N'g9', 9, 16)

替換generateSampleBySenceType()內(nèi)部sql(s"""|""".stripMargin)代碼類似如下:

select t10.*,t11.* from test_grid t10 cross join test_senceitems t11 where t10.height>=t11.minheight and t10.height<t11.maxheight and t10.gridcount>=t11.mingridcount and t10.gridcount<t11.maxgridcount

?

轉(zhuǎn)載于:https://www.cnblogs.com/yy3b2007com/p/8505152.html

總結(jié)

以上是生活随笔為你收集整理的Spark:如何替换sc.parallelize(List(item1,item2)).collect().foreach(row={})为并行?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 中国一级特黄真人毛片免费观看 | 中文字幕一区二区三区四区免费看 | 日本精品一区二区在线观看 | 亚洲福利电影 | 午夜色网 | 法国空姐在线观看完整版 | 熟女性饥渴一区二区三区 | 欧美老肥妇做.爰bbww视频 | 午夜67194| 福利国产片 | 夜夜操av| av在线网站观看 | 二区三区在线观看 | 亚洲免费精品视频在线观看 | 亚洲品质自拍视频 | 欧美日韩亚洲色图 | 国产伦理一区二区 | 欧美最猛性xxxx| 黄色成人毛片 | 国产亚洲av片在线观看18女人 | 吞精囗交69激情欧美 | 欧美 亚洲 另类 偷偷 自拍 | 久久久综合久久久 | 亚洲人在线观看视频 | 久久国产精品亚洲 | 国产成人一区二区在线 | 国产裸体无遮挡 | 日韩成人在线观看视频 | 一区二区三区免费在线视频 | 人妻熟女aⅴ一区二区三区汇编 | 亚洲精品天堂成人片av在线播放 | www精品视频 | 麻豆精品国产传媒mv男同 | 天天撸一撸 | 免费观看黄色网址 | 欧美一区二区黄色 | 亚洲日本护士毛茸茸 | 亚洲一级一级 | 97午夜 | 欧美一级爱爱 | 欧美日韩一区二区区 | 国产成人8x视频一区二区 | 一二三精品| 夜夜草天天干 | 中文字幕在线观看不卡 | 钻石午夜影院 | 哺乳期给上司喂奶hd | 中出av在线 | 都市豪门艳霸淫美妇 | 久久久二区| 欧美午夜剧场 | 四虎精品欧美一区二区免费 | 日本成人小视频 | 国产精品午夜未成人免费观看 | 青青青免费在线 | 国产特黄毛片 | 九色激情网| 三级精品视频 | 91精品啪在线观看国产线免费 | 国产成a人亚洲精v品无码 | 天堂中文8| 久久久久久爱 | 国产一区一区 | 夫の上司に犯波多野结衣853 | 日本成人精品视频 | 国产91视频在线 | 精品少妇一区二区三区免费观看 | 国产欧美日韩在线播放 | 麻豆视频在线观看免费网站黄 | 欧美成人免费在线观看 | 超级碰在线视频 | 91久久精品一区二区别 | 亚洲熟女综合一区二区三区 | 欣赏asian国模裸体pics | 女女同性女同一区二区三区九色 | 91天天射 | 麻豆精品在线观看 | 日韩福利一区二区三区 | 亚洲一区在线视频观看 | 色呦呦中文字幕 | 国产成人一区在线观看 | 成人高潮片免费 | 国产精品成久久久久三级 | a毛片在线观看 | 在线www色| 久久激情网站 | 私人毛片 | 奇米影视久久 | 久久久国际精品 | 极品美女开粉嫩精品 | 午夜黄色在线观看 | 欧美精品色哟哟 | 亚洲图片激情小说 | 色女人天堂 | 亚洲码国产精品高潮在线 | 欧美日韩免费一区二区三区 | 狠狠操中文字幕 | 五月婷色 | 国产人与zoxxxx另类 |