Hugging Face, End to EndLesson 42 of 75

Module 5 · Datasets, and the work that happens before any model

Query a dataset with SQL before downloading it

In this lesson

  • 8 min read
  • 8 reading sections
  • Knowledge check
  • Lesson 5 of 10 in this chapter

This chapter’s goalInspect, stream, filter and transform a dataset far larger than your RAM, query the Hub’s parquet conversion with SQL before downloading anything, run duplicate, leakage and class-balance checks on your own data, and publish it with a card stating provenance and licence.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch2:05Not available
Full audiobookNot availableNot available
How a filtered Parquet query reads dataRead metadataColumn and row-groupinformationApply the filterSkip groups whenstatistics rule themoutRead needed columnsFetch the relevantdata rangesCount matching rowsAggregate the selectedfilesA filter may rule out row groups using metadata. The query reads the required columns from theremaining groups and calculates the exact result for the selected files.
A filter may rule out row groups using metadata. The query reads the required columns from the remaining groups and calculates the exact result for the selected files.

Figure

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 10Free · no account needed
Lesson steps

The conversion nobody mentions

The Hub Dataset Viewer provides Parquet files for supported datasets. Its Parquet endpoint lists available files and indicates when conversion is partial. Check the split and whether the listed files cover your question.

DuckDB can query remote Parquet files directly. You can count labels or inspect lengths without manually downloading an entire dataset first.

DuckDB, which is free and is one pip install

Bash
pip install duckdb requests
Python
import duckdb
import requests

endpoint = (
    "https://datasets-server.huggingface.co/parquet"
)
response = requests.get(
    endpoint,
    params={"dataset": "stanfordnlp/imdb"},
    timeout=20,
)
response.raise_for_status()
payload = response.json()
if payload.get("partial") or payload.get("failed"):
    raise RuntimeError("Parquet files are incomplete")
files = payload["parquet_files"]
train = [
    item["url"] for item in files
    if item["split"] == "train"
    and item["config"] == "plain_text"
]
if not train:
    raise RuntimeError("No train Parquet files listed")
q = """
SELECT label, COUNT(*) AS n
FROM read_parquet(?)
GROUP BY label
ORDER BY label
"""
print(duckdb.execute(q, [train]).fetchall())

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Image Generation, in Practice exam.

Stuck on something?Ask Arjun, your AI tutor

How to cite: Addaly (2026) ‘Query a dataset with SQL before downloading it’, in Hugging Face, End to End. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/hugging-face/the-viewer-and-sql (Accessed: 29 November 2026).