Modello da Cloud Storage a BigQuery
Utilizza il modello Dataproc Serverless Cloud Storage to BigQuery per estrarre i dati da Cloud Storage in BigQuery.
Utilizzare il modello
Esegui il modello utilizzando l'interfaccia a riga di comando gcloud o l'API Dataproc.
gcloud
Prima di utilizzare i dati dei comandi riportati di seguito, effettua le seguenti sostituzioni:
- PROJECT_ID: obbligatorio. Il tuo Google Cloud ID progetto elencato nelle Impostazioni IAM.
- REGION: obbligatorio. Regione Compute Engine.
- TEMPLATE_VERSION: obbligatorio. Specifica
latest
per la versione del modello più recente o la data di una versione specifica, ad esempio2023-03-17_v0.1.0-beta
(visita gs://dataproc-templates-binaries o eseguigcloud storage ls gs://dataproc-templates-binaries
per elencare le versioni del modello disponibili). - CLOUD_STORAGE_PATH: obbligatorio. Percorso Cloud Storage di origine.
Esempio:
gs://dataproc-templates/hive_to_cloud_storage_output"
- FORMAT: obbligatorio. Formato dei dati di input. Opzioni:
avro
,parquet
,csv
ojson
. Nota: seavro
, devi aggiungere "file:///usr/lib/spark/connector/spark-avro.jar
" al campo dell'API o del flag gcloud CLIjars
.Esempio (il prefisso
file://
fa riferimento a un file jar di Dataproc Serverless):--jars=file:///usr/lib/spark/connector/spark-avro.jar,
[, ... other jars] - DATASET: obbligatorio. Set di dati BigQuery di destinazione.
- TABLE: obbligatorio. Tabella BigQuery di destinazione.
- TEMP_BUCKET: obbligatorio. Bucket Cloud Storage temporaneo utilizzato per la gestione temporanea dei dati prima del caricamento in BigQuery.
- SUBNET: facoltativo. Se non viene specificata una subnet, viene selezionata la subnet nella REGIONE specificata nella rete
default
.Esempio:
projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME
- TEMPVIEW e SQL_QUERY: facoltativi. Puoi utilizzare questi due parametri facoltativi per applicare una trasformazione Spark SQL durante il caricamento dei dati in BigQuery. TEMPVIEW è il nome della visualizzazione temporanea e SQL_QUERY è l'istruzione di query. TEMPVIEW e il nome della tabella in SQL_QUERY devono corrispondere.
- SERVICE_ACCOUNT: facoltativo. Se non viene specificato, viene utilizzato l'account di servizio Compute Engine predefinito.
- PROPERTY e PROPERTY_VALUE:
facoltativi. Elenco separato da virgole di
coppie Proprietà Spark=
value
. - LABEL e LABEL_VALUE:
facoltativi. Elenco separato da virgole di coppie
label
=value
. - LOG_LEVEL: facoltativo. Livello di registrazione. Può essere uno dei seguenti valori:
ALL
,DEBUG
,ERROR
,FATAL
,INFO
,OFF
,TRACE
oWARN
. Valore predefinito:INFO
. -
KMS_KEY: facoltativo. La chiave Cloud Key Management Service da utilizzare per la crittografia. Se non viene specificata una chiave, i dati vengono criptati at-rest utilizzando un Google-owned and Google-managed encryption key.
Esempio:
projects/PROJECT_ID/regions/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
Esegui il seguente comando:
Linux, macOS o 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=GCSTOBIGQUERY \ --templateProperty log.level="LOG_LEVEL" \ --templateProperty project.id="PROJECT_ID" \ --templateProperty gcs.bigquery.input.location="CLOUD_STORAGE_PATH" \ --templateProperty gcs.bigquery.input.format="FORMAT" \ --templateProperty gcs.bigquery.output.dataset="DATASET" \ --templateProperty gcs.bigquery.output.table="TABLE" \ --templateProperty gcs.bigquery.temp.bucket.name="TEMP_BUCKET" \ --templateProperty gcs.bigquery.temp.table="TEMPVIEW" \ --templateProperty gcs.bigquery.temp.query="SQL_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" ` --subnet="SUBNET" ` --kms-key="KMS_KEY" ` --service-account="SERVICE_ACCOUNT" ` --properties="PROPERTY=PROPERTY_VALUE" ` --labels="LABEL=LABEL_VALUE" ` -- --template=GCSTOBIGQUERY ` --templateProperty log.level="LOG_LEVEL" ` --templateProperty project.id="PROJECT_ID" ` --templateProperty gcs.bigquery.input.location="CLOUD_STORAGE_PATH" ` --templateProperty gcs.bigquery.input.format="FORMAT" ` --templateProperty gcs.bigquery.output.dataset="DATASET" ` --templateProperty gcs.bigquery.output.table="TABLE" ` --templateProperty gcs.bigquery.temp.bucket.name="TEMP_BUCKET" ` --templateProperty gcs.bigquery.temp.table="TEMPVIEW" ` --templateProperty gcs.bigquery.temp.query="SQL_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" ^ --subnet="SUBNET" ^ --kms-key="KMS_KEY" ^ --service-account="SERVICE_ACCOUNT" ^ --properties="PROPERTY=PROPERTY_VALUE" ^ --labels="LABEL=LABEL_VALUE" ^ -- --template=GCSTOBIGQUERY ^ --templateProperty log.level="LOG_LEVEL" ^ --templateProperty project.id="PROJECT_ID" ^ --templateProperty gcs.bigquery.input.location="CLOUD_STORAGE_PATH" ^ --templateProperty gcs.bigquery.input.format="FORMAT" ^ --templateProperty gcs.bigquery.output.dataset="DATASET" ^ --templateProperty gcs.bigquery.output.table="TABLE" ^ --templateProperty gcs.bigquery.temp.bucket.name="TEMP_BUCKET" ^ --templateProperty gcs.bigquery.temp.table="TEMPVIEW" ^ --templateProperty gcs.bigquery.temp.query="SQL_QUERY"
REST
Prima di utilizzare i dati della richiesta, apporta le seguenti sostituzioni:
- PROJECT_ID: obbligatorio. Il tuo Google Cloud ID progetto elencato nelle Impostazioni IAM.
- REGION: obbligatorio. Regione Compute Engine.
- TEMPLATE_VERSION: obbligatorio. Specifica
latest
per la versione del modello più recente o la data di una versione specifica, ad esempio2023-03-17_v0.1.0-beta
(visita gs://dataproc-templates-binaries o eseguigcloud storage ls gs://dataproc-templates-binaries
per elencare le versioni del modello disponibili). - CLOUD_STORAGE_PATH: obbligatorio. Percorso Cloud Storage di origine.
Esempio:
gs://dataproc-templates/hive_to_cloud_storage_output"
- FORMAT: obbligatorio. Formato dei dati di input. Opzioni:
avro
,parquet
,csv
ojson
. Nota: seavro
, devi aggiungere "file:///usr/lib/spark/connector/spark-avro.jar
" al campo dell'API o del flag gcloud CLIjars
.Esempio (il prefisso
file://
fa riferimento a un file jar di Dataproc Serverless):--jars=file:///usr/lib/spark/connector/spark-avro.jar,
[, ... other jars] - DATASET: obbligatorio. Set di dati BigQuery di destinazione.
- TABLE: obbligatorio. Tabella BigQuery di destinazione.
- TEMP_BUCKET: obbligatorio. Bucket Cloud Storage temporaneo utilizzato per la gestione temporanea dei dati prima del caricamento in BigQuery.
- SUBNET: facoltativo. Se non viene specificata una subnet, viene selezionata la subnet nella REGIONE specificata nella rete
default
.Esempio:
projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME
- TEMPVIEW e SQL_QUERY: facoltativi. Puoi utilizzare questi due parametri facoltativi per applicare una trasformazione Spark SQL durante il caricamento dei dati in BigQuery. TEMPVIEW è il nome della visualizzazione temporanea e SQL_QUERY è l'istruzione di query. TEMPVIEW e il nome della tabella in SQL_QUERY devono corrispondere.
- SERVICE_ACCOUNT: facoltativo. Se non viene specificato, viene utilizzato l'account di servizio Compute Engine predefinito.
- PROPERTY e PROPERTY_VALUE:
facoltativi. Elenco separato da virgole di
coppie Proprietà Spark=
value
. - LABEL e LABEL_VALUE:
facoltativi. Elenco separato da virgole di coppie
label
=value
. - LOG_LEVEL: facoltativo. Livello di registrazione. Può essere uno dei seguenti valori:
ALL
,DEBUG
,ERROR
,FATAL
,INFO
,OFF
,TRACE
oWARN
. Valore predefinito:INFO
. -
KMS_KEY: facoltativo. La chiave Cloud Key Management Service da utilizzare per la crittografia. Se non viene specificata una chiave, i dati vengono criptati at-rest utilizzando un Google-owned and Google-managed encryption key.
Esempio:
projects/PROJECT_ID/regions/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
Metodo HTTP e URL:
POST https://dataproc.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/batches
Corpo JSON della richiesta:
{ "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", "GCSTOBIGQUERY", "--templateProperty","log.level=LOG_LEVEL", "--templateProperty","project.id=PROJECT_ID", "--templateProperty","gcs.bigquery.input.location=CLOUD_STORAGE_PATH", "--templateProperty","gcs.bigquery.input.format=FORMAT", "--templateProperty","gcs.bigquery.output.dataset=DATASET", "--templateProperty","gcs.bigquery.output.table=TABLE", "--templateProperty","gcs.bigquery.temp.bucket.name=TEMP_BUCKET", "--templateProperty","gcs.bigquery.temp.table=TEMPVIEW", "--templateProperty","gcs.bigquery.temp.query=SQL_QUERY" ], "jarFileUris":[ "file:///usr/lib/spark/connector/spark-avro.jar", "gs://dataproc-templates-binaries/TEMPLATE_VERSION/java/dataproc-templates.jar" ] } }
Per inviare la richiesta, espandi una di queste opzioni:
Dovresti ricevere una risposta JSON simile alla seguente:
{ "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" } }