[英]How I can retrieve geolocation info for an IP Address in BigQuery?
I have a table in BigQuery containing my customers' IP addresses, and I want to understand their geographical distribution.我在 BigQuery 中有一个包含客户 IP 地址的表,我想了解他们的地理分布。
Is there any way I can retrieve geolocation information for these IP addresses, like city, state, and country using SQL?有什么方法可以使用 SQL 检索这些 IP 地址的地理位置信息,例如城市、州和国家/地区?
To retrieve geolocation information for an IP Address or identify its physical location you need to use a Geolocation database.要检索 IP 地址的地理位置信息或确定其物理位置,您需要使用地理位置数据库。
There is a service called MaxMind that provides a free/lite version of the Geolocation database, that you can use.有一个名为MaxMind的服务提供免费/精简版的地理定位数据库,您可以使用。
You can then write a function in Python to use this database and retrieve the geolocation information like city state and country for the specified IP.然后,您可以在 Python 中编写一个函数来使用此数据库并检索指定 IP 的地理位置信息,例如城市州和国家/地区。
In a recent release, BigQuery announced the support of Remote Functions that can be used to wrap Python functions into a SQL function that can be used in your queries.在最近的版本中,BigQuery 宣布支持远程函数,可用于将 Python 函数包装到可在查询中使用的 SQL 函数中。
I wrote a step-by-step tutorial on how to achieve that.我写了一个关于如何实现这一目标的分步教程。
There was a post about doing it efficiently using Geolite2 in GCP blog:在 GCP 博客中有一篇关于使用 Geolite2 高效执行此操作的帖子:
https://cloud.google.com/blog/products/data-analytics/geolocation-with-bigquery-de-identify-76-million-ip-addresses-in-20-seconds/ https://cloud.google.com/blog/products/data-analytics/geolocation-with-bigquery-de-identify-76-million-ip-addresses-in-20-seconds/
The query used Felipe fh-bigquery
dataset, that you'll need to recreate using Geolite2 source.该查询使用了 Felipe
fh-bigquery
数据集,您需要使用 Geolite2 源重新创建该数据集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.