{"id":354,"date":"2019-09-20T22:05:16","date_gmt":"2019-09-20T13:05:16","guid":{"rendered":"http:\/\/localhost:8000\/?p=354"},"modified":"2021-01-23T12:20:08","modified_gmt":"2021-01-23T03:20:08","slug":"bigquery","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2019\/09\/bigquery.html","title":{"rendered":"BigQuery\u306eTips"},"content":{"rendered":"

BigQuery\u95a2\u4fc2\u306eTips\u3092\u307e\u3068\u3081\u3066\u3044\u304d\u307e\u3059\u3002
\nbq\u30b3\u30de\u30f3\u30c9\u306b\u3064\u3044\u3066\u306f \u3053\u3061\u3089<\/a> \u306b\u8a18\u8f09\u3057\u3066\u307e\u3059\u3002<\/p>\n

\u30b3\u30b9\u30c8\u306b\u3064\u3044\u3066<\/h2>\n

\u3053\u3061\u3089<\/a>\u3092\u53c2\u7167\u3059\u308b\u3068\u308f\u304b\u308a\u307e\u3059\u304c\u3001\u30b9\u30c8\u30ec\u30fc\u30b8\u30b3\u30b9\u30c8\u3068\u30af\u30a8\u30ea\u30b3\u30b9\u30c8\u304c\u3042\u308a\u307e\u3059\u3002
\n\u30b9\u30c8\u30ec\u30fc\u30b8\u30b3\u30b9\u30c8\u306f\u3060\u3044\u305f\u3044\u60f3\u50cf\u3064\u304f\u3068\u601d\u3046\u306e\u3067\u3001\u3053\u3053\u3067\u306f\u30af\u30a8\u30ea\u30b3\u30b9\u30c8\u306b\u3064\u3044\u3066\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n

\u8a8d\u8b58\u3057\u3066\u304a\u304d\u305f\u3044\u306e\u306f\u4ee5\u4e0b\u306e\uff13\u3064\u3060\u3068\u79c1\u306f\u601d\u3063\u3066\u307e\u3059\u3002<\/p>\n

    \n
  1. \u30b3\u30b9\u30c8\u306f\u3001\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30c7\u30fc\u30bf\u91cf\uff08\u30d0\u30a4\u30c8\u6570\uff09\u3067\u6c7a\u307e\u308b<\/li>\n
  2. \u30ab\u30e9\u30e0\u578bDB\u306a\u306e\u3067\u3001\u5fc5\u8981\u306a\u30ab\u30e9\u30e0\u306e\u30c7\u30fc\u30bf\u3060\u3051\u3092\u53d6\u5f97\u3059\u308b<\/li>\n
  3. \u30aa\u30d7\u30c6\u30a3\u30de\u30a4\u30b6\u304c\u512a\u79c0\u306a\u306e\u3067\u3001\u6700\u7d42\u7684\u306b\u5229\u7528\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u30fb\u30ab\u30e9\u30e0\u4ee5\u5916\u306f\u51e6\u7406\u5bfe\u8c61\u306b\u306a\u3089\u306a\u3044<\/li>\n<\/ol>\n

    \u3053\u306e\u30eb\u30fc\u30eb\u3092\u5143\u306b\u8003\u3048\u308b\u3068\u3001\u3060\u3044\u305f\u3044\u30b3\u30b9\u30c8\u304c\u3069\u3046\u306a\u308b\u304b\u5206\u304b\u308a\u307e\u3059\u3002
    \n\u5b9f\u969b\u306bbq query --dry_run<\/code>\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30c7\u30fc\u30bf\u91cf\u3092\u53b3\u5bc6\u306b\u78ba\u8a8d\u3057\u3064\u3064\u4ee5\u4e0b\u306e\u8868\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n\n\n\n\n\n\n\n
    \u9805\u76ee<\/th>\n\u30b3\u30b9\u30c8\u3078\u306e\u5f71\u97ff<\/th>\n\u8aac\u660e<\/th>\n<\/tr>\n<\/thead>\n
    *<\/code><\/td>\n\u5bfe\u8c61\u30c6\u30fc\u30d6\u30eb\u306e\u5168\u30ab\u30e9\u30e0\u5206\u306e\u30b3\u30b9\u30c8\u304c\u304b\u304b\u308b<\/td>\n*<\/code>\u3092\u4f7f\u3046\u3068\u305d\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u5168\u30ab\u30e9\u30e0\u3092\u5bfe\u8c61\u306b\u3057\u3066\u3057\u307e\u3046\u3002\u30ab\u30e9\u30e0\u578bDB\u306a\u306e\u3067\u4f7f\u3046\u30ab\u30e9\u30e0\u3060\u3051\u3092\u6307\u5b9a\u3059\u308b\u3068\u305d\u306e\u30ab\u30e9\u30e0\u3060\u3051\u30c7\u30fc\u30bf\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306e\u3067\u30b3\u30b9\u30c8\u306f\u6e1b\u308b<\/td>\n<\/tr>\n
    WHERE\u53e5\u3084LIMIT\u3067\u30c7\u30fc\u30bf\u3092\u7d5e\u308b<\/td>\n\u30b3\u30b9\u30c8\u306f\u5909\u308f\u3089\u306a\u3044\uff08\u5168\u4ef6\u53d6\u5f97\u3068\u4e00\u7dd2\uff09<\/td>\nFROM\u53e5\u3067\u5bfe\u8c61\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u6307\u5b9a\u3057\u3001SELECT\u53e5\u3084WHERE\u53e5\u306a\u3069\u3067\u5229\u7528\u3059\u308b\u30ab\u30e9\u30e0\u304c\u6c7a\u307e\u3063\u305f\u6642\u70b9\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30c7\u30fc\u30bf\u306f\u6c7a\u307e\u308b\u306e\u3067\u3001\u305d\u306e\u3042\u3068\u30ec\u30b3\u30fc\u30c9\u3092\u7d5e\u3063\u3066\u3082\u30b3\u30b9\u30c8\u306b\u306f\u5f71\u97ff\u306f\u306a\u3044<\/td>\n<\/tr>\n
    JOIN<\/td>\nJOIN\u3067\u4f7f\u7528\u3059\u308b\u30ab\u30e9\u30e0\u5206\u30b3\u30b9\u30c8\u304c\u5897\u3048\u308b<\/td>\n\u7d50\u5408\u6761\u4ef6\u306eON\u53e5\u3084\u305d\u306e\u3042\u3068SELECT\u53e5\u3084WHERE\u53e5\u3067\u4f7f\u7528\u3057\u305f\u30ab\u30e9\u30e0\u306e\u30c7\u30fc\u30bf\u91cf\u5206\u3060\u3051\u5358\u7d14\u306b\u52a0\u7b97\u3055\u308c\u308b<\/td>\n<\/tr>\n
    UNION\u3084\u30b5\u30d6\u30af\u30a8\u30ea\u7b49\u3067\u540c\u3058\u30c6\u30fc\u30d6\u30eb\u306b\u4e8c\u56de\u30a2\u30af\u30bb\u30b9<\/td>\n\u30b3\u30b9\u30c8\u306f\u5909\u308f\u3089\u306a\u3044<\/td>\n\u30af\u30a8\u30ea\u5185\u3067\u30a2\u30af\u30bb\u30b9\u3057\u305f\u30c7\u30fc\u30bf\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u306b\u4fdd\u7ba1\u3055\u308c\u308b\u3088\u3046\u3067\u3001\u540c\u4e00\u30af\u30a8\u30ea\u5185\u3067\u4f55\u56de\u540c\u3058\u30c6\u30fc\u30d6\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3082\u30b3\u30b9\u30c8\u306b\u306f\u5f71\u97ff\u306f\u306a\u3044<\/td>\n<\/tr>\n
    \u30b5\u30d6\u30af\u30a8\u30ea\u3067*<\/code>\u3067\u53d6\u5f97\u3057\u305f\u7d50\u679c\u304b\u3089\u6700\u7d42\u7684\u306b\u4e00\u90e8\u306e\u30ab\u30e9\u30e0\u3060\u3051select<\/td>\n\u6700\u7d42\u7684\u306b\u5229\u7528\u3059\u308b\u30ab\u30e9\u30e0\u5206\u3060\u3051\u30b3\u30b9\u30c8\u304c\u304b\u304b\u308b<\/td>\n\u4f8b\u3048\u3070WITH fuga AS (SELECT * FROM hoge) SELECT id FROM fuga<\/code>\u306e\u3088\u3046\u306a\u30af\u30a8\u30ea\u3060\u3068hoge.*<\/code>\u5206\u3060\u3051\u30b3\u30b9\u30c8\u304c\u304b\u304b\u308a\u305d\u3046\u3060\u304c\u5b9f\u969b\u306b\u306fhoge.id<\/code>\u5206\u3060\u3051\u3057\u304b\u30b3\u30b9\u30c8\u306f\u304b\u304b\u3089\u306a\u3044\u3002\u30aa\u30d7\u30c6\u30a3\u30de\u30a4\u30b6\u304c\u512a\u79c0<\/td>\n<\/tr>\n
    \u96c6\u8a08\u51e6\u7406\u3084\u8a08\u7b97\u51e6\u7406<\/td>\n\u30b3\u30b9\u30c8\u306f\u5909\u308f\u3089\u306a\u3044<\/td>\n\u3069\u308c\u3060\u3051\u3084\u3063\u3066\u3082\u30b3\u30b9\u30c8\u306b\u306f\u5f71\u97ff\u3057\u306a\u3044<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

    \u5927\u91cf\u30c7\u30fc\u30bf\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u96c6\u7d04\uff08GROUP BY\uff09\u30af\u30a8\u30ea\u306e\u9ad8\u901f\u5316<\/h2>\n

    1\u5104\u4ef6\u4ee5\u4e0a\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u4fdd\u6301\u3059\u308b3\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u3092JOIN\u3057\u3066GROUP BY\u3059\u308b\u4ee5\u4e0b\u306e\u3088\u3046\u306aSQL\u3092\u983b\u7e41\u306b\u5b9f\u884c\u3059\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304d\u307e\u3057\u305f\u3002\uff08\u5b9f\u969b\u306b\u306f\u3082\u3063\u3068\u8907\u96d1\u3067\u3059\u304c...\uff09<\/p>\n

    SELECT\n  m.match_id\n  , SUM(ug1.group_rank * u1.user_score) AS first_user_group_score\n  , SUM(ug2.group_rank * u2.user_score) AS second_user_group_score\nFROM\n  mydata.match m\n  JOIN mydata.user_group ug1 ON (ug1.user_group_id = m.first_user_group_id)\n  JOIN mydata.user_group ug2 ON (ug2.user_group_id = m.second_user_group_id)\n  JOIN mydata.user u1 ON (u1.user_group_id = ug1.user_group_id)\n  JOIN mydata.user u2 ON (u2.user_group_id = ug2.user_group_id)\nGROUP BY\n  m.match_id\n;<\/code><\/pre>\n

    \u3053\u306eSQL1\u6642\u9593\u7d4c\u3063\u3066\u3082\u5168\u304f\u5fdc\u7b54\u304c\u8fd4\u3063\u3066\u6765\u305a\u3001MATCH<\/code>\u306e\u3068\u3053\u308d\u3092(SELECT * FROM mydata.match LIMIT 100000)<\/code>\u306e\u3088\u3046\u306a\u30b5\u30d6\u30af\u30a8\u30ea\u306b\u7f6e\u304d\u63db\u3048\u3066\u6700\u521d\u306e\u30c6\u30fc\u30d6\u30eb\u3092100\u4e07\u4ef6\u306b\u7d5e\u3063\u3066\u5b9f\u884c\u3057\u305f\u3068\u3053\u308d10\u5206\u304f\u3089\u3044\u3067\u8fd4\u3063\u3066\u304d\u307e\u3057\u305f\u304c\u3001\u5b9f\u904b\u7528\u306b\u306f\u3068\u3066\u3082\u8010\u3048\u3089\u308c\u306a\u3044\u306e\u3067\u9ad8\u901f\u5316\u3092\u691c\u8a0e\u3057\u307e\u3057\u305f\u3002<\/p>\n

    \u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0<\/h3>\n

    \u3053\u3061\u3089<\/a> \u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u8a18\u8ff0\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n

    \n

    \u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306f\u4e26\u3073\u9806\u3092\u793a\u3059\u3082\u306e\u3067\u3042\u308b\u305f\u3081\u3001\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u5217\u3068\u540c\u3058\u5024\u3092\u6301\u3064\u884c\u306f\u3001\u305d\u306e\u8fd1\u304f\u307e\u305f\u306f\u540c\u3058\u30d6\u30ed\u30c3\u30af\u306b\u683c\u7d0d\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u5217\u3067\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u305f\u96c6\u7d04\u30af\u30a8\u30ea\u306e\u6700\u9069\u5316\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002\u96c6\u7d04\u3092\u8a08\u7b97\u3059\u308b\u305f\u3081\u306b\u3001BigQuery \u3067\u306f\u307e\u305a\u5404\u30d6\u30ed\u30c3\u30af\u304b\u3089\u90e8\u5206\u7684\u306a\u96c6\u7d04\u3092\u8a08\u7b97\u3057\u307e\u3059\u3002\u6b21\u306b\u3001\u3053\u308c\u3089\u306e\u90e8\u5206\u7684\u306a\u96c6\u7d04\u3092\u30b7\u30e3\u30c3\u30d5\u30eb\u304a\u3088\u3073\u30de\u30fc\u30b8\u3057\u3066\u3001\u6700\u7d42\u7684\u306a\u96c6\u7d04\u3092\u8a08\u7b97\u3057\u307e\u3059\u3002\u901a\u5e38\u306f\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u5217\u3068\u540c\u3058\u5024\u3092\u6301\u3064\u884c\u304c\u4e00\u7dd2\u306b\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u4f5c\u6210\u3055\u308c\u305f\u90e8\u5206\u7684\u306a\u96c6\u7d04\u306e\u30b5\u30a4\u30ba\u306f\u304b\u306a\u308a\u5c0f\u3055\u304f\u306a\u308a\u3001\u30b7\u30e3\u30c3\u30d5\u30eb\u3059\u308b\u5fc5\u8981\u306e\u3042\u308b\u4e2d\u9593\u30c7\u30fc\u30bf\u306e\u91cf\u304c\u6e1b\u5c11\u3057\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u96c6\u7d04\u30af\u30a8\u30ea\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002<\/p>\n<\/blockquote>\n

    \u3053\u308c\u3092\u307f\u308b\u3068\u3001group by<\/code>\u306b\u6307\u5b9a\u3057\u3066\u3044\u308b\u9805\u76ee\u3067\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u3092\u884c\u3048\u3070\u3001\u30d6\u30ed\u30c3\u30af\u5185\u306e\u90e8\u5206\u7684\u306a\u96c6\u7d04\u306e\u30b5\u30a4\u30ba\u304c\u5c0f\u3055\u304f\u306a\u308a\u3001\u6700\u7d42\u7684\u306b\u30b7\u30e3\u30c3\u30d5\u30eb&\u30de\u30fc\u30b8\u3059\u308b\u5bfe\u8c61\u306e\u4e2d\u9593\u30c7\u30fc\u30bf\u6570\u304c\u6e1b\u308b\u306e\u3067\u9ad8\u901f\u5316\u3067\u304d\u305d\u3046\u3067\u3059\u3002<\/p>\n

    \u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u306e\u8a2d\u5b9a\u306fcreate table<\/code>\u6587\u306e\u4e2d\u3067\u884c\u3044\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n

    CREATE TABLE mydata.match (match_id, xxx, yyy, created_at)\nPARTITION BY DATE(created_at)\nCLUSTER BY match_id\n;<\/code><\/pre>\n

    \u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u3059\u308b\u305f\u3081\u306b\u306f\u30d1\u30fc\u30c6\u30a3\u30b7\u30e7\u30cb\u30f3\u30b0\u3082\u5408\u308f\u305b\u3066\u884c\u3046\u5fc5\u8981\u304c\u3042\u308b\u305f\u3081\u3001partition by<\/code>\u3082\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n

    match<\/code>\u30c6\u30fc\u30d6\u30eb\u306ematch_id<\/code>\u3001user_group<\/code>\u30c6\u30fc\u30d6\u30eb\u306euser_group_id<\/code>\u3001user<\/code>\u30c6\u30fc\u30d6\u30eb\u306euser_id<\/code>\u3067\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u3057\u3066\u3001\u30af\u30a8\u30ea\u3092\u518d\u5b9f\u884c\u3057\u305f\u3068\u3053\u308d\u300c100\u4e07\u4ef6\u306710\u5206\u300d\u3060\u3063\u305f\u306e\u304c\u300c100\u4e07\u4ef6\u306713\u5206\u300d\u306b\u3001\u3001\u3001\u3080\u3080\u3001\u3001\u306a\u305c\u3060\u3001\u77ed\u7e2e\u3055\u308c\u3066\u306a\u3044\u305e\u3002\u3002\u3002
    \nJOIN\u3059\u308b\u3068\u30c0\u30e1\u3068\u304b\u306a\u306e\u304b\u306a\u3002\u3002\u6642\u9593\u304c\u3042\u308b\u3068\u304d\u306b\u3082\u3046\u5c11\u3057\u30b7\u30f3\u30d7\u30eb\u306a\u4f8b\u3067\u8a66\u3057\u3066\u307f\u307e\u3059www<\/p>\n

    \u4e2d\u9593\u30c6\u30fc\u30d6\u30eb<\/h2>\n

    \u4e0a\u306e\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u3067\u306f\u601d\u3046\u3088\u3046\u306a\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u305b\u3093\u3067\u3057\u305f\u304c\u3001\u4e2d\u9593\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u3063\u3066\u51e6\u7406\u3059\u308b\u3053\u3068\u3067\u5287\u7684\u306e\u51e6\u7406\u304c\u65e9\u304f\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002
    \n\u4e0a\u8a18\u306e\u4f8b\u3060\u3068\u3001user_group.rank<\/code>\u3068user.score<\/code>\u3092\u3042\u3089\u304b\u3058\u3081\u639b\u3051\u5408\u308f\u305f\u4e2d\u9593\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u308b\u3068\u52b9\u679c\u7684\u3067\u3057\u305f\u3002<\/p>\n

    CREATE OR REPLACE TABLE mydata.tmp_user_group_score\nOPTIONS (\n    EXPIRATION_TIMESTAMP=TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 1 DAY) -- \u6709\u52b9\u671f\u95931\u65e5\n)\nAS\n  ug.user_group_id\n  , SUM(ug.group_rank * u.user_score) AS user_group_score\nFROM\n  mydata.user_group ug\n  JOIN mydata.user u ON (u.user_group_id = ug.user_group_id)\nGROUP BY\n  ug.user_group_id\n;<\/code><\/pre>\n

    \u305d\u306e\u4e0a\u3067\u3001\u4e2d\u9593\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3046\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u306b\u3088\u308a\u300c100\u4e07\u4ef6\u306710\u5206\u300d\u3060\u3063\u305f\u306e\u304c\u3001\u300c\u5168\u4ef6(\u6570\u5104\u4ef6)\u30675\u5206\u300d\u306b\u5927\u5e45\u6539\u5584\u3057\u307e\u3057\u305f\u3002<\/p>\n

    SELECT\n  m.match_id\n  , ugs1.user_group_score as first_user_group_score\n  , ugs2.user_group_score as second_user_group_score\nFROM\n  mydata.match m\n  JOIN mydata.tmp_user_group_score ugs1 ON (ugs1.user_group_id = m.first_user_group_id)\n  JOIN mydata.tmp_user_group_score ugs2 ON (ugs2.user_group_id = m.second_user_group_id)\n;<\/code><\/pre>\n

    \u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u306e\u5909\u66f4<\/h2>\n

    \u5217\u306e\u8ffd\u52a0<\/h3>\n

    ALTER TABLE hoge ADD COLUMN fuga<\/code>\u306e\u3088\u3046\u306aSQL\u3067\u306f\u5b9f\u884c\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n

    bq query \u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3046\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b--destination_table<\/code>\u3068--replace<\/code>\u3067\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n

    bq query --destination_table mydata.hoge --replace \\\n'SELECT h.*, CAST(null AS INT64) AS added_column FROM mydata.hoge h'<\/code><\/pre>\n

    \u5358\u7d14\u306b\u30af\u30a8\u30ea\u3060\u3051\u3067\u5b8c\u7d50\u3055\u305b\u305f\u3044\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n

    CREATE OR REPLACE TABLE mydata.hoge\nAS\nSELECT\n    h.*\n    , CAST(null AS INT64) AS added_column\nFROM\n    mydata.hoge h\n;<\/code><\/pre>\n

    \u305d\u306e\u4ed6\u3001JSON\u3067\u30b9\u30ad\u30fc\u30de\u60c5\u5831\u3092\u5b9a\u7fa9\u3057\u3066\u3001\u5217\u3092\u8ffd\u52a0\/\u5909\u66f4\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u3053\u3061\u3089<\/a>\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002<\/p>\n

    # json\u306b\u30b9\u30ad\u30fc\u30de\u60c5\u5831\u3092\u51fa\u529b\u3059\u308b\nbq --format=prettyjson show mydata.hoge > hoge.json\n\n# json\u306e\u5185\u5bb9\u3092\u3001fields\u306e\u4e2d\u8eab\u3060\u3051\u306b\u3057\u3066\u3001\u8ffd\u52a0\u3057\u305f\u3044\u30ab\u30e9\u30e0\u306eFIELD\u60c5\u5831\u3092\u8ffd\u52a0\u3059\u308b\nvi hoge.json \ncat hoge.json\n> [\n>     {\n>         "name": "id",\n>         "type": "INT64"\n>     },\n>     {\n>         "name": "fuga",\n>         "type": "STRING"\n>     },\n>     (\u7701\u7565)\n>     {\n>         "name": "added_column",\n>         "type": "INT64"\n>     },\n> ]\n\n# json\u3092\u5143\u306b\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u3092\u66f4\u65b0\u3059\u308b\nbq update mydata.hoge hoge.json<\/code><\/pre>\n

    \u5217\u3092\u524a\u9664\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001BigQuery error in update operation: Provided Schema does not match Table myproject:mydata.hoge. Field fuga is missing in new schema<\/code> \u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u524a\u9664\u3067\u304d\u307e\u305b\u3093\u3002\u5c11\u3057\u6b8b\u5ff5\u3067\u3059\u304c\u3001\u9593\u9055\u3063\u3066\u524a\u9664\u3057\u3066\u3057\u307e\u3046\u30ea\u30b9\u30af\u3092\u8003\u3048\u308b\u3068\u30e1\u30ea\u30c3\u30c8\u306e\u65b9\u304c\u5c11\u3057\u5927\u304d\u3044\u6c17\u304c\u3057\u307e\u3059\u3002<\/p>\n

    \u5217\u306e\u524a\u9664<\/h3>\n

    aLTER TABLE hoge DROP COLUMN fuga<\/code>\u306e\u3088\u3046\u306aSQL\u3067\u306f\u5b9f\u884c\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n

    bq query \u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3046\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b--destination_table<\/code>\u3068--replace<\/code>\u3067\u5b9f\u884c\u3057\u307e\u3059\u3002
    \nEXCEPT(fuga)<\/code>\u3067*<\/code>\u304b\u3089fuga<\/code>\u3092\u9664\u5916\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059<\/p>\n

    bq query --destination_table mydata.hoge --replace \\\n'SELECT * EXCEPT(fuga) FROM mydata.hoge'<\/code><\/pre>\n

    \u5358\u7d14\u306b\u30af\u30a8\u30ea\u3060\u3051\u3067\u5b8c\u7d50\u3055\u305b\u305f\u3044\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n

    CREATE OR REPLACE TABLE mydata.hoge\nAS\nSELECT\n  * EXCEPT(fuga)\nFROM\n  mydata.hoge\n;<\/code><\/pre>\n

    \u305d\u306e\u4ed6\u3001export\u3057\u3066\u304b\u3089\u65b0\u3057\u3044\u30c6\u30fc\u30d6\u30eb\u3068\u3057\u3066import\u3059\u308b\u65b9\u6cd5\u3082\u3042\u3063\u3066\u3001\u4e00\u756a\u4f4e\u30b3\u30b9\u30c8\u3067\u3059\u304c\u3001\u3061\u3087\u3063\u3068\u624b\u9593\u304c\u304b\u304b\u308b\u306e\u3067\u3088\u307b\u3069\u30b3\u30b9\u30c8\u304c\u304d\u306b\u306a\u308b\u5834\u5408\u3057\u304b\u4f7f\u308f\u306a\u3044\u6c17\u304c\u3057\u307e\u3059\u3002<\/p>\n

    BigQuery Web UI\uff08\u30b3\u30f3\u30bd\u30fc\u30eb\uff09\u304c\u4fbf\u5229<\/h2>\n

    Web UI<\/a>\u306fRedash\u3068\u304b\u306b\u6bd4\u3079\u308b\u3068\u5c11\u3057\u30b9\u30bf\u30a4\u30ea\u30c3\u30b7\u30e5\u611f\u304c\u306a\u3044\u3067\u3059\u304c\u3001\u6163\u308c\u308b\u3068\u4f7f\u3044\u3084\u3059\u3044\u6c17\u304c\u3057\u3066\u304d\u307e\u3057\u305f\u3002\u5c11\u306a\u304f\u3068\u3082bq query<\/code>\u3067\u5b9f\u884c\u3059\u308b\u3088\u308a\u306f\u5727\u5012\u7684\u306b\u697d\u3067\u3059\u3002\u306a\u304a\u3001\u4f7f\u7528\u3067\u304d\u308b\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u30ad\u30fc\u306f\u3053\u3061\u3089<\/a>\u304b\u3089\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n

    \u30af\u30a8\u30ea\u306e\u30d0\u30a4\u30c8\u6570\u3092\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u3067\u78ba\u8a8d\u3067\u304d\u308b<\/h3>\n

    \u30af\u30a8\u30ea\u30a8\u30c7\u30a3\u30bf\u3067\u5165\u529b\u4e2d\u306e\u30af\u30a8\u30ea\u3092\u5b9f\u884c\u3057\u305f\u5834\u5408\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30d0\u30a4\u30c8\u6570\u304c\u3001 <\/p>\n

    \n

    \u3053\u306e\u30af\u30a8\u30ea\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001337.7 KB \u304c\u51e6\u7406\u3055\u308c\u307e\u3059\u3002<\/p>\n<\/blockquote>\n

    \u306e\u3088\u3046\u306b\u3001\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u3067\u30af\u30a8\u30ea\u30a8\u30c7\u30a3\u30bf\u306e\u53f3\u4e0b\u306b\u8868\u793a\u3055\u308c\u307e\u3059<\/p>\n

    \u30af\u30a8\u30ea\u306e\u9078\u629e\u5b9f\u884c\u304c\u3067\u304d\u308b<\/h3>\n

    \u8907\u6570\u306e\u30af\u30a8\u30ea\u3092\u30af\u30a8\u30ea\u30a8\u30c7\u30a3\u30bf\u306b\u66f8\u3044\u3066\u304a\u304d\u3001\u305d\u306e\u3046\u3061\u4e00\u90e8\u3092\u9078\u629e\u3057\u3066\u5b9f\u884c<\/code>\u30dc\u30bf\u30f3\u306e\u53f3\u5074\u306e\u25bc<\/code>\u30e1\u30cb\u30e5\u30fc\u304b\u3089\u9078\u629e\u9805\u76ee\u3092\u5b9f\u884c<\/code>\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001\u30af\u30a8\u30ea\u306e\u9078\u629e\u5b9f\u884c\u304c\u3067\u304d\u307e\u3059\u3002\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u30ad\u30fccmd + e<\/code>\u304c\u4fbf\u5229\u3067\u3059\u30021TB\u30675\u30c9\u30eb\u306a\u306e\u3067100GB\u3050\u3089\u3044\u304b\u3089\u5c11\u3057\u6c17\u306b\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n

    Tab\u3067\u5358\u8a9e\u3092\u30aa\u30fc\u30c8\u30b3\u30f3\u30d7\u30ea\u30fc\u30c8\u3067\u304d\u308b<\/h3>\n

    \u4e88\u7d04\u8a9e\u3001\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u540d\u3001\u30c6\u30fc\u30d6\u30eb\u540d\u3001\u30ab\u30e9\u30e0\u540d\u306a\u3069\u3092\u3001Tab\u3067\u30aa\u30fc\u30c8\u30b3\u30f3\u30d7\u30ea\u30fc\u30c8\u3067\u304d\u307e\u3059\u3002
    \n\u4f8b\u3048\u3070\u3001hoge\u30c6\u30fc\u30d6\u30eb\u306bhoge h<\/code>\u3067\u30a8\u30a4\u30ea\u30a2\u30b9\u3092\u4ed8\u3051\u305f\u5f8c\u306b\u3001h.<\/code>\u307e\u3067\u5165\u529b\u3057\u3066Tab\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001hoge\u30c6\u30fc\u30d6\u30eb\u306b\u5b58\u5728\u3059\u308b\u9805\u76ee\u304c\u30d7\u30eb\u30c0\u30a6\u30f3\u8868\u793a\u3055\u308c\u307e\u3059\u3002\u304b\u306a\u308a\u4fbf\u5229\u3067\u3059\u3002<\/p>\n

    \u30af\u30a8\u30ea\u7d50\u679c\u3092\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3084CSV\u3001\u30c6\u30fc\u30d6\u30eb\u306b\u4fdd\u5b58\u3067\u304d\u308b<\/h3>\n

    \u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3082\u51fa\u305a\u306b\u4fdd\u5b58\u3067\u304d\u306a\u3044\u6642\u306f\u3001\u7d50\u679c\u306bARRAY\u3084STRUCT\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
    \n\u3053\u308c\u304c\u539f\u56e0\u306e\u5834\u5408\u3001ARRAY_TO_STRING()<\/code>\u3084FORMAT()<\/code>\u306a\u3069\u3067\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308b\u3068\u89e3\u6c7a\u3067\u304d\u307e\u3059\u3001<\/p>\n

    \u30af\u30a8\u30ea\u7d50\u679c\u304c\u30d6\u30e9\u30a6\u30b6\u306b\u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u308b<\/h3>\n

    \u30d6\u30e9\u30a6\u30b6\u306b\u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u30af\u30a8\u30ea\u7d50\u679c\u306e\u30a8\u30ea\u30a2\u3067\u3001\u4e8c\u672c\u6307\u30b9\u30ef\u30a4\u30d7\uff08Mac\uff09\u3067\u524d\u306e\u30af\u30a8\u30ea\u3084\u6b21\u306e\u30af\u30a8\u30ea\u306e\u7d50\u679c\u306bSQL\u3092\u518d\u5b9f\u884c\u3059\u308b\u3053\u3068\u306a\u304f\u79fb\u52d5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

    \u305d\u306e\u4ed6<\/h3>\n