Cloud Storage to Cloud Storage テンプレート

Managed Service for Apache Spark Cloud Storage to Cloud Storage テンプレートを使用して、Cloud Storage から Cloud Storage にデータを抽出します。

テンプレートの使用

gcloud CLI または Managed Service for Apache Spark API を使用してテンプレートを実行します。

gcloud

後述のコマンドデータを使用する前に、 次のように置き換えます。

  • PROJECT_ID: 必須。IAM 設定に載っている プロジェクト ID Google Cloud 。
  • REGION: 必須。Compute Engine のリージョン
  • SUBNET: 省略可。サブネットが指定されていない場合、default ネットワークの指定された REGION のサブネットが選択されます。

    : projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME

  • TEMPLATE_VERSION: 必須。最新のテンプレート バージョンまたは特定バージョンの日付(2023-03-17_v0.1.0-beta など)には latest を指定します(gs://dataproc-templates-binaries にアクセスするか、gcloud storage ls gs://dataproc-templates-binaries を実行して、使用可能なテンプレート バージョンを一覧表示します)。
  • CLOUD_STORAGE_INPUT_PATH: 必須。入力データの読み取り元の Cloud Storage パス。

    : gs://example-bucket/example-folder/

  • FORMAT: 必須。入力データ形式オプション: avroparquetorc注: avro の場合、jars gcloud CLI フラグまたは API フィールドに「file:///usr/lib/spark/connector/spark-avro.jar」を追加する必要があります。

    例(file:// 接頭辞は Managed Service for Apache Spark jar ファイルを参照します):

    --jars=file:///usr/lib/spark/connector/spark-avro.jar, [ ... other jars]
  • CLOUD_STORAGE_OUTPUT_PATH: 必須。出力が保存される Cloud Storage パス。

    : gs://example-bucket/example-folder/

  • OUTPUT_FILE_FORMAT: 必須。出力データ形式。オプション: avrocsvparquetjsonorc注: avro の場合、jars gcloud CLI フラグまたは API フィールドに「file:///usr/lib/spark/connector/spark-avro.jar」を追加する必要があります。

    例(file:// 接頭辞は Managed Service for Apache Spark jar ファイルを参照します):

    --jars=file:///usr/lib/spark/connector/spark-avro.jar, [ ... other jars]
  • MODE: 必須。Cloud Storage 出力の書き込みモード。 オプション: AppendOverwriteIgnoreErrorIfExists
  • TEMP_TABLETEMP_QUERY: 省略可。これら 2 つのオプションのパラメータを使用して、Cloud Storage にデータを読み込んでいる間に Spark SQL 変換を適用できます。 TEMP_TABLE は一時的なビュー名で、TEMP_QUERY はクエリ ステートメントです。TEMP_TABLE と TEMP_QUERY のテーブル名は一致する必要があります。
  • SERVICE_ACCOUNT: 省略可。指定されていない場合は、デフォルトの Compute Engine サービス アカウントが使用されます。
  • PROPERTYPROPERTY_VALUE: 省略可。Spark プロパティ=value ペアのカンマ区切りのリスト。
  • LABELLABEL_VALUE: 省略可。label=value ペアのカンマ区切りのリスト。
  • LOG_LEVEL: 省略可。ロギングのレベル。ALLDEBUGERRORFATALINFOOFFTRACEWARN のいずれかです。デフォルト: INFO
  • KMS_KEY: 省略可。暗号化に使用する Cloud Key Management Service 鍵。鍵が指定されていない場合、データは保存時に暗号化されます。 Google-owned and Google-managed encryption key

    例: projects/PROJECT_ID/regions/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME

次のコマンドを実行します。

Linux、macOS、Cloud Shell

gcloud dataproc batches submit spark \
    --class=com.google.cloud.dataproc.templates.main.DataProcTemplate \
    --version="1.2" \
    --project="PROJECT_ID" \
    --region="REGION" \
    --jars="gs://dataproc-templates-binaries/TEMPLATE_VERSION/java/dataproc-templates.jar,file:///usr/lib/spark/connector/spark-avro.jar" \
    --subnet="SUBNET" \
    --kms-key="KMS_KEY" \
    --service-account="SERVICE_ACCOUNT" \
    --properties="PROPERTY=PROPERTY_VALUE" \
    --labels="LABEL=LABEL_VALUE" \
    -- --template=GCSTOGCS \
    --templateProperty log.level="LOG_LEVEL" \
    --templateProperty project.id="PROJECT_ID" \
    --templateProperty gcs.gcs.input.location="CLOUD_STORAGE_INPUT_PATH" \
    --templateProperty gcs.gcs.input.format="INPUT_FILE_FORMAT" \
    --templateProperty gcs.gcs.output.location="CLOUD_STORAGE_OUTPUT_PATH" \
    --templateProperty gcs.gcs.output.format="OUTPUT_FILE_FORMAT" \
    --templateProperty gcs.gcs.write.mode="MODE" \
    --templateProperty gcs.gcs.temp.table="TEMP_TABLE" \
    --templateProperty gcs.gcs.temp.query="TEMP_QUERY"

Windows(PowerShell)

gcloud dataproc batches submit spark `
    --class=com.google.cloud.dataproc.templates.main.DataProcTemplate `
    --version="1.2" `
    --project="PROJECT_ID" `
    --region="REGION" `
    --jars="gs://dataproc-templates-binaries/TEMPLATE_VERSION/java/dataproc-templates.jar,file:///usr/lib/spark/connector/spark-avro.jar" `
    --subnet="SUBNET" `
    --kms-key="KMS_KEY" `
    --service-account="SERVICE_ACCOUNT" `
    --properties="PROPERTY=PROPERTY_VALUE" `
    --labels="LABEL=LABEL_VALUE" `
    -- --template=GCSTOGCS `
    --templateProperty log.level="LOG_LEVEL" `
    --templateProperty project.id="PROJECT_ID" `
    --templateProperty gcs.gcs.input.location="CLOUD_STORAGE_INPUT_PATH" `
    --templateProperty gcs.gcs.input.format="INPUT_FILE_FORMAT" `
    --templateProperty gcs.gcs.output.location="CLOUD_STORAGE_OUTPUT_PATH" `
    --templateProperty gcs.gcs.output.format="OUTPUT_FILE_FORMAT" `
    --templateProperty gcs.gcs.write.mode="MODE" `
    --templateProperty gcs.gcs.temp.table="TEMP_TABLE" `
    --templateProperty gcs.gcs.temp.query="TEMP_QUERY"

Windows(cmd.exe)

gcloud dataproc batches submit spark ^
    --class=com.google.cloud.dataproc.templates.main.DataProcTemplate ^
    --version="1.2" ^
    --project="PROJECT_ID" ^
    --region="REGION" ^
    --jars="gs://dataproc-templates-binaries/TEMPLATE_VERSION/java/dataproc-templates.jar,file:///usr/lib/spark/connector/spark-avro.jar" ^
    --subnet="SUBNET" ^
    --kms-key="KMS_KEY" ^
    --service-account="SERVICE_ACCOUNT" ^
    --properties="PROPERTY=PROPERTY_VALUE" ^
    --labels="LABEL=LABEL_VALUE" ^
    -- --template=GCSTOGCS ^
    --templateProperty log.level="LOG_LEVEL" ^
    --templateProperty project.id="PROJECT_ID" ^
    --templateProperty gcs.gcs.input.location="CLOUD_STORAGE_INPUT_PATH" ^
    --templateProperty gcs.gcs.input.format="INPUT_FILE_FORMAT" ^
    --templateProperty gcs.gcs.output.location="CLOUD_STORAGE_OUTPUT_PATH" ^
    --templateProperty gcs.gcs.output.format="OUTPUT_FILE_FORMAT" ^
    --templateProperty gcs.gcs.write.mode="MODE" ^
    --templateProperty gcs.gcs.temp.table="TEMP_TABLE" ^
    --templateProperty gcs.gcs.temp.query="TEMP_QUERY"

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: 必須。IAM 設定に載っている プロジェクト ID Google Cloud 。
  • REGION: 必須。Compute Engine のリージョン
  • SUBNET: 省略可。サブネットが指定されていない場合、default ネットワークの指定された REGION のサブネットが選択されます。

    : projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME

  • TEMPLATE_VERSION: 必須。最新のテンプレート バージョンまたは特定バージョンの日付(2023-03-17_v0.1.0-beta など)には latest を指定します(gs://dataproc-templates-binaries にアクセスするか、gcloud storage ls gs://dataproc-templates-binaries を実行して、使用可能なテンプレート バージョンを一覧表示します)。
  • CLOUD_STORAGE_INPUT_PATH: 必須。入力データの読み取り元の Cloud Storage パス。

    : gs://example-bucket/example-folder/

  • FORMAT: 必須。入力データ形式オプション: avroparquetorc注: avro の場合、jars gcloud CLI フラグまたは API フィールドに「file:///usr/lib/spark/connector/spark-avro.jar」を追加する必要があります。

    例(file:// 接頭辞は Managed Service for Apache Spark jar ファイルを参照します):

    --jars=file:///usr/lib/spark/connector/spark-avro.jar, [ ... other jars]
  • CLOUD_STORAGE_OUTPUT_PATH: 必須。出力が保存される Cloud Storage パス。

    : gs://example-bucket/example-folder/

  • OUTPUT_FILE_FORMAT: 必須。出力データ形式。オプション: avrocsvparquetjsonorc注: avro の場合、jars gcloud CLI フラグまたは API フィールドに「file:///usr/lib/spark/connector/spark-avro.jar」を追加する必要があります。

    例(file:// 接頭辞は Managed Service for Apache Spark jar ファイルを参照します):

    --jars=file:///usr/lib/spark/connector/spark-avro.jar, [ ... other jars]
  • MODE: 必須。Cloud Storage 出力の書き込みモード。 オプション: AppendOverwriteIgnoreErrorIfExists
  • TEMP_TABLETEMP_QUERY: 省略可。これら 2 つのオプションのパラメータを使用して、Cloud Storage にデータを読み込んでいる間に Spark SQL 変換を適用できます。 TEMP_TABLE は一時的なビュー名で、TEMP_QUERY はクエリ ステートメントです。TEMP_TABLE と TEMP_QUERY のテーブル名は一致する必要があります。
  • SERVICE_ACCOUNT: 省略可。指定されていない場合は、デフォルトの Compute Engine サービス アカウントが使用されます。
  • PROPERTYPROPERTY_VALUE: 省略可。Spark プロパティ=value ペアのカンマ区切りのリスト。
  • LABELLABEL_VALUE: 省略可。label=value ペアのカンマ区切りのリスト。
  • LOG_LEVEL: 省略可。ロギングのレベル。ALLDEBUGERRORFATALINFOOFFTRACEWARN のいずれかです。デフォルト: INFO
  • KMS_KEY: 省略可。暗号化に使用する Cloud Key Management Service 鍵。鍵が指定されていない場合、データは保存時に暗号化されます。 Google-owned and Google-managed encryption key

    例: projects/PROJECT_ID/regions/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME

HTTP メソッドと URL:

POST https://dataproc.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/batches

リクエストの本文(JSON):


{
  "environmentConfig":{
    "executionConfig":{
      "subnetworkUri":"SUBNET",
      "kmsKey": "KMS_KEY",
      "serviceAccount": "SERVICE_ACCOUNT"
    }
  },
  "labels": {
    "LABEL": "LABEL_VALUE"
  },
  "runtimeConfig": {
    "version": "1.2",
    "properties": {
      "PROPERTY": "PROPERTY_VALUE"
    }
  },
  "sparkBatch": {
    "mainClass": "com.google.cloud.dataproc.templates.main.DataProcTemplate",
    "args": [
      "--template","GCSTOGCS",
      "--templateProperty","project.id=PROJECT_ID",
      "--templateProperty","log.level=LOG_LEVEL",
      "--templateProperty","gcs.gcs.input.location=CLOUD_STORAGE_INPUT_PATH",
      "--templateProperty","gcs.gcs.input.format=INPUT_FILE_FORMAT",
      "--templateProperty","gcs.gcs.output.location=CLOUD_STORAGE_OUTPUT_PATH",
      "--templateProperty","gcs.gcs.output.format=OUTPUT_FILE_FORMAT",
      "--templateProperty","gcs.gcs.write.mode=MODE",
      "--templateProperty","gcs.gcs.temp.table=TEMP_TABLE",
      "--templateProperty","gcs.gcs.temp.query=TEMP_QUERY"
    ],
    "jarFileUris":[
      "gs://dataproc-templates-binaries/TEMPLATE_VERSION/java/dataproc-templates.jar",
      "file:///usr/lib/spark/connector/spark-avro.jar"
    ]
  }
}

リクエストを送信するには、次のいずれかのオプションを展開します。

次のような JSON レスポンスが返されます。


{
  "name": "projects/PROJECT_ID/regions/REGION/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.dataproc.v1.BatchOperationMetadata",
    "batch": "projects/PROJECT_ID/locations/REGION/batches/BATCH_ID",
    "batchUuid": "de8af8d4-3599-4a7c-915c-798201ed1583",
    "createTime": "2023-02-24T03:31:03.440329Z",
    "operationType": "BATCH",
    "description": "Batch"
  }
}