0

I just wonder if there's any way to check if the target table is being written data or it's safe to make query and read data from it. Something like table status (unreadable, dirty, clean, etc) would be great.

I tried to use api and get job configuration, but it does not show all the jobs, and this approach is not quite good since each time I need to list all jobs for the whole project and then do filtering to find the one I need. Furthermore, get destination table by downcasting to LoadJobConfiguration type will give null pointer exception...

Here's my codes using api:

  BigQuery bigquery = BigQueryOptions.newBuilder()
      .setProjectId(projectId)
      .build().getService();

  Page<Job> jobs = bigquery.listJobs(BigQuery.JobListOption.allUsers().);
  if (jobs == null) {
    System.out.println("Dataset does not contain any jobs.");
    return;
  }

  jobs.getValues().forEach( job -> {
    JobConfiguration jobConfiguration = job.getConfiguration();
    if (jobConfiguration.getType().equals(JobConfiguration.Type.LOAD)) {
      if (((LoadJobConfiguration) jobConfiguration)
          .getDestinationTable().equals(TableId.of(datasetName, tableName))) {
        if (job.isDone()) {
          System.out.println("Load Job with id " + job.getJobId() + " is done.");
        } else {
          System.out.println("Load Job with id " + job.getJobId() + " is processing.");
        }
      }
    }
  });
Vincent Y
  • 109
  • 6

0 Answers0