Vorlage von JDBC zu JDBC

Verwenden Sie die Dataproc Serverless-Vorlage „JDBC-zu-JDBC“, um Daten aus JDBC in JDBC zu extrahieren.

Diese Vorlage unterstützt die folgenden Datenbanken:

  • MySQL
  • PostgreSQL
  • Microsoft SQL Server
  • Oracle

Vorlage verwenden

Führen Sie die Vorlage mithilfe der gcloud CLI oder Dataproc API aus.

gcloud

Bevor Sie die folgenden Befehlsdaten verwenden, ersetzen Sie die folgenden Werte:

  • 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 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 Sie gsutil ls gs://dataproc-templates-binaries aus, um die verfügbaren Vorlagenversionen aufzulisten.
  • INPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH und OUTPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH: Erforderlich. Der vollständige Cloud Storage-Pfad, einschließlich des Dateinamens, in dem die JDBC-Connector-JAR-Dateien für Ein- und Ausgabe gespeichert sind.

    Hinweis: Wenn die Eingabe- und Ausgabe-JAR-Dateien identisch sind, reicht es aus, nur INPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH festzulegen.

    Mit den folgenden Befehlen können Sie JDBC-Connectors für das Hochladen in Cloud Storage herunterladen:

    • MySQL:
        wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.30.tar.gz
    • PostgreSQL:
        wget https://jdbc.postgresql.org/download/postgresql-42.2.6.jar
    • Microsoft SQL Server:
        wget https://repo1.maven.org/maven2/com/microsoft/sqlserver/mssql-jdbc/6.4.0.jre8/mssql-jdbc-6.4.0.jre8.jar
    • Oracle:
        wget https://repo1.maven.org/maven2/com/oracle/database/jdbc/ojdbc8/21.7.0.0/ojdbc8-21.7.0.0.jar

  • Die folgenden Variablen werden verwendet, um die erforderliche JDBC-Eingabe-URL zu erstellen:
    • INPUT_JDBC_HOST
    • INPUT_JDBC_PORT
    • INPUT_JDBC_DATABASE oder für Oracle INPUT_JDBC_SERVICE
    • INPUT_JDBC_USERNAME
    • INPUT_JDBC_PASSWORD

    Erstellen Sie das INPUT_JDBC_CONNECTION_URL mit einem der folgenden Connector-spezifischen Formate:

    • MySQL:
      jdbc:mysql://INPUT_JDBC_HOST:INPUT_JDBC_PORT/INPUT_JDBC_DATABASE?user=INPUT_JDBC_USERNAME&password=INPUT_JDBC_PASSWORD
    • PostgreSQL:
      jdbc:postgresql://INPUT_JDBC_HOST:INPUT_JDBC_PORT/INPUT_JDBC_DATABASE?user=INPUT_JDBC_USERNAME&password=INPUT_JDBC_PASSWORD
    • Microsoft SQL Server:
      jdbc:sqlserver://INPUT_JDBC_HOST:INPUT_JDBC_PORT;databaseName=INPUT_JDBC_DATABASE;user=INPUT_JDBC_USERNAME;password=INPUT_JDBC_PASSWORD
    • Oracle:
      jdbc:oracle:thin:@//INPUT_JDBC_HOST:INPUT_JDBC_PORT/INPUT_JDBC_SERVICE?user=INPUT_JDBC_USERNAME&password=INPUT_JDBC_PASSWORD
  • Die folgenden Variablen werden verwendet, um die erforderliche JDBC-Ausgabe-URL zu erstellen:
    • OUTPUT_JDBC_HOST
    • OUTPUT_JDBC_PORT
    • OUTPUT_JDBC_DATABASE oder für Oracle OUTPUT_JDBC_SERVICE
    • OUTPUT_JDBC_USERNAME
    • OUTPUT_JDBC_PASSWORD

    Erstellen Sie das OUTPUT_JDBC_CONNECTION_URL mit einem der folgenden Connector-spezifischen Formate:

    • MySQL:
      jdbc:mysql://OUTPUT_JDBC_HOST:OUTPUT_JDBC_PORT/OUTPUT_JDBC_DATABASE?user=OUTPUT_JDBC_USERNAME&password=OUTPUT_JDBC_PASSWORD
    • PostgreSQL:
      jdbc:postgresql://OUTPUT_JDBC_HOST:OUTPUT_JDBC_PORT/OUTPUT_JDBC_DATABASE?user=OUTPUT_JDBC_USERNAME&password=OUTPUT_JDBC_PASSWORD
    • Microsoft SQL Server:
      jdbc:sqlserver://OUTPUT_JDBC_HOST:OUTPUT_JDBC_PORT;databaseName=OUTPUT_JDBC_DATABASE;user=OUTPUT_JDBC_USERNAME;password=OUTPUT_JDBC_PASSWORD
    • Oracle:
      jdbc:oracle:thin:@//OUTPUT_JDBC_HOST:OUTPUT_JDBC_PORT/OUTPUT_JDBC_SERVICE?user=OUTPUT_JDBC_USERNAME&password=OUTPUT_JDBC_PASSWORD
  • INPUT_JDBC_TABLE: erforderlich. JDBC-Eingabetabellenname oder SQL-Abfrage für die JDBC-Eingabetabelle.

    Beispiel (die SQL-Abfrage sollte in Klammern stehen): (select * from TABLE_NAME) as ALIAS_TABLE_NAME

  • OUTPUT_JDBC_TABLE: erforderlich. JDBC-Tabelle, in der die Ausgabe gespeichert wird.
  • INPUT_DRIVER und OUTPUT_DRIVER: Erforderlich. Der JDBC-Eingabe- und -Ausgabetreiber, der für die Verbindung verwendet wird:
    • MySQL:
      com.mysql.cj.jdbc.Driver
    • PostgreSQL:
      org.postgresql.Driver
    • Microsoft SQL Server:
      com.microsoft.sqlserver.jdbc.SQLServerDriver
    • Oracle:
      oracle.jdbc.driver.OracleDriver
  • INPUT_PARTITION_COLUMN, LOWERBOUND, UPPERBOUND, NUM_PARTITIONS: Optional. Bei Verwendung müssen alle der folgenden Parameter angegeben werden:
    • INPUT_PARTITION_COLUMN: Name der JDBC-Eingabetabellenpartitionsspalte.
    • LOWERBOUND: Untergrenze der JDBC-Eingabetabellenpartitionsspalte, die zum Bestimmen des Partitionsschritts verwendet wird.
    • UPPERBOUND: Obergrenze der JDBC-Eingabetabellenpartitionsspalte, die zum Bestimmen des Partitionsschritts verwendet wird.
    • NUM_PARTITIONS: Die maximale Anzahl von Partitionen, die für die Parallelität von Lese- und Schreibvorgängen von Tabellen verwendet werden können. Wenn dieser Wert angegeben ist, wird er für die JDBC-Ein- und -Ausgabeverbindung verwendet.
  • FETCHSIZE: Optional. Die Anzahl der Zeilen, die pro Umlauf abgerufen werden sollen.
  • BATCH_SIZE: Optional. Anzahl der Datensätze, die pro Umlauf eingefügt werden sollen. Standardeinstellung: 1000
  • MODE: Optional. Schreibmodus für JDBC-Ausgabe. Optionen: Append, Overwrite, Ignore oder ErrorIfExists.
  • TABLE_PROPERTIES: Optional. Mit dieser Option können beim Erstellen der Ausgabetabelle datenbankspezifische Tabellen- und Partitionsoptionen festgelegt werden.
  • PRIMARY_KEY: Optional. Primärschlüsselspalte für die Ausgabetabelle. Die genannte Spalte darf keine doppelten Werte enthalten, da andernfalls ein Fehler ausgegeben wird.
  • JDBC_SESSION_INIT: Optional. Anweisung zur Sitzungsinitialisierung zum Lesen von Java-Vorlagen.
  • LOG_LEVEL: Optional. Protokollebene. Kann ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE oder WARN sein. Standardeinstellung: INFO.
  • TEMP_VIEW und TEMP_QUERY: Optional. Mit diesen beiden optionalen Parametern können Sie beim Laden von Daten in Cloud Storage eine Spark SQL-Transformation anwenden. TEMP_VIEW muss mit dem in der Abfrage verwendeten Tabellennamen übereinstimmen und TEMP_QUERY ist die Abfrageanweisung.
  • SERVICE_ACCOUNT: Optional. Wenn nicht angegeben, wird das Compute Engine-Standarddienstkonto verwendet.
  • PROPERTY und PROPERTY_VALUE: Optional. Durch Kommas getrennte Liste von Spark property=value-Paaren.
  • LABEL und LABEL_VALUE: Optional. Durch Kommas getrennte Liste von label=value-Paaren.
  • 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 von Google verwalteten Schlüssel im inaktiven Zustand verschlüsselt.

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

