2017-03-28 127 views
3

私はSnowflakeデータウェアハウスにロードする必要がある大きなJSONファイル、約5百万のレコードと約32GBのファイルサイズを持っています。私はこのファイルを1ファイルにつき約200kレコード(約1.25GB)のまとまりに分割する必要があります。私はNode.JSまたはPythonでAWS Lambda関数にデプロイするためにこれをやりたいのですが、残念ながらどちらもまだコード化されていません。私はC#と多くのSQLエクスペリエンスを持っており、ノードとPythonの両方を学ぶことは私のリストに載っています。大規模なjsonファイルを複数の小さなファイルに分割する

私の最初の質問は「どの言語がこの機能を果たすのでしょうか?Python、Node.JS?」です。

私はこのJSONファイル全体をメモリに読み込むことは望ましくないことを知っています(さらに出力より小さくファイル)。レコード数(200k)に基づいてに新しいファイルを「ストリーム」し、jsonオブジェクトを適切にクローズし、別の200kの新しいファイルに続き、というようにする必要があります。私はNodeがこれを行うことができることを知っていますが、もしPythonもこれを行うことができれば、私はすぐにやるつもりである他のETLのものをすぐに使い始めることが容易になると思います。

私の2番目の質問は、「上記の推奨事項に基づいて、私が開始/開始するために必要なモジュールをお勧めしますか?主にjsonファイル全体をメモリに取り込まないことに関連していますか?トリック、または「あなたはどうしていますか?そして、あなたが本当に寛大であると感じたら、私をこの深いところまで押し込むためのコード例がありますか?ありがとうございました。個人情報が含まれているため、JSONデータのサンプルを含めることはできませんが、私はJSONスキーマを提供できます...

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "items": { 
    "properties": { 
     "activities": { 
     "properties": { 
      "activity_id": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "frontlineorg_id": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "import_id": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "is_source": { 
      "items": { 
       "type": "boolean" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "address": { 
     "properties": { 
      "city": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "congress_dist_name": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "congress_dist_number": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "congress_end_yr": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "congress_number": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "congress_start_yr": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "county": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "formatted": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "latitude": { 
      "items": { 
       "type": "number" 
      }, 
      "type": "array" 
      }, 
      "longitude": { 
      "items": { 
       "type": "number" 
      }, 
      "type": "array" 
      }, 
      "number": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "observes_dst": { 
      "items": { 
       "type": "boolean" 
      }, 
      "type": "array" 
      }, 
      "post_directional": { 
      "items": { 
       "type": "null" 
      }, 
      "type": "array" 
      }, 
      "pre_directional": { 
      "items": { 
       "type": "null" 
      }, 
      "type": "array" 
      }, 
      "school_district": { 
      "items": { 
       "properties": { 
       "school_dist_name": { 
        "items": { 
        "type": "string" 
        }, 
        "type": "array" 
       }, 
       "school_dist_type": { 
        "items": { 
        "type": "string" 
        }, 
        "type": "array" 
       }, 
       "school_grade_high": { 
        "items": { 
        "type": "string" 
        }, 
        "type": "array" 
       }, 
       "school_grade_low": { 
        "items": { 
        "type": "string" 
        }, 
        "type": "array" 
       }, 
       "school_lea_code": { 
        "items": { 
        "type": "integer" 
        }, 
        "type": "array" 
       } 
       }, 
       "type": "object" 
      }, 
      "type": "array" 
      }, 
      "secondary_number": { 
      "items": { 
       "type": "null" 
      }, 
      "type": "array" 
      }, 
      "secondary_unit": { 
      "items": { 
       "type": "null" 
      }, 
      "type": "array" 
      }, 
      "state": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "state_house_dist_name": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "state_house_dist_number": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "state_senate_dist_name": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "state_senate_dist_number": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "street": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suffix": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "timezone": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "utc_offset": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "zip": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "age": { 
     "type": "integer" 
     }, 
     "anniversary": { 
     "properties": { 
      "date": { 
      "type": "null" 
      }, 
      "insert_datetime_utc": { 
      "type": "null" 
      }, 
      "suppressed_datetime_utc": { 
      "type": "null" 
      } 
     }, 
     "type": "object" 
     }, 
     "baptism": { 
     "properties": { 
      "church_id": { 
      "type": "null" 
      }, 
      "date": { 
      "type": "null" 
      }, 
      "insert_datetime_utc": { 
      "type": "null" 
      }, 
      "suppressed_datetime_utc": { 
      "type": "null" 
      } 
     }, 
     "type": "object" 
     }, 
     "birth_dd": { 
     "type": "integer" 
     }, 
     "birth_mm": { 
     "type": "integer" 
     }, 
     "birth_yyyy": { 
     "type": "integer" 
     }, 
     "church_attendance": { 
     "properties": { 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "likelihood": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "cohabiting": { 
     "properties": { 
      "confidence": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "likelihood": { 
      "items": { 
       "type": "null" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "dating": { 
     "properties": { 
      "bool": { 
      "type": "null" 
      }, 
      "insert_datetime_utc": { 
      "type": "null" 
      }, 
      "suppressed_datetime_utc": { 
      "type": "null" 
      } 
     }, 
     "type": "object" 
     }, 
     "divorced": { 
     "properties": { 
      "bool": { 
      "items": { 
       "type": "null" 
      }, 
      "type": "array" 
      }, 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "likelihood_considering": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "education": { 
     "properties": { 
      "est_level": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "email": { 
     "properties": { 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "is_work_school": { 
      "items": { 
       "type": "boolean" 
      }, 
      "type": "array" 
      }, 
      "string": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "engaged": { 
     "properties": { 
      "insert_datetime_utc": { 
      "type": "null" 
      }, 
      "likelihood": { 
      "type": "null" 
      }, 
      "suppressed_datetime_utc": { 
      "type": "null" 
      } 
     }, 
     "type": "object" 
     }, 
     "est_income": { 
     "properties": { 
      "est_level": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "ethnicity": { 
     "type": "string" 
     }, 
     "first_name": { 
     "type": "string" 
     }, 
     "formatted_birthdate": { 
     "type": "string" 
     }, 
     "gender": { 
     "type": "string" 
     }, 
     "head_of_household": { 
     "properties": { 
      "bool": { 
      "type": "null" 
      }, 
      "insert_datetime_utc": { 
      "type": "null" 
      }, 
      "suppressed_datetime_utc": { 
      "type": "null" 
      } 
     }, 
     "type": "object" 
     }, 
     "home_church": { 
     "properties": { 
      "church_id": { 
      "type": "null" 
      }, 
      "group_participant": { 
      "type": "null" 
      }, 
      "insert_datetime_utc": { 
      "type": "null" 
      }, 
      "is_coaching": { 
      "type": "null" 
      }, 
      "is_giving": { 
      "type": "null" 
      }, 
      "is_serving": { 
      "type": "null" 
      }, 
      "membership_date": { 
      "type": "null" 
      }, 
      "regular_attendee": { 
      "type": "null" 
      }, 
      "suppressed_datetime_utc": { 
      "type": "null" 
      } 
     }, 
     "type": "object" 
     }, 
     "hub_poid": { 
     "type": "integer" 
     }, 
     "insert_datetime_utc": { 
     "type": "string" 
     }, 
     "ip_address": { 
     "properties": { 
      "insert_datetime_utc": { 
      "type": "null" 
      }, 
      "string": { 
      "type": "null" 
      }, 
      "suppressed_datetime_utc": { 
      "type": "null" 
      } 
     }, 
     "type": "object" 
     }, 
     "last_name": { 
     "type": "string" 
     }, 
     "marriage_segment": { 
     "properties": { 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "string": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "married": { 
     "properties": { 
      "bool": { 
      "items": { 
       "type": "boolean" 
      }, 
      "type": "array" 
      }, 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "middle_name": { 
     "type": "string" 
     }, 
     "miscellaneous": { 
     "properties": { 
      "attribute": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "value": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "name_suffix": { 
     "type": "null" 
     }, 
     "name_title": { 
     "type": "null" 
     }, 
     "newlywed": { 
     "properties": { 
      "bool": { 
      "type": "null" 
      }, 
      "insert_datetime_utc": { 
      "type": "null" 
      }, 
      "suppressed_datetime_utc": { 
      "type": "null" 
      } 
     }, 
     "type": "object" 
     }, 
     "parent": { 
     "properties": { 
      "bool": { 
      "items": { 
       "type": "boolean" 
      }, 
      "type": "array" 
      }, 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "likelihood_expecting": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "person_id": { 
     "type": "integer" 
     }, 
     "phone": { 
     "properties": { 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "number": { 
      "items": { 
       "type": "integer" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "type": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "property_rights": { 
     "properties": { 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "string": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "psychographic_cluster": { 
     "properties": { 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "string": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "religion": { 
     "properties": { 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "string": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "religious_segment": { 
     "properties": { 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "string": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     }, 
     "separated": { 
     "properties": { 
      "bool": { 
      "type": "null" 
      }, 
      "insert_datetime_utc": { 
      "type": "null" 
      }, 
      "suppressed_datetime_utc": { 
      "type": "null" 
      } 
     }, 
     "type": "object" 
     }, 
     "significant_other": { 
     "properties": { 
      "first_name": { 
      "type": "null" 
      }, 
      "insert_datetime_utc": { 
      "type": "null" 
      }, 
      "last_name": { 
      "type": "null" 
      }, 
      "middle_name": { 
      "type": "null" 
      }, 
      "name_suffix": { 
      "type": "null" 
      }, 
      "name_title": { 
      "type": "null" 
      }, 
      "suppressed_datetime_utc": { 
      "type": "null" 
      } 
     }, 
     "type": "object" 
     }, 
     "suppressed_datetime_utc": { 
     "type": "string" 
     }, 
     "target_group": { 
     "properties": { 
      "insert_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "string": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      }, 
      "suppressed_datetime_utc": { 
      "items": { 
       "type": "string" 
      }, 
      "type": "array" 
      } 
     }, 
     "type": "object" 
     } 
    }, 
    "type": "object" 
    }, 
    "type": "array" 
} 
+0

をあなたのJSON形式の特別な何かがありますか?たとえば、新しい行のすべてのレコードがあるか、すべてのレコードが '{'のみを含む行で始まり、 '}'で終わり、インデントが内部にありますか?もしそうなら、些細なファイルを解析するスクリプトが役に立ちます:) –

+0

有効なグループごとにJSONを分割する私のコードは 'csplit -n 6 -f _ '/ \ {(?:[^ {} |(?R) ])* \}/''-f'は出力ファイルにプリフィックスを追加するだけです –

答えて

1

Ans PythonやNodeの方がタスクのほうが良いかどうかは疑問であり、私たちはStack Overflowについて意見を述べることはできません。 PythonやNodeを使って、より多くの経験を持ち、何を使いたいのかを自分で決める必要があります。

ノードを使用する場合は、JSON解析をストリーミングするために役立つモジュールがいくつかあります。例えば。これらのモジュール:あなたは、Pythonで行く場合

、ストリーミングJSONパーサーはここにもあります

関連する問題