> ## Documentation Index
> Fetch the complete documentation index at: https://jmail.world/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# DuckDB / SQL

> HTTP 経由で Parquet ファイルを SQL で直接クエリする

[DuckDB](https://duckdb.org/) は、Parquet ファイルを HTTP 経由で、事前のダウンロードやセットアップなしに直接クエリできます。これはデータをインタラクティブに探索するための最速の方法です。

## セットアップ

DuckDB をインストールしてから、直接クエリを実行します：

```bash theme={null}
duckdb
```

```sql theme={null}
SELECT sender, COUNT(*) as n
FROM read_parquet('https://data.jmail.world/v1/emails-slim.parquet')
GROUP BY sender ORDER BY n DESC LIMIT 20;
```

## サンプルクエリ

### ![](https://mintcdn.com/jmail/F-FAi3RZzojcIyie/images/jmail-app.png?fit=max\&auto=format\&n=F-FAi3RZzojcIyie\&q=85\&s=3d45d0246f3c69c7024d9a467fcfad28) 送信者別のメール件数を集計

```sql theme={null}
SELECT sender, COUNT(*) as n
FROM read_parquet('https://data.jmail.world/v1/emails-slim.parquet')
GROUP BY sender ORDER BY n DESC LIMIT 20;
```

### ![](https://mintcdn.com/jmail/F-FAi3RZzojcIyie/images/jmail-app.png?fit=max\&auto=format\&n=F-FAi3RZzojcIyie\&q=85\&s=3d45d0246f3c69c7024d9a467fcfad28) Epstein が送信したメール

```sql theme={null}
SELECT subject, sent_at, to_recipients
FROM read_parquet('https://data.jmail.world/v1/emails-slim.parquet')
WHERE epstein_is_sender = true
ORDER BY sent_at DESC LIMIT 20;
```

### ![](https://mintcdn.com/jmail/F-FAi3RZzojcIyie/images/jdrive.png?fit=max\&auto=format\&n=F-FAi3RZzojcIyie\&q=85\&s=fbe04f350a6febb5b8e050cba1003c2c) ドキュメント検索

```sql theme={null}
SELECT original_filename, document_description, page_count
FROM read_parquet('https://data.jmail.world/v1/documents.parquet')
WHERE document_description ILIKE '%flight%'
LIMIT 20;
```

### ![](https://mintcdn.com/jmail/F-FAi3RZzojcIyie/images/jphotos.png?fit=max\&auto=format\&n=F-FAi3RZzojcIyie\&q=85\&s=e9f59aaa9fa1ebb967916b9d576f6018) 写真データを人物データと結合する

```sql theme={null}
SELECT p.name, COUNT(*) as appearances
FROM read_parquet('https://data.jmail.world/v1/photo_faces.parquet') pf
JOIN read_parquet('https://data.jmail.world/v1/people.parquet') p
  ON pf.person_id = p.id
GROUP BY p.name ORDER BY appearances DESC;
```

### エンティティタイプ別のスター数

```sql theme={null}
SELECT entity_type, SUM(count) as total_stars
FROM read_parquet('https://data.jmail.world/v1/star_counts.parquet')
GROUP BY entity_type ORDER BY total_stars DESC;
```

## Polars での利用

[Polars](https://pola.rs/) は HTTP 経由で Parquet を読み込むこともできます。

```python theme={null}
import polars as pl

df = pl.read_parquet("https://data.jmail.world/v1/emails-slim.parquet")
print(df.group_by("sender").len().sort("len", descending=True).head(20))
```

## pandas での利用

```python theme={null}
import pandas as pd

df = pd.read_parquet("https://data.jmail.world/v1/emails-slim.parquet")
print(df.groupby("sender").size().sort_values(ascending=False).head(20))
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.