Vorlage „Cloud Storage für Cloud Spanner“
Verwenden Sie die Vorlage „Serverless for Apache Spark Cloud Storage to Spanner“, um Daten aus Cloud Storage in Spanner zu extrahieren.
Vorlage verwenden
Führen Sie die Vorlage mit der gcloud CLI oder der Dataproc API aus.
gcloud
Ersetzen Sie folgende Werte, bevor sie einen der Befehlsdaten verwenden:
- PROJECT_ID: erforderlich. Die Google Cloud Projekt-ID, die in den IAM-Einstellungen aufgeführt ist.
- REGION: erforderlich. Compute Engine-Region.
- SUBNET: Optional. Wenn kein Subnetz angegeben ist, wird das Subnetz in der angegebenen REGION im Netzwerk
default
ausgewählt.Beispiel:
projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME
- TEMPLATE_VERSION: erforderlich. Geben Sie
latest
für die neueste Vorlagenversion oder das Datum einer bestimmten Version an, z. B.2023-03-17_v0.1.0-beta
. Rufen Sie gs://dataproc-templates-binaries auf oder führen Siegcloud storage ls gs://dataproc-templates-binaries
aus, um die verfügbaren Vorlagenversionen aufzulisten. - CLOUD_STORAGE_INPUT_PATH: erforderlich. Cloud Storage-Pfad, aus dem Eingabedaten gelesen werden.
Beispiel:
gs://example-bucket/example-folder/
- FORMAT: erforderlich. Format der Eingabedaten. Optionen:
avro
,parquet
oderorc
. Hinweis:Wennavro
, 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 Serverless for Apache Spark-JAR-Datei):--jars=file:///usr/lib/spark/connector/spark-avro.jar,
[ ... other jars] - INSTANCE: erforderlich. Cloud Spanner-Instanz-ID.
- DATABASE: erforderlich. Die Datenbank-ID der Spanner-Datenbank.
- TABLE: erforderlich. Name der Spanner-Ausgabetabelle.
- SPANNER_JDBC_DIALECT: erforderlich. Spanner-JDBC-Dialekt.
Optionen:
googlesql
oderpostgresql
. Die Standardeinstellung istgooglesql
. - MODE: Optional. Schreibmodus für die Spanner-Ausgabe.
Optionen:
Append
,Overwrite
,Ignore
oderErrorifExists
. Die Standardeinstellung istErrorifExists
. - PRIMARY_KEY: erforderlich. Durch Kommas getrennte Primärschlüsselspalten, die beim Erstellen der Spanner-Ausgabetabelle erforderlich sind.
- BATCHSIZE: Optional. Anzahl der Datensätze, die in einem Roundtrip in die Spanner-Tabelle eingefügt werden sollen. Der Standardwert ist 1.000.
- SERVICE_ACCOUNT: Optional. Wenn nicht angegeben, wird das Compute Engine-Standarddienstkonto verwendet.
- PROPERTY und PROPERTY_VALUE:
Optional. Durch Kommas getrennte Liste von Spark-Eigenschaft=
value
-Paaren. - LABEL und LABEL_VALUE:
Optional. Durch Kommas getrennte Liste von
label
=value
-Paaren. - LOG_LEVEL: Optional. Ebene der Protokollierung. Kann einer der folgenden Werte sein:
ALL
,DEBUG
,ERROR
,FATAL
,INFO
,OFF
,TRACE
oderWARN
. 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 Daten mit einem Google-owned and Google-managed encryption keyim Ruhezustand verschlüsselt.
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://dataproc-templates-binaries/TEMPLATE_VERSION/java/dataproc-templates.jar" \ --subnet="SUBNET" \ --kms-key="KMS_KEY" \ --service-account="SERVICE_ACCOUNT" \ --properties="PROPERTY=PROPERTY_VALUE" \ --labels="LABEL=LABEL_VALUE" \ -- --template GCSTOSPANNER \ --templateProperty log.level="LOG_LEVEL" \ --templateProperty project.id="PROJECT_ID" \ --templateProperty gcs.spanner.input.format="FORMAT" \ --templateProperty gcs.spanner.input.location="CLOUD_STORAGE_INPUT_PATH" \ --templateProperty gcs.spanner.output.instance="INSTANCE" \ --templateProperty gcs.spanner.output.database="DATABASE" \ --templateProperty gcs.spanner.output.table="TABLE" \ --templateProperty gcs.spanner.output.saveMode="MODE" \ --templateProperty gcs.spanner.output.primaryKey="PRIMARY_KEY" \ --templateProperty gcs.spanner.output.batchInsertSize="BATCHSIZE" \ --templateProperty spanner.jdbc.dialect="SPANNER_JDBC_DIALECT"
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" ` --subnet="SUBNET" ` --kms-key="KMS_KEY" ` --service-account="SERVICE_ACCOUNT" ` --properties="PROPERTY=PROPERTY_VALUE" ` --labels="LABEL=LABEL_VALUE" ` -- --template GCSTOSPANNER ` --templateProperty log.level="LOG_LEVEL" ` --templateProperty project.id="PROJECT_ID" ` --templateProperty gcs.spanner.input.format="FORMAT" ` --templateProperty gcs.spanner.input.location="CLOUD_STORAGE_INPUT_PATH" ` --templateProperty gcs.spanner.output.instance="INSTANCE" ` --templateProperty gcs.spanner.output.database="DATABASE" ` --templateProperty gcs.spanner.output.table="TABLE" ` --templateProperty gcs.spanner.output.saveMode="MODE" ` --templateProperty gcs.spanner.output.primaryKey="PRIMARY_KEY" ` --templateProperty gcs.spanner.output.batchInsertSize="BATCHSIZE" ` --templateProperty spanner.jdbc.dialect="SPANNER_JDBC_DIALECT"
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" ^ --subnet="SUBNET" ^ --kms-key="KMS_KEY" ^ --service-account="SERVICE_ACCOUNT" ^ --properties="PROPERTY=PROPERTY_VALUE" ^ --labels="LABEL=LABEL_VALUE" ^ -- --template GCSTOSPANNER ^ --templateProperty log.level="LOG_LEVEL" ^ --templateProperty project.id="PROJECT_ID" ^ --templateProperty gcs.spanner.input.format="FORMAT" ^ --templateProperty gcs.spanner.input.location="CLOUD_STORAGE_INPUT_PATH" ^ --templateProperty gcs.spanner.output.instance="INSTANCE" ^ --templateProperty gcs.spanner.output.database="DATABASE" ^ --templateProperty gcs.spanner.output.table="TABLE" ^ --templateProperty gcs.spanner.output.saveMode="MODE" ^ --templateProperty gcs.spanner.output.primaryKey="PRIMARY_KEY" ^ --templateProperty gcs.spanner.output.batchInsertSize="BATCHSIZE" ^ --templateProperty spanner.jdbc.dialect="SPANNER_JDBC_DIALECT"
REST
Ersetzen Sie diese Werte in den folgenden Anfragedaten:
- PROJECT_ID: erforderlich. Die Google Cloud Projekt-ID, die in den IAM-Einstellungen aufgeführt ist.
- REGION: erforderlich. Compute Engine-Region.
- SUBNET: Optional. Wenn kein Subnetz angegeben ist, wird das Subnetz in der angegebenen REGION im Netzwerk
default
ausgewählt.Beispiel:
projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME
- TEMPLATE_VERSION: erforderlich. Geben Sie
latest
für die neueste Vorlagenversion oder das Datum einer bestimmten Version an, z. B.2023-03-17_v0.1.0-beta
. Rufen Sie gs://dataproc-templates-binaries auf oder führen Siegcloud storage ls gs://dataproc-templates-binaries
aus, um die verfügbaren Vorlagenversionen aufzulisten. - CLOUD_STORAGE_INPUT_PATH: erforderlich. Cloud Storage-Pfad, aus dem Eingabedaten gelesen werden.
Beispiel:
gs://example-bucket/example-folder/
- FORMAT: erforderlich. Format der Eingabedaten. Optionen:
avro
,parquet
oderorc
. Hinweis:Wennavro
, 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 Serverless for Apache Spark-JAR-Datei):--jars=file:///usr/lib/spark/connector/spark-avro.jar,
[ ... other jars] - INSTANCE: erforderlich. Cloud Spanner-Instanz-ID.
- DATABASE: erforderlich. Die Datenbank-ID der Spanner-Datenbank.
- TABLE: erforderlich. Name der Spanner-Ausgabetabelle.
- SPANNER_JDBC_DIALECT: erforderlich. Spanner-JDBC-Dialekt.
Optionen:
googlesql
oderpostgresql
. Die Standardeinstellung istgooglesql
. - MODE: Optional. Schreibmodus für die Spanner-Ausgabe.
Optionen:
Append
,Overwrite
,Ignore
oderErrorifExists
. Die Standardeinstellung istErrorifExists
. - PRIMARY_KEY: erforderlich. Durch Kommas getrennte Primärschlüsselspalten, die beim Erstellen der Spanner-Ausgabetabelle erforderlich sind.
- BATCHSIZE: Optional. Anzahl der Datensätze, die in einem Roundtrip in die Spanner-Tabelle eingefügt werden sollen. Der Standardwert ist 1.000.
- SERVICE_ACCOUNT: Optional. Wenn nicht angegeben, wird das Compute Engine-Standarddienstkonto verwendet.
- PROPERTY und PROPERTY_VALUE:
Optional. Durch Kommas getrennte Liste von Spark-Eigenschaft=
value
-Paaren. - LABEL und LABEL_VALUE:
Optional. Durch Kommas getrennte Liste von
label
=value
-Paaren. - LOG_LEVEL: Optional. Ebene der Protokollierung. Kann einer der folgenden Werte sein:
ALL
,DEBUG
,ERROR
,FATAL
,INFO
,OFF
,TRACE
oderWARN
. 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 Daten mit einem Google-owned and Google-managed encryption keyim Ruhezustand verschlüsselt.
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","GCSTOSPANNER", "--templateProperty","project.id=PROJECT_ID", "--templateProperty","log.level=LOG_LEVEL", "--templateProperty","gcs.spanner.input.format=FORMAT", "--templateProperty","gcs.spanner.input.location=CLOUD_STORAGE_INPUT_PATH", "--templateProperty","gcs.spanner.output.instance=INSTANCE", "--templateProperty","gcs.spanner.output.database=DATABASE", "--templateProperty","gcs.spanner.output.table=TABLE", "--templateProperty","gcs.spanner.output.saveMode=MODE", "--templateProperty","gcs.spanner.output.primaryKey=PRIMARY_KEY", "--templateProperty","gcs.spanner.output.batchInsertSize=BATCHSIZE", "--templateProperty spanner.jdbc.dialect=SPANNER_JDBC_DIALECT" ], "jarFileUris":[ "gs://dataproc-templates-binaries/TEMPLATE_VERSION/java/dataproc-templates.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" } }