- BigQuery 教程
- BigQuery - 首頁
- BigQuery - 概述
- BigQuery - 初始設定
- BigQuery 與本地 SQL 引擎
- BigQuery - Google Cloud Console
- BigQuery - Google Cloud 層次結構
- 什麼是 Dremel?
- 什麼是 BigQuery Studio?
- BigQuery - 資料集
- BigQuery - 表
- BigQuery - 檢視
- BigQuery - 建立表
- BigQuery - 基本模式設計
- BigQuery - 修改表
- BigQuery - 複製表
- 刪除和恢復表
- BigQuery - 填充表
- 標準 SQL 與傳統 SQL
- BigQuery - 編寫第一個查詢
- BigQuery - CRUD 操作
- 分割槽和聚類
- BigQuery - 資料型別
- BigQuery - 複雜資料型別
- BigQuery - STRUCT 資料型別
- BigQuery - ARRAY 資料型別
- BigQuery - JSON 資料型別
- BigQuery - 表元資料
- BigQuery - 使用者定義函式
- 連線到外部資料來源
- 整合計劃查詢
- 整合 BigQuery API
- BigQuery - 整合 Airflow
- 整合連線的表格
- 整合資料傳輸
- BigQuery - 物化檢視
- BigQuery - 角色和許可權
- BigQuery - 查詢最佳化
- BigQuery - BI 引擎
- 監控使用情況和效能
- BigQuery - 資料倉庫
- 挑戰和最佳實踐
- BigQuery 資源
- BigQuery - 快速指南
- BigQuery - 資源
- BigQuery - 討論
BigQuery - STRUCT 資料型別
STRUCT 和 ARRAY 是開發人員在 BigQuery 的列式結構中儲存巢狀資料的方式。
什麼是 Struct?
STRUCT 是一組具有指定型別(必需)和欄位名稱(可選)的欄位的集合。值得注意的是,與 ARRAY 不同,STRUCT 型別可以包含混合的資料型別。
為了更好地理解 STRUCT 型別,請再次檢視上一章中的示例,現在進行了一些更改。
"locations": [
{"store_no": 4, "employee_count": 15, "store_name": "New York 5th Ave"},
{"store_no": 5, "employee_count": 30, "store_name": "New York Lower Manh"}
]
之前“locations”是相同型別的**字典**(用 JSON 表示),現在它包含兩個 STRUCT,其型別為**<整數,整數,字串>**。
- 儘管支援 STRUCT 型別,但在表建立階段,BigQuery 沒有提供顯式的 STRUCT 標籤。
- 相反,STRUCT 表示為具有 NULLABLE 模式的 RECORD。
**注意** - 將 STRUCT 視為容器而非專用資料型別。
在模式中定義時,STRUCT 內部的元素將用“.”表示和選擇。此處,**模式**將為 -
{"locations", "RECORD", "NULLABLE"},
{"locations.store_no", "INTEGER", "NULLABLE},
{"locations.employee_count", "INTEGER", "NULLABLE"},
{"locations.store_name", "STRING", "NULLABLE"}
點表示法
要選擇 STRUCT 元素,需要在 FROM 子句中使用**點表示法** -
查詢執行後,您可能會得到如下**輸出** -
廣告