简体   繁体   English

如何在 BigQuery 中检索 IP 地址的地理位置信息?

[英]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.

相关问题 如何在我的 Cloud-Run Flask 应用程序中获取用户的 IP 地址? - How can I get the user's IP-Address in my Cloud-Run Flask app? 使用 API 密钥从外部 IP 地址检索 PubSub Schema - Retrieve PubSub Schema from external IP address with API Key 如何在 BigQuery 中编写条件 string_agg 函数? - How can I write a conditional string_agg function in BigQuery? 如何解决 BigQuery 中的“在美国位置找不到数据集”错误? - How can I solve the error "Dataset was not found in location US" in BigQuery? 如何将动态 IP 地址添加到 Google Cloud 中的“授权 javascript 来源”列表中,以便将 Google 登录集成到我的 web 应用程序中? - How can I add a dynamic IP address to the "Authorised javascript origins" list in Google Cloud so that I can integrate Google sign-in into my web app? 如何使用 google cloud bigquery 进行集成测试 - How can I make integration tests with google cloud bigquery 如何在 BigQuery 中取消连接字符串,删除另一列中存在的初始 substring? - How can I de-concatenate a string in BigQuery, removing the initial substring that exists in another column? 在 bigquery 中,如何检查一个数组中的至少一个元素是否在另一个数组中? - In bigquery how can I check if at least one elemnt from one array is in another array? 如何使用 firebase 数据库存储和检索数组值? - How can i stored and retrieve an array value using firebase database? 如何在 BigQuery 中随机匹配元素 - How Do I Randomly Match Elements in BigQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM