Preparare i set di dati e le tabelle BigQuery

Per creare set di dati AML AI in un'istanza, devi organizzare i dati in BigQuery all'interno del progetto Google Cloud. Le seguenti sezioni mostrano un modo per preparare questi set di dati e tabelle.

crea un set di dati di output BigQuery

Esegui questo comando per creare un set di dati da utilizzare utilizzato per inviare gli output della pipeline a BigQuery. Nel seguente , seleziona un nome per BQ_OUTPUT_DATASET_NAME che contenga solo lettere (maiuscole o minuscole), numeri e trattini bassi. Non puoi utilizzare trattini.

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

Per vedere gli output di AML AI, consulta la sezione Modello dei dati di output di AML.

crea il set di dati di input BigQuery

Creare un set di dati di input BigQuery. In seguito, inserirai il i dati sulle transazioni dell'istituto finanziario in questo set di dati.

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

crea le tabelle del set di dati di input BigQuery e carica i dati delle transazioni

Forniamo lo schema del modello dei dati di input AML nei seguenti formati:

Forniamo i tabella di registrazione del gruppo in formato JSON. Utilizzerai questa tabella in seguito, quando registri le parti per per creare i risultati delle previsioni.

Per scaricare il file JSON per ogni tabella e utilizzarlo per creare i campi associati Applicando lo schema alla tabella BigQuery, esegui questo comando: .

for table in party_registration 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

Carica i dati sulle transazioni del tuo istituto finanziario nelle tabelle del set di dati. Per ulteriori informazioni, consulta le Guide rapide su BigQuery.

Concedi l'accesso ai set di dati BigQuery

L'API crea automaticamente un account di servizio nel progetto. Il servizio deve poter accedere ai set di dati di input e output di BigQuery.

Per PROJECT_NUMBER, usa il numero di progetto associato a PROJECT_ID. Puoi trovare il progetto nella pagina Impostazioni IAM.

  1. Installa jq sul tuo di sviluppo software. Se non riesci a installare jq sul tuo computer di sviluppo, puoi usare Cloud Shell o uno degli altri metodi per concedere l'accesso a una risorsa disponibili nella documentazione di BigQuery.
  2. Esegui questi comandi per concedere l'accesso in lettura al set di dati di input e ai relativi tabelle.

    # 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"
    # Registered parties table
    export PARTY_REGISTRATION_TABLE="PARTY_REGISTRATION_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 $PARTY_REGISTRATION_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. Esegui questi comandi per concedere l'accesso in scrittura al set di dati di output.

    # 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