Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 10 additions & 33 deletions src/content/articles/getting-started-bigquery.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ difficulty: beginner
published: false
---

M-Lab publishes all measurement data to Google BigQuery as a free, open dataset. Access is sponsored by M-Lab — queries against the `measurement-lab` project don't come out of your own GCP quota — but you must join the M-Lab Discuss group first to activate that sponsorship. **Saving query results to your own BigQuery tables, or running queries billed to your own project, will incur charges to you.**
M-Lab publishes all measurement data to [Google BigQuery](https://cloud.google.com/bigquery/what-is-bigquery) as a free, open dataset. Access is sponsored by M-Lab — queries against the `measurement-lab` project don't come out of your own GCP quota — but you must join the M-Lab Discuss group first to activate that sponsorship. **Saving query results to your own BigQuery tables, or running queries billed to your own project, will incur charges to you.**

Questions? Email [support@measurementlab.net](mailto:support@measurementlab.net).

Expand Down Expand Up @@ -44,38 +44,28 @@ BigQuery's `bq` command-line tool is now available and queries against `measurem

If you need to query from an application using a service account (`@developer.gserviceaccount.com`), email [support@measurementlab.net](mailto:support@measurementlab.net) so M-Lab can add it to M-Lab Discuss manually. Ensure the account has the **BigQuery User**, **BigQuery Job User**, and **BigQuery Data Viewer** IAM roles on the `measurement-lab` project.

## Key Datasets

| Dataset | Description |
|---------|-------------|
| `ndt` | NDT speed tests — use `ndt7_union` for general analysis |
| `ndt_raw` | Raw NDT archives including traceroute and TCP info |
| `msak` / `msak_raw` | Multi-stream throughput measurements |
| `wehe_raw` | App-specific traffic differentiation tests |

For most use cases, start with `measurement-lab.ndt.ndt7_union`.

## Your First Query

Average download speed by country for the last 30 days:
For speed test results, you can start with the `measurement-lab.ndt.ndt7_union` table.
For example, for the average download speed by country for the last 30 days:

<!-- sqltest -->
```sql
-- Average download speed by country for the last 30 days
-- Median download speed by country for a day
SELECT
client.Geo.CountryCode AS country,
ROUND(AVG(a.MeanThroughputMbps), 2) AS avg_download_mbps,
ROUND(APPROX_QUANTILES(a.MeanThroughputMbps, 2)[OFFSET(1)], 2) AS median_download_mbps,
COUNT(*) AS test_count
FROM `measurement-lab.ndt.ndt7_union`
WHERE date >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
WHERE date = '2024-06-01'
AND a.MeanThroughputMbps > 0
AND a.MeanThroughputMbps < 10000 -- exclude outliers
GROUP BY country
ORDER BY avg_download_mbps DESC
ORDER BY median_download_mbps DESC
LIMIT 20
```

## Understanding the Schema
### Understanding the Schema

NDT7 results have a nested structure. The key top-level fields are:

Expand Down Expand Up @@ -103,20 +93,9 @@ server.Site — M-Lab site ID (e.g., "lga01")
server.Metro — metro area (e.g., "lga" for New York)
```

## Unified Views vs. Raw Tables

M-Lab provides both raw tables and cleaned **unified views**:

- `measurement-lab.ndt.ndt7_union` — **recommended** for most analysis; quality-filtered, includes M-Lab-managed and Host-Managed server data
- `measurement-lab.ndt.ndt7` — M-Lab-managed servers only
- `measurement-lab.ndt.ndt7_dynamic` — Host-Managed servers only
- `measurement-lab.ndt_raw.*` — unfiltered 1-to-1 archives; use only if you need test failures or custom quality logic

The unified views exclude tests shorter than 9 seconds, tests with less than 8 KB transferred, and M-Lab's own monitoring traffic.

## Query Costs and Partition Pruning

The NDT7 table is large (~5 TB/month of new data). **Always** filter by `DATE(a.TestTime)` to use BigQuery's partition pruning:
The NDT7 table is large (~0.5 TB/day of new data). **Always** filter by `DATE(a.TestTime)` to use BigQuery's partition pruning:

```sql
-- Efficient: uses partition pruning
Expand All @@ -126,7 +105,7 @@ WHERE DATE(a.TestTime) = '2024-06-01'
WHERE a.TestTime > '2024-06-01'
```

Use the **preview** feature in the BigQuery UI to inspect data before running queries, and add `LIMIT` clauses during development.
Use the **preview** feature in the BigQuery UI to inspect data before running queries. The daily query limit per user per day is currently set to 10TiB.

## Exporting Data

Expand All @@ -151,8 +130,6 @@ AS (
## Further Reading

- [M-Lab BigQuery Schema](https://www.measurementlab.net/data/docs/bq/schema) — full schema documentation
- [Google BigQuery documentation](https://cloud.google.com/bigquery/what-is-bigquery)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we're removing links to content that can help our user's and community members place jargon (like BigQuery) in a broader context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the level of detail / tech depth of the article. We assume users have basic understading of these systems. Otherwise half of the content cannot be understood. Or, alternatively, we would need to provide links for all systems referred in there (e.g., Google Cloud Console, SKD, etc.)

However, you're correct that we should help our users, in case they are not familiar with these systems. I'm adding this link in the beginning of the article, inline with the text, similarly to the Google Cloud Console, etc.

- [Querying date-partitioned tables](https://cloud.google.com/bigquery/docs/querying-partitioned-tables)
- [NDT (Network Diagnostic Tool)](../test-ndt) — the primary dataset
- [Analyzing M-Lab Data: A Researcher's Guide](../research-guide) — ISP comparison patterns and advanced queries

Expand Down
Loading