-
[GCP] Google BigQuery 빅쿼리 Schema 설계(feat. json 타입)GCP/BigQuery 2021. 8. 31. 23:17
JSON 타입의 데이터를 BigQuery에 적재하려고 할 때 각 필드별 데이터 타입에 맞춰 테이블 스키마를 설계해야 하는데,
하위 레벨의 nested 구조로 이루어진 json 타입에 맞춰 스키마를 설정하는 방법입니다.
Array : []
리스트안에 string으로 이루어진 데이터 value 타입
id:”1", name:”abc”, age:”20", address_history: [“current”, “previous”, “birth”]
BigQuery 스키마
여러개의 문자열들이 반복되어 이루어져 있으므로,
- Type: STRING
- Mode: REPEATED
Array Type Struct: {}
딕셔너리 안에 여러개의 key-value 값들로 이루어진 데이터
id:”1", name:”abc”, age:”20", address_history: { “status”:”current”, “address”:”London”, “postcode”:”ABC123D” }
BigQuery 스키마
Struct 타입은 RECORD로 표현할 수 있으므로,
- Type: RECORD
- Mode: NULLABLE
아래 하위 필드들에 포함 key 값들 추가하기
Struct Type Array of Structs
딕셔너리 안에 여러개의 딕셔너리가 리스트로 묶여져 있는 데이터 형태
id:”1", name:”abc”, age:”20", address_history: [ { “status”:”current”, “address”:”London”, “postcode”:”ABC123D” }, { “status”:”previous”, “address”:”New Delhi”, “postcode”:”738497" }, { “status”:”birth”, “address”:”New York”, “postcode”:”SHI747H” } ]
BigQuery 스키마
여러개의 Struct 타입들이 반복되어 이루어져 있으므로,
- Type: RECORD(Struct 타입에 쓰임)
- Mode: REPEATED
아래 하위 필드들에 포함 key 값들 추가하기
Array of Sructs *Column(필드) 삭제 후 재추가
시도한 작업에 실패했습니다. 다시 시도해 주세요.
추적 번호: c6300399935313203column 삭제 후 재추가 => 컬럼을 한번 삭제하면 같은 이름으로 생성이 안되므로, 테이블 삭제 후 새로 생성할 것!
ref.
https://medium.com/google-cloud/how-to-work-with-array-and-structs-in-bigquery-9c0a2ea584a6
How to work with Array and Structs in BigQuery
Everything about Array, Struct, Record, Repeated, nested schema, usage, query in Google BigQuery
medium.com
https://cloud.google.com/bigquery/docs/nested-repeated?hl=ko#console
테이블 스키마에 중첩 및 반복 열 지정 | BigQuery | Google Cloud
의견 보내기 테이블 스키마에 중첩 및 반복 열 지정 이 페이지에서는 BigQuery에서 중첩 및 반복 열이 있는 테이블 스키마를 정의하는 방법을 설명합니다. 테이블 스키마 개요는 스키마 지정을 참
cloud.google.com
- 이상 오늘의 삽질일기 끝:)
여기저기 삽질도 해보고
날려도 먹으면서
배우는 게
결국 남는거다
- Z.Sabziller