Führen Sie den folgenden Befehl aus:

Linux, macOS oder Cloud Shell

gcloud dataproc batches submit spark \
    --class=com.google.cloud.dataproc.templates.main.DataProcTemplate \
    --project="PROJECT_ID" \
    --region="REGION" \
    --version="1.1" \
    --jars="gs://dataproc-templates-binaries/TEMPLATE_VERSION/java/dataproc-templates.jar,INPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH,OUTPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH" \
    --subnet="SUBNET" \
    --kms-key="KMS_KEY" \
    --service-account="SERVICE_ACCOUNT" \
    --properties="PROPERTY=PROPERTY_VALUE" \
    --labels="LABEL=LABEL_VALUE" \
    -- --template JDBCTOJDBC \
    --templateProperty project.id="PROJECT_ID" \
    --templateProperty log.level="LOG_LEVEL" \
    --templateProperty jdbctojdbc.input.url="INPUT_JDBC_CONNECTION_URL" \
    --templateProperty jdbctojdbc.input.driver="INPUT_DRIVER" \
    --templateProperty jdbctojdbc.input.table="INPUT_JDBC_TABLE" \
    --templateProperty jdbctojdbc.output.url="OUTPUT_JDBC_CONNECTION_URL" \
    --templateProperty jdbctojdbc.output.driver="OUTPUT_DRIVER" \
    --templateProperty jdbctojdbc.output.table="OUTPUT_JDBC_TABLE" \
    --templateProperty jdbctojdbc.input.fetchsize="FETCHSIZE" \
    --templateProperty jdbctojdbc.input.partitioncolumn="INPUT_PARTITION_COLUMN" \
    --templateProperty jdbctojdbc.input.lowerbound="LOWERBOUND" \
    --templateProperty jdbctojdbc.input.upperbound="UPPERBOUND" \
    --templateProperty jdbctojdbc.numpartitions="NUM_PARTITIONS" \
    --templateProperty jdbctojdbc.output.mode="MODE" \
    --templateProperty jdbctojdbc.output.batch.size="BATCH_SIZE" \
    --templateProperty jdbctojdbc.output.primary.key="PRIMARY_KEY" \
    --templateProperty jdbctojdbc.output.create.table.option="TABLE_PROPERTIES" \
    --templateProperty jdbctojdbc.sessioninitstatement="JDBC_SESSION_INIT" \
    --templateProperty jdbctojdbc.temp.view.name="TEMP_VIEW" \
    --templateProperty jdbctojdbc.sql.query="TEMP_QUERY"

