spark geoip
import java.io.File
import scala.io.Source
import com.sanoma.cda.geoip.MaxMindIpGeo
import com.sanoma.cda.geo.Point
import java.io.PrintWriter
val geoIp = MaxMindIpGeo("/data/elas-input/GeoIP2-City.mmdb", 1000,synchronized = true)
def iter_dir(srcDir:String,dstDir:String): Unit ={
val files = (new File(srcDir)).listFiles().filter(_.isFile)
for( item <- files){
println(item.getName)
val dstname = item.getName
val out = new PrintWriter(s"""${dstDir}/${dstname}""")
for(line <- Source.fromFile(item).getLines()){
val it = line.split("\t")
val geo = geoIp.getLocation(it(0))
if(geo.isEmpty){
out.printf("%s,%s,%s,%s\n",it(0),it(1),it(2),it(3),it(4),"")
}
else{
val geoGet = geo.get
val countryCode = geoGet.countryCode.getOrElse("")
val countryName = geoGet.countryName.getOrElse("")
val region = geoGet.region.getOrElse("")
val city = geoGet.city.getOrElse("")
val geoPoint = geoGet.geoPoint
val latitude = if(geoPoint.isEmpty) "" else geoPoint.get.latitude.toString
val longitude = if(geoPoint.isEmpty) "" else geoPoint.get.longitude.toString
val postalCode = geoGet.postalCode.getOrElse("")
val continent = geoGet.continent.getOrElse("")
out.printf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",it(0),it(1),it(2),it(3),it(4),countryCode,countryName,region,city,latitude,longitude,postalCode,continent,it(5))
}
}
out.close()
}
}
iter_dir("/data/elas-input/uniqServiceDir","/data/elas-input/tsoutput")
val str2 = "North Amercia"
val index = str.indexOf(str2)
val index2 = str.length + index + 1
val content = str.substring(index2)
spark geoip的更多相关文章
- spark streaming 使用geoIP解析IP
1.首先将GEOIP放到服务器上,如,/opt/db/geo/GeoLite2-City.mmdb 2.新建scala sbt工程,测试是否可以顺利解析 import java.io.Fileimpo ...
- geoip ip2region2 with spark
上一篇文章中 我使用 maxmind的免费库开发了一个waterdrop的 插件,测试数据发现,国内的有些市级还是不准确,而且香港并不是显示中国,这就不友好了. 找了一下,发下 ip2region 这 ...
- spark操作geoip的domain数据库
val ipv4 = sc.textFile("hdfs://hbase11:9000/sparkTsData/GeoIP2-Domain-Blocks-IPv4.csv").ma ...
- geoip scala api
#!/bin/bash /home/hadoop/spark-1.6.2/bin/spark-shell --master spark://hbase11:7077 --executor-memory ...
- 使用Java编写并运行Spark应用程序
我们首先提出这样一个简单的需求: 现在要分析某网站的访问日志信息,统计来自不同IP的用户访问的次数,从而通过Geo信息来获得来访用户所在国家地区分布状况.这里我拿我网站的日志记录行示例,如下所示: 1 ...
- Spark踩坑记——Spark Streaming+Kafka
[TOC] 前言 在WeTest舆情项目中,需要对每天千万级的游戏评论信息进行词频统计,在生产者一端,我们将数据按照每天的拉取时间存入了Kafka当中,而在消费者一端,我们利用了spark strea ...
- Spark RDD 核心总结
摘要: 1.RDD的五大属性 1.1 partitions(分区) 1.2 partitioner(分区方法) 1.3 dependencies(依赖关系) 1.4 compute(获取分区迭代列表) ...
- spark处理大规模语料库统计词汇
最近迷上了spark,写一个专门处理语料库生成词库的项目拿来练练手, github地址:https://github.com/LiuRoy/spark_splitter.代码实现参考wordmaker ...
- Hive on Spark安装配置详解(都是坑啊)
个人主页:http://www.linbingdong.com 简书地址:http://www.jianshu.com/p/a7f75b868568 简介 本文主要记录如何安装配置Hive on Sp ...
随机推荐
- ListView适配器获取布局文件作为View的三种方式
第一种方法: public View getView(int position, View convertView, ViewGroup parent) { View view = null; if ...
- Linux运维人员共用root帐户权限审计
Linux运维人员共用root帐户权限审计 2016-11-02 运维部落 一.应用场景 在中小型企业,公司不同运维人员基本都是以root 账户进行服务器的登陆管理,缺少了账户权限审计制度.不出问题还 ...
- npm安装完bower,使用时提示bower不是内部或外部命令
归根结底还是环境变量的问题,但是配了好几次没配成功,最后就直接把装好的node里面的复制到系统创建的环境变量目录下,问题解决! 问题描述:我们安装node.js,npm,通过npm安装bower一路正 ...
- hdu3555 数位dp
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
- Oracle的自增长主键
自增长主键 --首先建一个表TEST create table TEST( NID int PRIMARY KEY, test1 varchar2(20), test2 varchar2(20) ...
- lucene-查询query->WildcardQuery使用通配符搜索
Lucene也提供了通配符的查询,这就是WildcardQuery. package ch11; import org.apache.lucene.analysis.standard.Standard ...
- C#-WinForm-客户端程序-Form基本属性
WinForm - 客服端程序(C/S) WindowsForm 的简称 客户端应用程序:是需要安装在用户电脑上才可以使用的程序,代码部分在用户电脑上执行 特点:不需要联网也可以打开使用部分功能,但现 ...
- 【Gym 100971K】Palindromization
Mihahim has a string s. He wants to delete exactly one character from it so that the resulting strin ...
- 在代码中使用Autolayout – intrinsicContentSize和Content Hugging Priority
我们继续来看在代码中使用Autolayout的话题.先说intrinsicContentSize,也就是控件的内置大小.比如UILabel,UIButton等控件,他们都有自己的内置大小.控件的内置大 ...
- [模板]tarjan求强连通分量
大约是今年4月学的算法了,后来5月的时候做题还写了一个退化的tarjanQAQ. 时间复杂度:O(n+m) 用途:有向图缩环 #include<set> #include<cmath ...