Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
BigQuery Schema Migration #bq_sushi
Search
Naotoshi Seo
April 08, 2016
Technology
6.2k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
BigQuery Schema Migration #bq_sushi
Naotoshi Seo
April 08, 2016
More Decks by Naotoshi Seo
See All by Naotoshi Seo
ZOZOTOWNリプレイス2020
sonots
5
40k
Red Chainer and Cumo: Practical Deep Learning in Ruby at RubyKaigi 2019
sonots
1
4.9k
Introduction of Cumo, and Integration to Red Chainer
sonots
1
1.3k
Implementation of Cumo, a CUDA-aware version of Ruby/Numo
sonots
1
2.1k
Fast Numerical Computing and Deep Learning in Ruby with Cumo
sonots
0
10k
CuPy improvments around memory
sonots
3
1.8k
DeNA AIシステム部におけるクラウドを活用した機械学習基盤の構築
sonots
4
6.4k
Triglav - Data Driven Workflow Tool
sonots
1
4.4k
DeNA流データエンジニアリングの極意
sonots
17
13k
Other Decks in Technology
See All in Technology
Execution in the Kingdom of Agents: Reflections on Abstraction and Complexity
bcantrill
0
750
FinTech 1-2 : Overview of FinTech
ks91
PRO
0
130
VS Code × GitHub Copilot での Fabric 開発
ryomaru0825
1
220
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
270
[2026 Oracle Technical Deep Dive] エンタープライズAIエージェントを支えるOCIソリューション。ラインナップと特徴を理解しよう! (2026年9月17日開催)
oracle4engineer
PRO
0
280
Snowflake Horizon Catalog と Apache Iceberg で作る オープンなデータ基盤
kitagawaz
0
390
HolmesGPTで始めるSREエージェント入門!プラットフォームの障害調査はAIにお任せ 〜
leveragestech
PRO
0
140
AI臭い文章とは何なのか
nasuvitz
38
77k
【データ横丁主催】AI Agentがコンテキストを使って仕事をした後、何が残るのか― 組織の経験を次の判断に引き継ぐ「Agent Memory」
shisyu_gaku
2
320
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
16
120k
認知負荷を吸収し、プロダクトをまたぐPR Preview基盤の設計事例
taiki45
2
570
Meet AgentCore Identity Consent Portal
hironobuiga
3
160
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
470
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
We Have a Design System, Now What?
morganepeng
55
8.3k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
780
HDC tutorial
michielstock
2
940
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
620
How to Talk to Developers About Accessibility
jct
2
560
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
700
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Transcript
#JH2VFSZͷςʔϒϧΛ .JHSBUF ΧϥϜՃɺআɺ ܕมߋ ͢Δ 2016/04/08 @sonots #bq_sushi 3
ࣗݾհ • ඌར @sonots • DeNA ੳج൫ • Fluentd ίϛολ
• Ruby ίϛολ • ࠷ۙ embulk ۀ • embulk-output-bigquery • embulk-filter-column, etc
• 4݄23ൃചʂ • σʔλऩूಛू • Fluentd / Embulk • DeNA
/ Cookpad ͷࣄྫ
ΞδΣϯμ • ฐࣾͰͷ BigQuery ར༻ • εΩʔϚมߋͷඞཁੑ • BigQuery ʹ͓͚ΔεΩʔϚมߋͷࠔ͞
• εΩʔϚมߋͷઓུ
ฐࣾͰͷ BigQuery ར༻ • West (US) Ͱ̍Ҏ্લ͔Βར༻ • JP ͰϘνϘν͍࢝Ί͍ͯΔ
• σʔλҠߦπʔϧ࡞ͬͯΔ • hdfs2bigquery • vertica2bigquery • bigquery2hdfs • bigquery2vertica
ฐࣾͰͷੳۀ • σʔλҠߦ Hadoop/Vertica ӡ༻ج൫νʔϜ • ੳۀΞφϦετ͕ߦ͏ • BigQuery ʹΫΤϦΛ͛ΔͷΞφϦετ
εΩʔϚมߋͷඞཁੑ(1) • ϩάʹΧϥϜ͕Ճ͞Εͨ • ͬͺΓΧϥϜ͕ফ͞Εͨ • ΧϥϜͷܕΛؒҧ͑ͨ • INTEGER ͬΆ͍ͱࢥͬͯͨΒ
11,12 Έ͍ͨͳ ͕ೖͬͯΔߦ͕͋ͬͯ STRING ͡Όͳ͍ͱμϝ ͩͬͨͱ͔͋Δ͋Δ
εΩʔϚมߋͷඞཁੑ(2) • BigQuery ςʔϒϧ໊ϕετϓϥΫςΟε • ςʔϒϧ໊લஔࢺ_ˋY%m%d • ຖ৽͘͠ςʔϒϧΛ࡞Δ • ຖεΩʔϚ࠶ఆٛͷνϟϯε͕͋Δ
• εΩʔϚมߋ͠ͳͯ͘ྑ͍͡ΌΜʁ
εΩʔϚมߋͷඞཁੑ(3) • ̎ͭͷςʔϒϧͰΧϥϜͷܕ͕ҧ͏ͱΤϥʔʂ SELECT name FROM TABLE_DATE_RANGE(data.people_, TIMESTAMP('2014-03-26'), TIMESTAMP('2014-03-27')) WHERE
age >= 35 • Ωϟετ͢Δͱ͍͏ख͋Δ͕ɺੳ࣌ଞͷ͜ ͱʹ಄Λ͍͍ͨͷͰආ͚͍ͨ
εΩʔϚมߋπʔϧͷఏڙ • ͋Δ͖࢟(εΩʔϚ)Λఏࣔ͢Δͱɺ • ΧϥϜͷՃ • ΧϥϜͷআ • ΧϥϜͷܕมߋ •
Λࣗಈผͯ͠ɺεΩʔϚมߋͰ͖ΔΑ͏ʹ ͍ͯ͋͛ͨ͠
BigQuery ʹ͓͚Δ εΩʔϚมߋͷࠔ͞
εΩʔϚมߋͷࠔ • BigQuery ʹ ALTER TABLE ͕ͳ͍ • ΧϥϜՃͷAPI͋Δ •
ΧϥϜআɺܕมߋͷ API ͕ͳ͍ Ͳ͏͢Δ͔ʁͱ͍͏
ΧϥϜՃ • patch_table (or update_table) API ͰͰ͖Δ client.patch_table(project_id, dataset_id, table_id,
{ schema: { fields: [ {name:"time", type:"TIMESTAMP", mode:"NULLABLE"}, {name:"id", type:"INTEGER", mode:"NULLABLE"}, ] } }) google-api-ruby-client
ΧϥϜՃ(ҙ) • ͢Ͱʹ͋ΔεΩʔϚ + Ճ͢ΔΧϥϜ • get_table ͰεΩʔϚΛऔಘͯ͠Ϛʔδͯ͛͠Δ response =
get_table(project_id, dataset_id, table_id) columns = response.schema.fields.map {|col| col.to_h } columns << {name:"id", type:"INTEGER", mode:"NULLABLE"} google-api-ruby-client
patch tables ͷ੍ • Ճͨ͠ΧϥϜඌʹՃ͞ΕΔ • ՃͰ͖Δͷ NULLABLE ·ͨ REPEATED
͚ͩ • mode: REQUIRED ͳΧϥϜ͕ՃͰ͖ͳ͍ • มߋ REQUIRED => NULLABLE ͚ͩ • NULLABLE Λ REQUIRED ʹͰ͖ͳ͍ • REPEATED ʹͰ͖ͳ͍
ΧϥϜআɺܕมߋ
ΧϥϜআɺܕมߋ • ̎ͭͷઓུ • (1) export & filter & load
• (2) select & copy
(1) export & filter & load • gcs ʹ export
• embulk ΒͳʹΒͰ download ͭͭ͠Λม ͢Δ filtering ॲཧΛߦ͏ • BQ ʹ load ͠ͳ͓͢
(1) export & filter & load • ར • ՝ۚ͞Εͳ͍
• ܽ • ҰϩʔΧϧʹμϯϩʔυ্ͯ͛͢͠ ͜ͱʹͳΔͷͰඇৗʹ͍ɻɻɻ
(2) select & copy • insert_job API ʹ query ͱ
destination_table Λࢦఆ insert_job(project_id, { configuration: { query: { query:"SELECT ... FROM [...]", destination_table: { dataset_id: dataset_id, table_id: table_id }, } } }, {})
(2) select & copy ͷྫ SELECT STRING(business_id) AS business_id, STRING(full_address)
AS full_address, schools, BOOLEAN(open) AS open, FROM [dataset_id.table_id] • ΩϟετͰܕมߋ • ੍: ܕมߋ͢Δͱ mode: NULLABLE ʹͳΔ • ࢦఆ͠ͳ͔ͬͨΧϥϜআ͞ΕΔ
(2) select & copy • ར • ͍ • ܽ
• ՝ۚ͞ΕΔ
(2) select & copy Λ࠾༻ (1) export & filter &
load ΔͳΒ HDFS͔ΒσʔλLoadΓͯ࣌ؒ͋͠·ΓมΘΒͳ͍ ...
Further dive into select & copy
RECORD ܕͷΩϟετํ๏ SELECT INTEGER(votes.funny) AS votes.funny, INTEGER(votes.useful) AS votes.useful, INTEGER(votes.cool)
AS votes.cool, FROM [dataset_id.table_id] • υοτ۠ΓͰࢦఆ͢Δ
select & copy ͰͷΧϥϜՃ SELECT column1, INTEGER(NULL) AS column2, INTEGER(NULL)
AS (record.column3), FROM [dataset_id.table_id] • INTEGER ܕͷ column2 ΛՃ • RECORD ܕͷ record ΧϥϜͰͳ͘ record_column3 ͱ͍͏໊લͷΧϥϜ͕Ͱ͖Δɻɻɻ • patch table API ͬͨ΄͏͕ྑͦ͞͏ɻɻɻ
mode: REPEATED ΧϥϜͷࢦఆ • SELECT ͰࢦఆͰ͖Δ REPEATED ΧϥϜ̍ͭͩ ͚ɺͳͲͷ੍͕͋ͬͨΓ •
SELECT ͢Δͱߦ͕૿͑ΔͷͰɺREPEATED Χϥ Ϝͷͳ͍ߦ͕૿͑ͨςʔϒϧΛ࡞Δ͜ͱʹͳΔ • Ͳ͏ݫͦ͠͏
Atomic ͳςʔϒϧͷஔ • ௨ৗͷઓུ • มલͷςʔϒϧ => มޙ • atomic
ʹ swap • BigQuery ʹ rename ͕ͳ͍ʂແཧʂʁ • copy ͷ destination_table Λࣗࣗʹࢦఆ • atomic ʹ swap ͞ΕΔʂʂ
·ͱΊ
·ͱΊΔͱ • ΧϥϜͷՃ͕ඞཁͳ߹ɺ·ͣ patch table • ΧϥϜͷআɺ·ͨܕมߋ͕ඞཁͳ߹ɺ ͔ͦ͜Β͞Βʹ select &
copy • copyઌࣗࣗΛࢦఆ͢Δ͜ͱͰ atomic ʹ swap Ͱ͖Δ
੍ • mode: REPEATED ΧϥϜΛѻ͑ͳ͍ • mode: NULLABLE ΧϥϜͷΈՃՄೳ •
ܕมߋ͢Δͱ mode: NULLABLE ʹͳΔ
https://github.com/sonots/bigquery_migration/
͍ํ require 'bigquery_migration' config = { json_keyfile: '/path/to/your-project-000.json' dataset: 'your_dataset_name'
table: 'your_table_name' } columns = [ { name: 'string', type: 'STRING' }, { name: 'record', type: 'RECORD', fields: [ { name: 'integer', type: 'INTEGER' }, { name: 'timestamp', type: 'TIMESTAMP' }, ] } ] migrator = BigqueryMigration.new(config) migrator.migrate_table(columns: columns)
• 4݄23ൃചʂ • σʔλऩूಛू • Fluentd / Embulk • DeNA
/ Cookpad ͷࣄྫ