OpenAICloudflare Developer PlatformApr 20, 2026, 12:00 AM

R2 SQL - R2 SQL adds JSON functions, EXPLAIN FORMAT JSON, and unpartitioned table support

A condensed section focused on the key takeaways first.

Original Post

Quick Digest

Summary

A condensed section focused on the key takeaways first.

openaienmodel: gpt-5-mini-2025-08-07

R2 SQL adds JSON functions, EXPLAIN FORMAT JSON, and unpartitioned table support

Key Points

  • JSON functions for in-SQL JSON extraction
  • EXPLAIN FORMAT JSON emits structured plans
  • Query unpartitioned Iceberg tables (partition if >1000 files)

Summary

Cloudflare R2 SQL adds three practical features: SQL-level JSON functions for extracting and manipulating JSON stored in Apache Iceberg tables in R2 Data Catalog, an EXPLAIN FORMAT JSON mode that returns execution plans as structured JSON for programmatic analysis and observability, and support for querying unpartitioned Iceberg tables (useful for small or non-time-based datasets).

Key Points

  • JSON functions: new built-in functions like json_get_str, json_get_int, json_get_bool, and json_contains let you extract and test JSON values directly in queries without client-side parsing. Example: SELECT json_get_str(doc, 'name') AS name FROM my_namespace.sales_data WHERE json_contains(doc, 'email').
  • EXPLAIN FORMAT JSON: returns the query execution plan as structured JSON (machine-readable) so you can integrate plan output into observability tools or automated analysis. Example: EXPLAIN FORMAT JSON SELECT * FROM logpush.requests LIMIT 10;.
  • Unpartitioned table support: R2 SQL can query Iceberg tables that have no partition keys—handy for smaller datasets. For tables with more than ~1000 files, continue to prefer partitioning for performance.

Notes

  • Check the R2 SQL docs for the full list of JSON functions and EXPLAIN details before production use.
  • Use partitioning as a scalability optimization when table file counts grow beyond recommended thresholds.

Full Translation

Translations

A translation section that keeps the flow of the original article.

openaijamodel: gpt-5-mini-2025-08-07

R2 SQL — JSON関数、EXPLAIN FORMAT JSON、非パーティション化テーブルのサポートを追加

R2 SQL が JSON 関数、EXPLAIN FORMAT JSON、非パーティション化テーブルをサポート

R2 SQL は Cloudflare のサーバーレスで分散型の解析クエリエンジンで、R2 Data Catalog に保存された Apache Iceberg ↗ テーブルのクエリを実行します。今回、R2 SQL は以下をサポートします:

  • Apache Iceberg テーブル内に格納された JSON データを SQL 内で直接抽出・操作する JSON 関数
  • クエリ実行計画を構造化された JSON として取得できる EXPLAIN FORMAT JSON
  • R2 Data Catalog に保存されたパーティションキーを持たない(非パーティション化)テーブルのクエリ

JSON 関数

JSON 関数により、クライアント側で加工することなく SQL 内で JSON 値を抽出・操作できます。例:

SELECT json_get_str(doc, 'name') AS name,
       json_get_int(doc, 'user', 'profile', 'level') AS level,
       json_get_bool(doc, 'active') AS is_active
FROM my_namespace.sales_data
WHERE json_contains(doc, 'email')

利用可能な関数の完全な一覧は JSON functions を参照してください。

EXPLAIN FORMAT JSON

EXPLAIN FORMAT JSON はクエリ実行計画を構造化された JSON として返すため、プログラム的な解析や可観測性(observability)統合に利用できます。例: CLI での実行例:

npx wrangler r2 sql query " ${ WAREHOUSE } " "EXPLAIN FORMAT JSON SELECT * FROM logpush.requests LIMIT 10;"

出力例(要約):

{
  "plan": {
    "name": "CoalescePartitionsExec",
    "output_partitions": 1,
    "rows": 10,
    "size_approx": "310B",
    "children": [
      {
        "name": "DataSourceExec",
        "output_partitions": 4,
        "rows": 28951,
        "size_approx": "900.0KB",
        "table": "logpush.requests",
        "files": 7,
        "bytes": 900019,
        "projection": [
          "__ingest_ts",
          "CPUTimeMs",
          "DispatchNamespace",
          "Entrypoint",
          "Event",
          "EventTimestampMs",
          "EventType",
          "Exceptions",
          "Logs",
          "Outcome",
          "ScriptName",
          "ScriptTags",
          "ScriptVersion",
          "WallTimeMs"
        ],
        "limit": 10
      }
    ]
  }
}

詳細は EXPLAIN を参照してください。

非パーティション化 Iceberg テーブル

パーティションキーを持たない Iceberg テーブルを直接クエリできるようになりました。これは、時系列の自然な次元を持たない小規模データセットに有用です。ただし、ファイル数が 1000 を超えるテーブルでは、性能向上のためにパーティションを推奨します。

最新のガイダンスは Limitations and best practices を参照してください。

参考

  • JSON functions
  • EXPLAIN
  • R2 Data Catalog
  • Limitations and best practices