Windows (PowerShell)

gcloud dataproc batches submit spark `
    --class=com.google.cloud.dataproc.templates.main.DataProcTemplate `
    --project="PROJECT_ID" `
    --region="REGION" `
    --version="1.1" `
    --jars="gs://dataproc-templates-binaries/TEMPLATE_VERSION/java/dataproc-templates.jar,INPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH,OUTPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH" `
    --subnet="SUBNET" `
    --kms-key="KMS_KEY" `
    --service-account="SERVICE_ACCOUNT" `
    --properties="PROPERTY=PROPERTY_VALUE" `
    --labels="LABEL=LABEL_VALUE" `
    -- --template JDBCTOJDBC `
    --templateProperty project.id="PROJECT_ID" `
    --templateProperty log.level="LOG_LEVEL" `
    --templateProperty jdbctojdbc.input.url="INPUT_JDBC_CONNECTION_URL" `
    --templateProperty jdbctojdbc.input.driver="INPUT_DRIVER" `
    --templateProperty jdbctojdbc.input.table="INPUT_JDBC_TABLE" `
    --templateProperty jdbctojdbc.output.url="OUTPUT_JDBC_CONNECTION_URL" `
    --templateProperty jdbctojdbc.output.driver="OUTPUT_DRIVER" `
    --templateProperty jdbctojdbc.output.table="OUTPUT_JDBC_TABLE" `
    --templateProperty jdbctojdbc.input.fetchsize="FETCHSIZE" `
    --templateProperty jdbctojdbc.input.partitioncolumn="INPUT_PARTITION_COLUMN" `
    --templateProperty jdbctojdbc.input.lowerbound="LOWERBOUND" `
    --templateProperty jdbctojdbc.input.upperbound="UPPERBOUND" `
    --templateProperty jdbctojdbc.numpartitions="NUM_PARTITIONS" `
    --templateProperty jdbctojdbc.output.mode="MODE" `
    --templateProperty jdbctojdbc.output.batch.size="BATCH_SIZE" `
    --templateProperty jdbctojdbc.output.primary.key="PRIMARY_KEY" `
    --templateProperty jdbctojdbc.output.create.table.option="TABLE_PROPERTIES" `
    --templateProperty jdbctojdbc.sessioninitstatement="JDBC_SESSION_INIT" `
    --templateProperty jdbctojdbc.temp.view.name="TEMP_VIEW" `
    --templateProperty jdbctojdbc.sql.query="TEMP_QUERY"

Windows (cmd.exe)

gcloud dataproc batches submit spark ^
    --class=com.google.cloud.dataproc.templates.main.DataProcTemplate ^
    --project="PROJECT_ID" ^
    --region="REGION" ^
    --version="1.1" ^
    --jars="gs://dataproc-templates-binaries/TEMPLATE_VERSION/java/dataproc-templates.jar,INPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH,OUTPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH" ^
    --subnet="SUBNET" ^
    --kms-key="KMS_KEY" ^
    --service-account="SERVICE_ACCOUNT" ^
    --properties="PROPERTY=PROPERTY_VALUE" ^
    --labels="LABEL=LABEL_VALUE" ^
    -- --template JDBCTOJDBC ^
    --templateProperty project.id="PROJECT_ID" ^
    --templateProperty log.level="LOG_LEVEL" ^
    --templateProperty jdbctojdbc.input.url="INPUT_JDBC_CONNECTION_URL" ^
    --templateProperty jdbctojdbc.input.driver="INPUT_DRIVER" ^
    --templateProperty jdbctojdbc.input.table="INPUT_JDBC_TABLE" ^
    --templateProperty jdbctojdbc.output.url="OUTPUT_JDBC_CONNECTION_URL" ^
    --templateProperty jdbctojdbc.output.driver="OUTPUT_DRIVER" ^
    --templateProperty jdbctojdbc.output.table="OUTPUT_JDBC_TABLE" ^
    --templateProperty jdbctojdbc.input.fetchsize="FETCHSIZE" ^
    --templateProperty jdbctojdbc.input.partitioncolumn="INPUT_PARTITION_COLUMN" ^
    --templateProperty jdbctojdbc.input.lowerbound="LOWERBOUND" ^
    --templateProperty jdbctojdbc.input.upperbound="UPPERBOUND" ^
    --templateProperty jdbctojdbc.numpartitions="NUM_PARTITIONS" ^
    --templateProperty jdbctojdbc.output.mode="MODE" ^
    --templateProperty jdbctojdbc.output.batch.size="BATCH_SIZE" ^
    --templateProperty jdbctojdbc.output.primary.key="PRIMARY_KEY" ^
    --templateProperty jdbctojdbc.output.create.table.option="TABLE_PROPERTIES" ^
    --templateProperty jdbctojdbc.sessioninitstatement="JDBC_SESSION_INIT" ^
    --templateProperty jdbctojdbc.temp.view.name="TEMP_VIEW" ^
    --templateProperty jdbctojdbc.sql.query="TEMP_QUERY"

REST

Bevor Sie die Anfragedaten verwenden, ersetzen Sie die folgenden Werte:

  • 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 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 Sie gsutil ls gs://dataproc-templates-binaries aus, um die verfügbaren Vorlagenversionen aufzulisten.
  • INPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH und OUTPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH: Erforderlich. Der vollständige Cloud Storage-Pfad, einschließlich des Dateinamens, in dem die JDBC-Connector-JAR-Dateien für Ein- und Ausgabe gespeichert sind.

    Hinweis: Wenn die Eingabe- und Ausgabe-JAR-Dateien identisch sind, reicht es aus, nur INPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH festzulegen.

    Mit den folgenden Befehlen können Sie JDBC-Connectors für das Hochladen in Cloud Storage herunterladen:

    • MySQL:
        wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.30.tar.gz
    • PostgreSQL:
        wget https://jdbc.postgresql.org/download/postgresql-42.2.6.jar
    • Microsoft SQL Server:
        wget https://repo1.maven.org/maven2/com/microsoft/sqlserver/mssql-jdbc/6.4.0.jre8/mssql-jdbc-6.4.0.jre8.jar
    • Oracle:
        wget https://repo1.maven.org/maven2/com/oracle/database/jdbc/ojdbc8/21.7.0.0/ojdbc8-21.7.0.0.jar

  • Die folgenden Variablen werden verwendet, um die erforderliche JDBC-Eingabe-URL zu erstellen:
    • INPUT_JDBC_HOST
    • INPUT_JDBC_PORT
    • INPUT_JDBC_DATABASE oder für Oracle INPUT_JDBC_SERVICE
    • INPUT_JDBC_USERNAME
    • INPUT_JDBC_PASSWORD

    Erstellen Sie das INPUT_JDBC_CONNECTION_URL mit einem der folgenden Connector-spezifischen Formate:

    • MySQL:
      jdbc:mysql://INPUT_JDBC_HOST:INPUT_JDBC_PORT/INPUT_JDBC_DATABASE?user=INPUT_JDBC_USERNAME&password=INPUT_JDBC_PASSWORD
    • PostgreSQL:
      jdbc:postgresql://INPUT_JDBC_HOST:INPUT_JDBC_PORT/INPUT_JDBC_DATABASE?user=INPUT_JDBC_USERNAME&password=INPUT_JDBC_PASSWORD
    • Microsoft SQL Server:
      jdbc:sqlserver://INPUT_JDBC_HOST:INPUT_JDBC_PORT;databaseName=INPUT_JDBC_DATABASE;user=INPUT_JDBC_USERNAME;password=INPUT_JDBC_PASSWORD
    • Oracle:
      jdbc:oracle:thin:@//INPUT_JDBC_HOST:INPUT_JDBC_PORT/INPUT_JDBC_SERVICE?user=INPUT_JDBC_USERNAME&password=INPUT_JDBC_PASSWORD
  • Die folgenden Variablen werden verwendet, um die erforderliche JDBC-Ausgabe-URL zu erstellen:
    • OUTPUT_JDBC_HOST
    • OUTPUT_JDBC_PORT
    • OUTPUT_JDBC_DATABASE oder für Oracle OUTPUT_JDBC_SERVICE
    • OUTPUT_JDBC_USERNAME
    • OUTPUT_JDBC_PASSWORD

    Erstellen Sie das OUTPUT_JDBC_CONNECTION_URL mit einem der folgenden Connector-spezifischen Formate:

    • MySQL:
      jdbc:mysql://OUTPUT_JDBC_HOST:OUTPUT_JDBC_PORT/OUTPUT_JDBC_DATABASE?user=OUTPUT_JDBC_USERNAME&password=OUTPUT_JDBC_PASSWORD
    • PostgreSQL:
      jdbc:postgresql://OUTPUT_JDBC_HOST:OUTPUT_JDBC_PORT/OUTPUT_JDBC_DATABASE?user=OUTPUT_JDBC_USERNAME&password=OUTPUT_JDBC_PASSWORD
    • Microsoft SQL Server:
      jdbc:sqlserver://OUTPUT_JDBC_HOST:OUTPUT_JDBC_PORT;databaseName=OUTPUT_JDBC_DATABASE;user=OUTPUT_JDBC_USERNAME;password=OUTPUT_JDBC_PASSWORD
    • Oracle:
      jdbc:oracle:thin:@//OUTPUT_JDBC_HOST:OUTPUT_JDBC_PORT/OUTPUT_JDBC_SERVICE?user=OUTPUT_JDBC_USERNAME&password=OUTPUT_JDBC_PASSWORD
  • INPUT_JDBC_TABLE: erforderlich. JDBC-Eingabetabellenname oder SQL-Abfrage für die JDBC-Eingabetabelle.

    Beispiel (die SQL-Abfrage sollte in Klammern stehen): (select * from TABLE_NAME) as ALIAS_TABLE_NAME

  • OUTPUT_JDBC_TABLE: erforderlich. JDBC-Tabelle, in der die Ausgabe gespeichert wird.
  • INPUT_DRIVER und OUTPUT_DRIVER: Erforderlich. Der JDBC-Eingabe- und -Ausgabetreiber, der für die Verbindung verwendet wird:
    • MySQL:
      com.mysql.cj.jdbc.Driver
    • PostgreSQL:
      org.postgresql.Driver
    • Microsoft SQL Server:
      com.microsoft.sqlserver.jdbc.SQLServerDriver
    • Oracle:
      oracle.jdbc.driver.OracleDriver
  • INPUT_PARTITION_COLUMN, LOWERBOUND, UPPERBOUND, NUM_PARTITIONS: Optional. Bei Verwendung müssen alle der folgenden Parameter angegeben werden:
    • INPUT_PARTITION_COLUMN: Name der JDBC-Eingabetabellenpartitionsspalte.
    • LOWERBOUND: Untergrenze der JDBC-Eingabetabellenpartitionsspalte, die zum Bestimmen des Partitionsschritts verwendet wird.
    • UPPERBOUND: Obergrenze der JDBC-Eingabetabellenpartitionsspalte, die zum Bestimmen des Partitionsschritts verwendet wird.
    • NUM_PARTITIONS: Die maximale Anzahl von Partitionen, die für die Parallelität von Lese- und Schreibvorgängen von Tabellen verwendet werden können. Wenn dieser Wert angegeben ist, wird er für die JDBC-Ein- und -Ausgabeverbindung verwendet.
  • FETCHSIZE: Optional. Die Anzahl der Zeilen, die pro Umlauf abgerufen werden sollen.
  • BATCH_SIZE: Optional. Anzahl der Datensätze, die pro Umlauf eingefügt werden sollen. Standardeinstellung: 1000
  • MODE: Optional. Schreibmodus für JDBC-Ausgabe. Optionen: Append, Overwrite, Ignore oder ErrorIfExists.
  • TABLE_PROPERTIES: Optional. Mit dieser Option können beim Erstellen der Ausgabetabelle datenbankspezifische Tabellen- und Partitionsoptionen festgelegt werden.
  • PRIMARY_KEY: Optional. Primärschlüsselspalte für die Ausgabetabelle. Die genannte Spalte darf keine doppelten Werte enthalten, da andernfalls ein Fehler ausgegeben wird.
  • JDBC_SESSION_INIT: Optional. Anweisung zur Sitzungsinitialisierung zum Lesen von Java-Vorlagen.
  • LOG_LEVEL: Optional. Protokollebene. Kann ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE oder WARN sein. Standardeinstellung: INFO.
  • TEMP_VIEW und TEMP_QUERY: Optional. Mit diesen beiden optionalen Parametern können Sie beim Laden von Daten in Cloud Storage eine Spark SQL-Transformation anwenden. TEMP_VIEW muss mit dem in der Abfrage verwendeten Tabellennamen übereinstimmen und TEMP_QUERY ist die Abfrageanweisung.
  • SERVICE_ACCOUNT: Optional. Wenn nicht angegeben, wird das Compute Engine-Standarddienstkonto verwendet.
  • PROPERTY und PROPERTY_VALUE: Optional. Durch Kommas getrennte Liste von Spark property=value-Paaren.
  • LABEL und LABEL_VALUE: Optional. Durch Kommas getrennte Liste von label=value-Paaren.
  • 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 von Google verwalteten Schlüssel im inaktiven Zustand 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 der Anfrage:


{
  "environmentConfig": {
    "executionConfig": {
      "subnetworkUri": "SUBNET",
      "kmsKey": "KMS_KEY",
      "serviceAccount": "SERVICE_ACCOUNT"
    }
  },
  "labels": {
    "LABEL": "LABEL_VALUE"
  },
  "runtimeConfig": {
    "version": "1.1",
    "properties": {
      "PROPERTY": "PROPERTY_VALUE"
    }
  },
  "sparkBatch": {
    "mainClass": "com.google.cloud.dataproc.templates.main.DataProcTemplate",
    "args": [
      "--template","JDBCTOJDBC",
      "--templateProperty","log.level=LOG_LEVEL",
      "--templateProperty","project.id=PROJECT_ID",
      "--templateProperty","jdbctojdbc.input.url=INPUT_JDBC_CONNECTION_URL",
      "--templateProperty","jdbctojdbc.input.driver=INPUT_DRIVER",
      "--templateProperty","jdbctojdbc.input.table=INPUT_TABLE",
      "--templateProperty","jdbctojdbc.output.url=OUTPUT_JDBC_CONNECTION_URL",
      "--templateProperty","jdbctojdbc.output.driver=OUTPUT_DRIVER",
      "--templateProperty","jdbctojdbc.output.table=OUTPUT_TABLE",
      "--templateProperty","jdbctojdbc.input.fetchsize=FETCHSIZE",
      "--templateProperty","jdbctojdbc.input.partitioncolumn=INPUT_PARTITION_COLUMN",
      "--templateProperty","jdbctojdbc.input.lowerbound=LOWERBOUND",
      "--templateProperty","jdbctojdbc.input.upperbound=UPPERBOUND",
      "--templateProperty","jdbctojdbc.numpartitions=NUM_PARTITIONS",
      "--templateProperty","jdbctojdbc.output.mode=MODE",
      "--templateProperty","jdbctojdbc.output.batch.size=BATCH_SIZE",
      "--templateProperty","jdbctojdbc.output.primary.key=PRIMARY_KEY",
      "--templateProperty","jdbctojdbc.output.create.table.option=TABLE_PROPERTIES",
      "--templateProperty","jdbctojdbc.sessioninitstatement=JDBC_SESSION_INIT",
      "--templateProperty","jdbctojdbc.temp.view.name=TEMP_VIEW",
      "--templateProperty","jdbctojdbc.sql.query=TEMP_QUERY"
    ],
    "jarFileUris": [
      "gs://dataproc-templates-binaries/TEMPLATE_VERSION/java/dataproc-templates.jar",
      "INPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH",
      "OUTPUT_JDBC_CONNECTOR_CLOUD_STORAGE_PATH"
    ]
  }
}

Wenn Sie die Anfrage senden möchten, maximieren Sie eine der folgenden Optionen:

Sie sollten in etwa folgende JSON-Antwort 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"
  }
}