Vorlage „Cloud Storage zu Cloud Storage“
Mit der Vorlage „Cloud Storage zu Cloud Storage“ des Managed Service for Apache Spark können Sie Daten aus Cloud Storage in Cloud Storage extrahieren.
Vorlage verwenden
Führen Sie die Vorlage mit der gcloud CLI oder der Managed Service for Apache Spark API aus.
gcloud
Ersetzen Sie folgende Werte, bevor sie einen der Befehlsdaten verwenden:
- PROJECT_ID: erforderlich. Ihre Google Cloud Projekt-ID, die in den IAM-Einstellungen aufgeführt ist.
- REGION: erforderlich. Compute Engine -Region.
- SUBNET: optional. Wenn kein Subnetzwerk angegeben ist, wird das Subnetzwerk
in der angegebenen REGION im
defaultNetzwerk ausgewählt.Beispiel:
projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME - TEMPLATE_VERSION: erforderlich. Geben Sie
latestfür die neueste Vorlagenversion oder das Datum einer bestimmten Version an, z. B.2023-03-17_v0.1.0-beta(unter gs://templates-binaries oder mit dem Befehlgcloud storage ls gs://templates-binarieskönnen Sie die verfügbaren Vorlagenversionen auflisten). - CLOUD_STORAGE_INPUT_PATH: erforderlich. Cloud Storage-Pfad, aus dem Eingabedaten gelesen werden.
Beispiel:
gs://example-bucket/example-folder/ - FORMAT: erforderlich. Format für Eingabedaten. Optionen:
avro,parquetoderorc. Hinweis: Wenn Sieavroverwenden, müssen Sie dem gcloud CLI-Flag oder API-Feldjars"file:///usr/lib/spark/connector/spark-avro.jar" hinzufügen.Beispiel (das Präfix
file://verweist auf eine JAR-Datei des Managed Service for Apache Spark):--jars=file:///usr/lib/spark/connector/spark-avro.jar,[ ... other jars] -
CLOUD_STORAGE_OUTPUT_PATH:
erforderlich. Cloud Storage-Pfad, in dem die Ausgabe gespeichert wird.
Beispiel:
gs://example-bucket/example-folder/ -
OUTPUT_FILE_FORMAT:
erforderlich. Ausgabedatenformat. Optionen:
avro,csvparquet,jsonoderorc. Hinweis: Wenn Sieavroverwenden, müssen Sie dem gcloud CLI-Flag oder API-Feldjars"file:///usr/lib/spark/connector/spark-avro.jar" hinzufügen.Beispiel (das Präfix
file://verweist auf eine JAR-Datei des Managed Service for Apache Spark):--jars=file:///usr/lib/spark/connector/spark-avro.jar,[ ... other jars] -
MODE:
erforderlich. Schreibmodus für die Cloud Storage-Ausgabe.
Optionen:
Append,Overwrite,IgnoreoderErrorIfExists. - TEMP_TABLE und TEMP_QUERY: optional. Mit diesen beiden optionalen Parametern können Sie eine Spark SQL-Transformation anwenden, während Sie Daten in Cloud Storage laden. TEMP_TABLE ist der Name der temporären Ansicht und TEMP_QUERY ist die Abfrageanweisung. TEMP_TABLE und der Tabellenname in TEMP_QUERY müssen übereinstimmen.
- SERVICE_ACCOUNT: optional. Wenn nicht angegeben, wird das Compute Engine-Standarddienstkonto verwendet.
- PROPERTY und PROPERTY_VALUE:
optional. Durch Kommas getrennte Liste von
Spark-Eigenschaft=
valuePaaren. - LABEL und LABEL_VALUE:
optional. Durch Kommas getrennte Liste von
label=value-Paaren. - LOG_LEVEL: optional. Protokollierungsstufe. Mögliche Werte:
ALL,DEBUG,ERROR,FATAL,INFO,OFF,TRACEoderWARN. Standard:INFO. -
KMS_KEY: optional. Der Cloud Key Management Service-Schlüssel, der für die Verschlüsselung verwendet werden soll. Wenn kein Schlüssel angegeben ist, werden inaktive Daten verschlüsselt mit einem Google-owned and Google-managed encryption key.
Beispiel:
projects/PROJECT_ID/regions/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
Führen Sie folgenden Befehl aus:
Linux, macOS oder 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://templates-binaries/TEMPLATE_VERSION/java/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://templates-binaries/TEMPLATE_VERSION/java/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://templates-binaries/TEMPLATE_VERSION/java/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
Ersetzen Sie diese Werte in den folgenden Anfragedaten:
- PROJECT_ID: erforderlich. Ihre Google Cloud Projekt-ID, die in den IAM-Einstellungen aufgeführt ist.
- REGION: erforderlich. Compute Engine -Region.
- SUBNET: optional. Wenn kein Subnetzwerk angegeben ist, wird das Subnetzwerk
in der angegebenen REGION im
defaultNetzwerk ausgewählt.Beispiel:
projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME - TEMPLATE_VERSION: erforderlich. Geben Sie
latestfür die neueste Vorlagenversion oder das Datum einer bestimmten Version an, z. B.2023-03-17_v0.1.0-beta(unter gs://templates-binaries oder mit dem Befehlgcloud storage ls gs://templates-binarieskönnen Sie die verfügbaren Vorlagenversionen auflisten). - CLOUD_STORAGE_INPUT_PATH: erforderlich. Cloud Storage-Pfad, aus dem Eingabedaten gelesen werden.
Beispiel:
gs://example-bucket/example-folder/ - FORMAT: erforderlich. Format für Eingabedaten. Optionen:
avro,parquetoderorc. Hinweis: Wenn Sieavroverwenden, müssen Sie dem gcloud CLI-Flag oder API-Feldjars"file:///usr/lib/spark/connector/spark-avro.jar" hinzufügen.Beispiel (das Präfix
file://verweist auf eine JAR-Datei des Managed Service for Apache Spark):--jars=file:///usr/lib/spark/connector/spark-avro.jar,[ ... other jars] -
CLOUD_STORAGE_OUTPUT_PATH:
erforderlich. Cloud Storage-Pfad, in dem die Ausgabe gespeichert wird.
Beispiel:
gs://example-bucket/example-folder/ -
OUTPUT_FILE_FORMAT:
erforderlich. Ausgabedatenformat. Optionen:
avro,csvparquet,jsonoderorc. Hinweis: Wenn Sieavroverwenden, müssen Sie dem gcloud CLI-Flag oder API-Feldjars"file:///usr/lib/spark/connector/spark-avro.jar" hinzufügen.Beispiel (das Präfix
file://verweist auf eine JAR-Datei des Managed Service for Apache Spark):--jars=file:///usr/lib/spark/connector/spark-avro.jar,[ ... other jars] -
MODE:
erforderlich. Schreibmodus für die Cloud Storage-Ausgabe.
Optionen:
Append,Overwrite,IgnoreoderErrorIfExists. - TEMP_TABLE und TEMP_QUERY: optional. Mit diesen beiden optionalen Parametern können Sie eine Spark SQL-Transformation anwenden, während Sie Daten in Cloud Storage laden. TEMP_TABLE ist der Name der temporären Ansicht und TEMP_QUERY ist die Abfrageanweisung. TEMP_TABLE und der Tabellenname in TEMP_QUERY müssen übereinstimmen.
- SERVICE_ACCOUNT: optional. Wenn nicht angegeben, wird das Compute Engine-Standarddienstkonto verwendet.
- PROPERTY und PROPERTY_VALUE:
optional. Durch Kommas getrennte Liste von
Spark-Eigenschaft=
valuePaaren. - LABEL und LABEL_VALUE:
optional. Durch Kommas getrennte Liste von
label=value-Paaren. - LOG_LEVEL: optional. Protokollierungsstufe. Mögliche Werte:
ALL,DEBUG,ERROR,FATAL,INFO,OFF,TRACEoderWARN. Standard:INFO. -
KMS_KEY: optional. Der Cloud Key Management Service-Schlüssel, der für die Verschlüsselung verwendet werden soll. Wenn kein Schlüssel angegeben ist, werden inaktive Daten verschlüsselt mit einem Google-owned and Google-managed encryption key.
Beispiel:
projects/PROJECT_ID/regions/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
HTTP-Methode und URL:
POST https://dataproc.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/batches
JSON-Text anfordern:
{
"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://templates-binaries/TEMPLATE_VERSION/java/templates.jar",
"file:///usr/lib/spark/connector/spark-avro.jar"
]
}
}
Wenn Sie die Anfrage senden möchten, maximieren Sie eine der folgenden Optionen:
Sie sollten eine JSON-Antwort ähnlich wie diese erhalten:
{
"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"
}
}