ELI*_*ELI 2 scala apache-spark
我有两个数据帧df1和ip2Country.
df1包含IP地址,我试图将IP地址映射到经度和纬度等地理位置信息中.ip2Country
我将它作为Spark提交作业运行,但操作需要很长时间,即使df1只有少于2500行.
我的代码:
val agg =df1.join(ip2Country, ip2Country("network_start_int")=df1("sint")
, "inner")
.select($"src_ip"
,$"country_name".alias("scountry")
,$"iso_3".alias("scode")
,$"longitude".alias("slong")
,$"latitude".alias("slat")
,$"dst_ip",$"dint",$"count")
.filter($"slong".isNotNull)
val agg1 =agg.join(ip2Country, ip2Country("network_start_int")=agg("dint")
, "inner")
.select($"src_ip",$"scountry"
,$"scode",$"slong"
,$"slat",$"dst_ip"
,$"country_name".alias("dcountry")
,$"iso_3".alias("dcode")
,$"longitude".alias("dlong")
,$"latitude".alias("dlat"),$"count")
.filter($"dlong".isNotNull)
有没有其他方式加入这两个表?或者我做错了吗?
小智 10
如果你有一个需要加入小数据的大数据帧 - 广播连接非常有效.在这里阅读:广播联接(又名地图侧联接)
bigdf.join(broadcast(smalldf))
Run Code Online (Sandbox Code Playgroud)