BigQuery-Datasets und -Tabellen vorbereiten

Zum Erstellen von AML AI-Datasets in einer Instanz müssen Sie Daten in BigQuery in diesem Google Cloud-Projekt bereitstellen. In den folgenden Abschnitten wird eine Möglichkeit gezeigt, diese Datasets und Tabellen vorzubereiten.

BigQuery-Ausgabe-Dataset erstellen

Führen Sie den folgenden Befehl aus, um ein Dataset zu erstellen, mit dem die Pipelineausgaben an BigQuery gesendet werden. Wählen Sie im folgenden Befehl einen Namen für BQ_OUTPUT_DATASET_NAME aus, der nur Buchstaben (Groß- oder Kleinbuchstaben), Ziffern und Unterstriche enthält. Sie dürfen keine Bindestriche verwenden.

bq mk \
  --location=LOCATION \
  --project_id=PROJECT_ID \
  BQ_OUTPUT_DATASET_NAME

Informationen zum Ansehen der AML AI-Ausgaben finden Sie unter AML-Ausgabedatenmodell.

BigQuery-Eingabe-Dataset erstellen

Erstellen Sie ein BigQuery-Eingabe-Dataset. Später geben Sie die Transaktionsdaten Ihres Finanzinstituts in dieses Dataset ein.

bq mk \
  --location=LOCATION \
  --project_id=PROJECT_ID \
  BQ_INPUT_DATASET_NAME

BigQuery-Eingabe-Dataset-Tabellen erstellen und Transaktionsdaten hochladen

Wir stellen das Schema für das AML-Eingabedatenmodell in den folgenden Formaten zur Verfügung:

Führen Sie den folgenden Befehl aus, um die JSON-Datei für jede Tabelle herunterzuladen und zum Erstellen der zugehörigen BigQuery-Tabelle durch Anwenden des Schemas zu verwenden.

for table in party account_party_link transaction risk_case_event party_supplementary_data
do
  curl -O "https://cloud.google.com/financial-services/anti-money-laundering/docs/reference/schemas/${table}.json"
  bq mk --table --project_id PROJECT_ID BQ_INPUT_DATASET_NAME.$table $table.json
done

Laden Sie die Transaktionsdaten Ihres Finanzinstituts in die Dataset-Tabellen hoch. Weitere Informationen finden Sie in den BigQuery-Kurzanleitungen.

Zugriff auf BigQuery-Datasets gewähren

Die API erstellt automatisch ein Dienstkonto in Ihrem Projekt. Das Dienstkonto benötigt Zugriff auf die BigQuery-Eingabe- und -Ausgabe-Datasets.

  1. Installieren Sie jq auf Ihrem Entwicklungscomputer. Wenn Sie jq nicht auf Ihrem Entwicklungscomputer installieren können, können Sie Cloud Shell oder eine der anderen Methoden verwenden, um Zugriff auf eine Ressource aus der BigQuery-Dokumentation zu gewähren.
  2. Führen Sie die folgenden Befehle aus, um Lesezugriff auf das Eingabe-Dataset und seine Tabellen zu gewähren.

    # The BigQuery input dataset name. You created this dataset and
    # uploaded the financial data into it in a previous step. This dataset should be
    # stored in the Google Cloud project.
    
    export BQ_INPUT_DATASET_NAME="BQ_INPUT_DATASET_NAME"
    
    # The BigQuery tables in the input dataset. These tables should
    # be part of the same project as the intended instance.
    # Make sure to replace each table variable with the appropriate table name.
    export PARTY_TABLE="PARTY_TABLE"
    export ACCOUNT_PARTY_LINK_TABLE="ACCOUNT_PARTY_LINK_TABLE"
    export TRANSACTION_TABLE="TRANSACTION_TABLE"
    export RISK_CASE_EVENT_TABLE="RISK_CASE_EVENT_TABLE"
    # Optional table
    export PARTY_SUPPLEMENTARY_DATA_TABLE="PARTY_SUPPLEMENTARY_DATA_TABLE"
    
    # Grant the API read access to the BigQuery dataset.
    # Update the current access permissions on the BigQuery dataset and store in a temp file.
    # Note: This step requires jq as a dependency.
    # If jq is not available, the file /tmp/mydataset.json may be created manually.
    bq show --format=prettyjson "PROJECT_ID:BQ_INPUT_DATASET_NAME" | jq '.access+=[{"role":"READER","userByEmail":"service-PROJECT_NUMBER@gcp-sa-financialservices.iam.gserviceaccount.com" }]'> /tmp/mydataset.json
    # Update the BigQuery dataset access permissions using the temp file.
    bq update --source /tmp/mydataset.json "PROJECT_ID:BQ_INPUT_DATASET_NAME"
    
    # Grant the API read access to the BigQuery table if the table is provided.
    for TABLE in $PARTY_TABLE $TRANSACTION_TABLE $ACCOUNT_PARTY_LINK_TABLE $RISK_CASE_EVENT_TABLE $PARTY_SUPPLEMENTARY_DATA_TABLE ; do
      [ -n TABLE ] && bq add-iam-policy-binding \
        --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-financialservices.iam.gserviceaccount.com" --role="roles/bigquery.dataViewer" \
        PROJECT_ID:BQ_INPUT_DATASET_NAME.${TABLE}
    done
    
  3. Führen Sie die folgenden Befehle aus, um Schreibzugriff auf das Ausgabe-Dataset zu gewähren.

    # Note: This step requires jq as a dependency.
    # If jq isn't available, the file /tmp/mydataset.json may be created manually.
    bq show --format=prettyjson PROJECT_ID:BQ_OUTPUT_DATASET_NAME | jq '.access+=[{"role":"roles/bigquery.dataEditor","userByEmail":"service-PROJECT_NUMBER@gcp-sa-financialservices.iam.gserviceaccount.com" }]'> /tmp/perms.json
    
    bq update --source /tmp/perms.json PROJECT_ID:BQ_OUTPUT_DATASET_NAME