说明:日常业务经常涉及到ip映射地域的统计,有一定的使用复杂度,本文结合业界几种现状,做一次综合测试评估。
通过ip地址获取用户地理位置信息,一般包括的信息由国家、区域(省/州)、城市、街道、经纬度、ISP提供商等信息。
质量评价标准
国内比较有名的是”纯真“数据库,以及最近更出来的17MON,国外常用的MaxMind、ip2location。
国内百度、淘宝、新浪对外也提供有api接口,可以获取用户经纬度,但是存在访问次数限制。
一般有人维护的,都是收费的,质量、干净、准确程度更好些。
质量 | 粒度 | 准确度 | 维护 | 经纬度 | |
---|---|---|---|---|---|
公司 | 中 | 中 | 中 | --- | 无 |
纯真 | 低 | 高 | 高 | 杂 | 无 |
17MON | 中 | 中 | 高 | 有 | 无 |
MaxMind | 高 | 高 | 中 | 有 | 有 |
如下从本公司(ip库)、17MON、MaxMind(免费版)做统计查询比较。
吐槽:纯真格式杂乱不同一,17MON目前只能精确到省份,MaxMind中国部分是汉语拼音。
数据来源,从iplog抓取2500万条用户记录,统计用户uv
耗时 | uv | |
---|---|---|
公司 |
101.3s |
841974 |
17MON |
92.3s |
1152597 |
MaxMInd |
170.0s |
1391777 |
测试sql语句:
公司:
hive -e "create temporary function ip_to_city as ‘com.renren.dolphin.udf.IpToArea‘;use acorn_3g;select count(distinct id) from test_iplog where get_json_object(ip_to_city(ip),‘$.province‘) = ‘北京市‘;"
17MON:
hive -e "use acorn_3g;add FILE ./17monipdb.dat;add JAR ./HiveUDFs-1.0-SNAPSHOT.jar;create temporary function ip_to_mon as ‘cn.gxnu.ipdata.MonIp‘;select count(distinct id) from test_iplog where split(ip_to_mon(ip),‘\t‘)[1] = ‘北京‘;"
MaxMind
hive -e "add FILE ./GeoLiteCity.dat;add JAR ./HiveUDFs-1.0-SNAPSHOT.jar;CREATE TEMPORARY FUNCTION geoip as ‘net.petrabarus.hiveudfs.GeoIP‘; ;select count(distinct id) from acorn_3g.test_iplog where geoip(cast (ip_num as bigint),‘REGION_NAME‘,‘./GeoLiteCity.dat‘)=‘Beijing‘;"
名称 | 说明 | 参数 | 返回值 |
---|---|---|---|
iptolog | IP地址转换为long型 | string | long |
longtoip | long转变为ip地址类型 | long | string |
iptocountry | 返回国家名称 | ip | string |
iptoprovince |
返回省份名称 | ip | string |
iptocity | 返回城市名称 | ip | string |
根据以往业务,打算开发以上几个hive内置函数,减轻大家ip转地域使用复杂度
参考文献
17MON:http://tool.17mon.cn/ipdb.html
maxmind:http://dev.maxmind.com/geoip/legacy/geolite/#
使用Hive UDF和GeoIP库为Hive加入IP识别功能:http://www.cnblogs.com/likai198981/p/3465365.html
关于hive中iP地址映射地域调研,布布扣,bubuko.com
原文:http://blog.csdn.net/moon_yang_bj/article/details/20880475