79206804

Date: 2024-11-20 10:36:05
Score: 0.5
Natty:
Report link

A good practice would be to have a control over the jobs you launch. I mean, you can generate unique IDs for the jobs and then you can check their status and what to do with them. Practical example in python: I want to load data from a csv. I create a unique job_id using the hashlib library

import hashlib
file_name = ‘data.csv’
job_id = hashlib.sha256(file_name.encode()).hexdigest()

Next, I'll launch the job

from google.cloud import bigquery

client = bigquery.Client()
job_config = bigquery.LoadJobConfig(...)
uri = ‘gs://your_bucket/data.csv’

job = client.load_table_from_uri(
    uri,
    ‘your_dataset.your_table’,
    job_config=job_config,
    job_id=job_id
)

If I want to check what state it is in, I can use the following command from the bq console (https://cloud.google.com/bigquery/docs/reference/bq-cli-reference?hl=es-419#bq_show):

bq show --job <PROJECT_ID>:<JOB_ID>

With this we will verify in which state is the job and therefore, if you want to run it again or wait for it to finish (with error or not) so you don't get the duplicity you are talking about.

I hope this is useful for you!

Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: var0hub