並列ループを使用してデータを集計する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
一般公開 BigQuery データセットに対して個別のクエリを行うことで、ドキュメント内の単語の数または一連のドキュメントを返します。共有変数を使用すると、単語のカウント数を蓄積し、すべての反復処理が完了した後に読み取ることができます。
もっと見る
このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。
コードサンプル
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],[],[],[],null,["# Aggregate data using a parallel loop\n\nSeparate queries to a public BigQuery dataset each return the number of words in a document, or set of documents. A shared variable allows the count of the words to accumulate and be read after all the iterations complete.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Execute workflow steps in parallel](/workflows/docs/execute-parallel-steps)\n\nCode sample\n-----------\n\n### YAML\n\n # Use a parallel loop to make ten queries to a public BigQuery dataset and\n # use a shared variable to accumulate a count of words; after all iterations\n # complete, return the total number of words across all documents\n main:\n params: [input]\n steps:\n - init:\n assign:\n - numWords: 0\n - corpuses:\n - sonnets\n - various\n - 1kinghenryvi\n - 2kinghenryvi\n - 3kinghenryvi\n - comedyoferrors\n - kingrichardiii\n - titusandronicus\n - tamingoftheshrew\n - loveslabourslost\n - runQueries:\n parallel: # 'numWords' is shared so it can be written within the parallel loop\n shared: [numWords]\n for:\n value: corpus\n in: ${corpuses}\n steps:\n - runQuery:\n call: googleapis.bigquery.v2.jobs.query\n args:\n projectId: ${sys.get_env(\"GOOGLE_CLOUD_PROJECT_ID\")}\n body:\n useLegacySql: false\n query: ${\"SELECT COUNT(DISTINCT word) FROM `bigquery-public-data.samples.shakespeare` \" + \" WHERE corpus='\" + corpus + \"' \"}\n result: query\n - add:\n assign:\n - numWords: ${numWords + int(query.rows[0].f[0].v)} # first result is the count\n - done:\n return: ${numWords}\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=workflows)."]]