{"id":583,"date":"2020-01-11T22:00:11","date_gmt":"2020-01-11T13:00:11","guid":{"rendered":"http:\/\/kei0310.info\/?p=583"},"modified":"2020-01-11T22:37:08","modified_gmt":"2020-01-11T13:37:08","slug":"post-583","status":"publish","type":"post","link":"http:\/\/kei0310.info\/?p=583","title":{"rendered":"BigQuery\u306b\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u304b\u3089\u30d0\u30c3\u30c1\u30ed\u30fc\u30c9\u307e\u3067\u3057\u305f\u30e1\u30e2"},"content":{"rendered":"<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u4f5c\u6210\u3001\u8ab2\u91d1\u8a2d\u5b9a\u307e\u3067\u3057\u3066\u3044\u308b\u524d\u63d0\u3002<\/p>\n<h2>\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u4f5c\u6210<\/h2>\n<pre class=\"lang:default decode:true\" title=\"dataset\u306e\u4f5c\u6210\">$ bq mk --dataset test_dataset_batch_load\r\nDataset 'xxxxxxxx:test_dataset_batch_load' successfully created.<\/pre>\n<h2>\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210<\/h2>\n<pre class=\"lang:default decode:true\" title=\"\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\">$ bq mk --table test_dataset_batch_load.test_batch_load id:int64,user_id:int64,name:string\r\nTable 'xxxxxxxx:test_dataset_batch_load.test_batch_load' successfully created.<\/pre>\n<h2>\u30c7\u30fc\u30bf\u306e\u4f5c\u6210\uff08\u30c7\u30fc\u30bf\u304c\u306a\u3044\u5834\u5408\uff09<\/h2>\n<p>\u3053\u3093\u306a\u304b\u3093\u3058\u3067\u30c7\u30fc\u30bf\u4f5c\u6210<\/p>\n<pre class=\"lang:default decode:true \" title=\"\u30c7\u30fc\u30bf\u4f5c\u6210\">$ find . -type f\r\n.\/data\/data1_tsv0000.gz\r\n.\/data\/data1_tsv0001.gz\r\n.\/data\/data1_tsv0002.gz\r\n\r\n$ zcat .\/data\/data1_tsv0000.gz\r\n0       1       a\r\n1       2       b\r\n2       3       c\r\n3       4       d<\/pre>\n<h2>\u30c7\u30fc\u30bf\u3092GCS\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9<\/h2>\n<pre class=\"lang:default decode:true \" title=\"\u30c7\u30fc\u30bf\u3092GCS\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\">$ gsutil cp -r .\/data gs:\/\/[your-gcs-bucket]\/test_batch_load\/data\r\nCopying file:\/\/.\/data\/data1_tsv0000.gz [Content-Type=application\/octet-stream]...\r\nCopying file:\/\/.\/data\/data1_tsv0001.gz [Content-Type=application\/octet-stream]...\r\nCopying file:\/\/.\/data\/data1_tsv0002.gz [Content-Type=application\/octet-stream]...\r\n\/ [3 files][  233.0 B\/  233.0 B]                                                \r\nOperation completed over 3 objects\/233.0 B.<\/pre>\n<h2>\u30c7\u30fc\u30bf\u3092GCS\u304b\u3089BigQuery\u306b\u30ed\u30fc\u30c9<\/h2>\n<pre class=\"lang:default decode:true \">$ bq load --source_format=CSV --field_delimiter=\"\\t\" test_dataset_batch_load.test_batch_load gs:\/\/[your-gcs-bucket]\/test_batch_load\/data\/data1_tsv*.gz \"id:int64,user_id:int64,name:STRING\"\r\nWaiting on bqjob_r5ac7adb308d60126_0000016f94af5c50_1 ... (1s) Current status: DONE<\/pre>\n<h2>\u30ed\u30fc\u30c9\u3057\u305f\u30c7\u30fc\u30bf\u3092\u30af\u30a8\u30ea\u3057\u3066\u307f\u308b<\/h2>\n<pre class=\"lang:default decode:true \" title=\"\u30ed\u30fc\u30c9\u3057\u305f\u30c7\u30fc\u30bf\u3092\u30af\u30a8\u30ea\u3057\u3066\u307f\u308b\">$ bq query --nouse_legacy_sql \"select id, user_id, name from test_dataset_batch_load.test_batch_load\"\r\nWaiting on bqjob_r35337cdceedf0638_0000016f94c91977_1 ... (0s) Current status: DONE   \r\n+----+---------+--------------------------------------------+\r\n| id | user_id |                    name                    |\r\n+----+---------+--------------------------------------------+\r\n|  5 |       6 | adsfad                                     |\r\n|  6 |       7 | ka;lkd;l                                   |\r\n|  8 |       9 | dka;dkie                                   |\r\n| 10 |      10 | ,cvzfjf                                    |\r\n| 11 |      11 | tetrwttrytyetytytyrtytrtyryuyujkhjknkm,nm, |\r\n| 12 |      34 | lf,g5f5v5e5fg                              |\r\n|  0 |       1 | a                                          |\r\n|  1 |       2 | b                                          |\r\n|  2 |       3 | c                                          |\r\n|  3 |       4 | d                                          |\r\n+----+---------+--------------------------------------------+<\/pre>\n<h2>\u3061\u306a\u307f\u306b\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u5168\u91cf<\/h2>\n<p>\u3042\u3063\u3066\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \" title=\"\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u5168\u91cf\">$ find . -type f | xargs -I {} bash -c \"echo {}; zcat {}\"\r\n.\/data\/data1_tsv0000.gz\r\n0       1       a\r\n1       2       b\r\n2       3       c\r\n3       4       d\r\n.\/data\/data1_tsv0001.gz\r\n5       6       adsfad\r\n6       7       ka;lkd;l\r\n8       9       dka;dkie\r\n.\/data\/data1_tsv0002.gz\r\n10      10      ,cvzfjf\r\n11      11      tetrwttrytyetytytyrtytrtyryuyujkhjknkm,nm,\r\n12      34      lf,g5f5v5e5fg<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u4f5c\u6210\u3001\u8ab2\u91d1\u8a2d\u5b9a\u307e\u3067\u3057\u3066\u3044\u308b\u524d\u63d0\u3002 \u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u4f5c\u6210 $ bq mk --dataset test_dataset_batch_load Dataset 'xxxxxxxx:test_dataset_batc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[213,212],"tags":[],"_links":{"self":[{"href":"http:\/\/kei0310.info\/index.php?rest_route=\/wp\/v2\/posts\/583"}],"collection":[{"href":"http:\/\/kei0310.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kei0310.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kei0310.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/kei0310.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=583"}],"version-history":[{"count":5,"href":"http:\/\/kei0310.info\/index.php?rest_route=\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":588,"href":"http:\/\/kei0310.info\/index.php?rest_route=\/wp\/v2\/posts\/583\/revisions\/588"}],"wp:attachment":[{"href":"http:\/\/kei0310.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kei0310.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kei0310.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}