關於hive中iP位址對映地域調研

2021-06-20 22:03:35 字數 1967 閱讀 3130

說明:日常業務經常涉及到ip對映地域的統計,有一定的使用複雜度,本文結合業界幾種現狀,做一次綜合測試評估。

通過ip位址獲取使用者地理位置資訊,一般包括的資訊由國家、區域(省/州)、城市、街道、經緯度、isp提供商等資訊。

質量評價標準

國內比較有名的是」純真「資料庫,以及最近更出來的17mon,國外常用的maxmind、ip2location。

一般有人維護的,都是收費的,質量、乾淨、準確程度更好些。

質量粒度

準確度維護

經緯度收費

吐槽公司中中

中---

無---

位址庫太舊純真低

高高有無

無資料比較雜

17mon中中

高有無暫無

只能精確到省份

maxmind高高

中有有免費/收費

中國地區,以漢語拼音顯示

如下從本公司(ip庫)、17mon、maxmind(免費版)做統計查詢比較。

綜合來說:推薦maxmind wiki、文件齊全,也有相應的api。

資料**,從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

返回國家名稱

ipstring

iptoprovince 

返回省份名稱

ipstring

iptocity

返回城市名稱

ipstring

根據以往業務,打算開發以上幾個函式,內建到hive中,減輕大家ip轉地域使用複雜度

17mon:

maxmind:

使用hive udf和geoip庫為hive加入ip識別功能:

關於IP位址

ip是英文 internet protocol 的縮寫,意思是 網路之間互連的協議 也就是為 計算機網路 相互連線進行通訊而設計的協議。ip位址是乙個32位的二進位制數,通常被分割為4個 8位 二進位制數 也就是4個位元組 ip位址通常用 點分十進位制 表示成 a.b.c.d 的形式,其中,a,b,...

獲取IP位址函式(本地 網域名稱轉換)

getip.c get local or remote ip address by domain name include include include include include include define h addr h addr list 0 char getip char dn o...

JAVA根據IP位址獲取詳細的地域資訊

獲取自己電腦在外網的ip 在系統中,的頭部一般都有顯示是哪個城市的,使用者進入到 的首頁後,預設城市應該是使用者本地的城市資訊,例如 北京,就要根據你的ip位址的資訊,查詢資料,獲取北京部分的資料,呵呵,當然我可能描述的不是很清楚,但是可以理解成,通過ip位址定位地理資訊就行。很多人現在使用以qq資...