Skip to content

ip2continent_name

ip2continent_name(ip)

Description

Get continent of ip

This functions uses IP address data powered by IPinfo and released under Creative Commons Attribution-ShareAlike 4.0 International License. You are required to attribute IPinfo to use their free datasets. The attribution requirements can be met by giving their service credit as your data source. Simply place a link to IPinfo on the website, application, or social media account that uses their data.

Usage

Call or Deploy ip2continent_name ?
Call ip2continent_name directly

The easiest way to use bigfunctions

  • ip2continent_name function is deployed in 39 public datasets for all of the 39 BigQuery regions.
  • It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)

Public BigFunctions Datasets

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...
Deploy ip2continent_name in your project

Why deploy?

  • You may prefer to deploy ip2continent_name in your own project to build and manage your own catalog of functions.
  • This is particularly useful if you want to create private functions (for example calling your internal APIs).
  • Get started by reading the framework page

Deployment

ip2continent_name function can be deployed with:

pip install bigfunctions
bigfun get ip2continent_name
bigfun deploy ip2continent_name

Requirements

ip2continent_name uses the following secrets. Get them by reading the documentation link and store them in Google Secret Manager in the project where you deploy the function (and give Accessor role to the service account of the function):

name description documentation to get the secret
ipinfo_token IP Info Token doc

Examples

select bigfunctions.eu.ip2continent_name("152.216.7.110")
select bigfunctions.us.ip2continent_name("152.216.7.110")
select bigfunctions.europe_west1.ip2continent_name("152.216.7.110")
+---------------+
| continent     |
+---------------+
| North America |
+---------------+

Use cases

You have web server logs stored in BigQuery that contain the IP addresses of visitors. You want to analyze traffic patterns by continent. You can use the ip2continent_name function to add a "continent" column to your log data:

#standardSQL
SELECT
    timestamp,
    request,
    userAgent,
    clientIp,
    bigfunctions.us.ip2continent_name(clientIp) AS continent  -- Assuming your data is in US region
  FROM
    `your_project.your_dataset.your_webserver_logs`;

This query adds a continent column derived from the clientIp column. You can then use this new column for aggregations and reporting:

#standardSQL
SELECT
    continent,
    COUNT(*) AS visit_count
  FROM (
    SELECT
        bigfunctions.us.ip2continent_name(clientIp) AS continent
      FROM
        `your_project.your_dataset.your_webserver_logs`
  )
  GROUP BY continent
  ORDER BY visit_count DESC;

This would give you a breakdown of the number of visits from each continent. Remember to replace your_project.your_dataset.your_webserver_logs with the actual path to your table and select the appropriate BigQuery region for the function call (e.g., bigfunctions.eu, bigfunctions.asia_northeast1, etc.) based on your data location.


Need help or Found a bug?
Get help using ip2continent_name

The community can help! Engage the conversation on Slack

We also provide professional suppport.

Report a bug about ip2continent_name

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

We also provide professional suppport.


Show your ❤ by adding a ⭐ on