test_class.declarator: mockBigquery
test_class.modifier: @Mock private
test_class.original_string: @Mock private Bigquery mockBigquery;
test_class.type: Bigquery
test_class.var_name: mockBigquery
test_class.declarator: mockBigqueryJobs
test_class.modifier: @Mock private
test_class.original_string: @Mock private Bigquery.Jobs mockBigqueryJobs;
test_class.type: Bigquery.Jobs
test_class.var_name: mockBigqueryJobs
test_class.declarator: mockBigqueryJobsGet
test_class.modifier: @Mock private
test_class.original_string: @Mock private Bigquery.Jobs.Get mockBigqueryJobsGet;
test_class.type: Bigquery.Jobs.Get
test_class.var_name: mockBigqueryJobsGet
test_class.declarator: mockBigqueryJobsInsert
test_class.modifier: @Mock private
test_class.original_string: @Mock private Bigquery.Jobs.Insert mockBigqueryJobsInsert;
test_class.type: Bigquery.Jobs.Insert
test_class.var_name: mockBigqueryJobsInsert
test_class.declarator: mockBigqueryTables
test_class.modifier: @Mock private
test_class.original_string: @Mock private Bigquery.Tables mockBigqueryTables;
test_class.type: Bigquery.Tables
test_class.var_name: mockBigqueryTables
test_class.declarator: mockBigqueryTablesGet
test_class.modifier: @Mock private
test_class.original_string: @Mock private Bigquery.Tables.Get mockBigqueryTablesGet;
test_class.type: Bigquery.Tables.Get
test_class.var_name: mockBigqueryTablesGet
test_class.declarator: mockErrorExtractor
test_class.modifier: @Mock private
test_class.original_string: @Mock private ApiErrorExtractor mockErrorExtractor;
test_class.type: ApiErrorExtractor
test_class.var_name: mockErrorExtractor
test_class.declarator: jobStatus
test_class.modifier: private
test_class.original_string: private JobStatus jobStatus;
test_class.type: JobStatus
test_class.var_name: jobStatus
test_class.declarator: jobHandle
test_class.modifier: private
test_class.original_string: private Job jobHandle;
test_class.type: Job
test_class.var_name: jobHandle
test_class.declarator: fakeTable
test_class.modifier: private
test_class.original_string: private Table fakeTable;
test_class.type: Table
test_class.var_name: fakeTable
test_class.declarator: fakeTableSchema
test_class.modifier: private
test_class.original_string: private TableSchema fakeTableSchema;
test_class.type: TableSchema
test_class.var_name: fakeTableSchema
test_class.declarator: jobProjectId = "google.com:foo-project"
test_class.modifier: private
test_class.original_string: private String jobProjectId = "google.com:foo-project";
test_class.type: String
test_class.var_name: jobProjectId
test_class.declarator: kmsKeyName =
        "projects/google.com:foo-project/locations/us-west1/keyRings/ring-1/cryptoKeys/key-1"
test_class.modifier: private final
test_class.original_string: private final String kmsKeyName =
        "projects/google.com:foo-project/locations/us-west1/keyRings/ring-1/cryptoKeys/key-1";
test_class.type: String
test_class.var_name: kmsKeyName
test_class.declarator: tableRef
test_class.modifier: private
test_class.original_string: private TableReference tableRef;
test_class.type: TableReference
test_class.var_name: tableRef
test_class.declarator: projectId = "google.com:bar-project"
test_class.modifier: private
test_class.original_string: private String projectId = "google.com:bar-project";
test_class.type: String
test_class.var_name: projectId
test_class.declarator: datasetId = "test_dataset"
test_class.modifier: private
test_class.original_string: private String datasetId = "test_dataset";
test_class.type: String
test_class.var_name: datasetId
test_class.declarator: tableId = "test_table"
test_class.modifier: private
test_class.original_string: private String tableId = "test_table";
test_class.type: String
test_class.var_name: tableId
test_class.declarator: jobId = "bigquery-job-1234"
test_class.modifier: private
test_class.original_string: private String jobId = "bigquery-job-1234";
test_class.type: String
test_class.var_name: jobId
test_class.declarator: helper
test_class.modifier: private
test_class.original_string: private BigQueryHelper helper;
test_class.type: BigQueryHelper
test_class.var_name: helper
test_class.file: bigquery/src/test/java/com/google/cloud/hadoop/io/bigquery/BigQueryHelperTest.java
test_class.identifier: BigQueryHelperTest
test_case.body: @Test
    public void testInsertJobOrFetchDuplicateAlreadyExistsException() throws IOException {
      IOException fakeConflictException = new IOException("fake 409 conflict");
      when(mockBigqueryJobsInsert.execute()).thenThrow(fakeConflictException);
      when(mockErrorExtractor.itemAlreadyExists(any(IOException.class))).thenReturn(true);
      when(mockBigqueryJobsGet.execute()).thenReturn(jobHandle);
  
      assertThat(helper.insertJobOrFetchDuplicate(jobProjectId, jobHandle)).isEqualTo(jobHandle);
  
      verify(mockBigquery, times(2)).jobs();
      ArgumentCaptor<Job> jobCaptor = ArgumentCaptor.forClass(Job.class);
      verify(mockBigqueryJobs, times(1)).insert(eq(jobProjectId), jobCaptor.capture());
      Job job = jobCaptor.getValue();
      assertThat(job).isEqualTo(jobHandle);
      verify(mockBigqueryJobsInsert, times(1)).execute();
      verify(mockBigqueryJobs, times(1)).get(eq(jobProjectId), eq(jobId));
      verify(mockBigqueryJobsGet, times(1)).setLocation(eq(null));
      verify(mockBigqueryJobsGet, times(1)).execute();
      verify(mockErrorExtractor).itemAlreadyExists(eq(fakeConflictException));
    }
test_case.class_method_signature: BigQueryHelperTest.testInsertJobOrFetchDuplicateAlreadyExistsException()
test_case.full_signature: @Test public void testInsertJobOrFetchDuplicateAlreadyExistsException()
test_case.identifier: testInsertJobOrFetchDuplicateAlreadyExistsException
test_case.invocations: thenThrow when execute thenReturn when itemAlreadyExists any thenReturn when execute isEqualTo assertThat insertJobOrFetchDuplicate jobs verify times forClass insert verify times eq capture getValue isEqualTo assertThat execute verify times get verify times eq eq setLocation verify times eq execute verify times itemAlreadyExists verify eq
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testInsertJobOrFetchDuplicateAlreadyExistsException()
focal_class.declarator: BIGQUERY_JOB_ID_PATTERN = "[a-zA-Z0-9_-]+"
focal_class.modifier: public static final
focal_class.original_string: public static final String BIGQUERY_JOB_ID_PATTERN = "[a-zA-Z0-9_-]+";
focal_class.type: String
focal_class.var_name: BIGQUERY_JOB_ID_PATTERN
focal_class.declarator: BIGQUERY_JOB_ID_MAX_LENGTH = 1024
focal_class.modifier: public static final
focal_class.original_string: public static final int BIGQUERY_JOB_ID_MAX_LENGTH = 1024;
focal_class.type: int
focal_class.var_name: BIGQUERY_JOB_ID_MAX_LENGTH
focal_class.declarator: logger = GoogleLogger.forEnclosingClass()
focal_class.modifier: private static final
focal_class.original_string: private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
focal_class.type: GoogleLogger
focal_class.var_name: logger
focal_class.declarator: errorExtractor = ApiErrorExtractor.INSTANCE
focal_class.modifier: private
focal_class.original_string: private ApiErrorExtractor errorExtractor = ApiErrorExtractor.INSTANCE;
focal_class.type: ApiErrorExtractor
focal_class.var_name: errorExtractor
focal_class.declarator: service
focal_class.modifier: private
focal_class.original_string: private Bigquery service;
focal_class.type: Bigquery
focal_class.var_name: service
focal_class.file: bigquery/src/main/java/com/google/cloud/hadoop/io/bigquery/BigQueryHelper.java
focal_class.identifier: BigQueryHelper
focal_class.class_method_signature: BigQueryHelper.BigQueryHelper(Bigquery service)
focal_class.full_signature: public  BigQueryHelper(Bigquery service)
focal_class.identifier: BigQueryHelper
focal_class.modifiers: public
focal_class.parameters: (Bigquery service)
focal_class.signature:  BigQueryHelper(Bigquery service)
focal_class.class_method_signature: BigQueryHelper.getRawBigquery()
focal_class.full_signature: public Bigquery getRawBigquery()
focal_class.identifier: getRawBigquery
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Bigquery
focal_class.signature: Bigquery getRawBigquery()
focal_class.class_method_signature: BigQueryHelper.importFederatedFromGcs(
        String projectId,
        TableReference tableRef,
        @Nullable TableSchema schema,
        BigQueryFileFormat sourceFormat,
        List<String> gcsPaths)
focal_class.full_signature: public void importFederatedFromGcs(
        String projectId,
        TableReference tableRef,
        @Nullable TableSchema schema,
        BigQueryFileFormat sourceFormat,
        List<String> gcsPaths)
focal_class.identifier: importFederatedFromGcs
focal_class.modifiers: public
focal_class.parameters: (
        String projectId,
        TableReference tableRef,
        @Nullable TableSchema schema,
        BigQueryFileFormat sourceFormat,
        List<String> gcsPaths)
focal_class.return: void
focal_class.signature: void importFederatedFromGcs(
        String projectId,
        TableReference tableRef,
        @Nullable TableSchema schema,
        BigQueryFileFormat sourceFormat,
        List<String> gcsPaths)
focal_class.class_method_signature: BigQueryHelper.importFromGcs(
        String projectId,
        TableReference tableRef,
        @Nullable TableSchema schema,
        @Nullable TimePartitioning timePartitioning,
        @Nullable String kmsKeyName,
        BigQueryFileFormat sourceFormat,
        String createDisposition,
        String writeDisposition,
        List<String> gcsPaths,
        boolean awaitCompletion)
focal_class.full_signature: public void importFromGcs(
        String projectId,
        TableReference tableRef,
        @Nullable TableSchema schema,
        @Nullable TimePartitioning timePartitioning,
        @Nullable String kmsKeyName,
        BigQueryFileFormat sourceFormat,
        String createDisposition,
        String writeDisposition,
        List<String> gcsPaths,
        boolean awaitCompletion)
focal_class.identifier: importFromGcs
focal_class.modifiers: public
focal_class.parameters: (
        String projectId,
        TableReference tableRef,
        @Nullable TableSchema schema,
        @Nullable TimePartitioning timePartitioning,
        @Nullable String kmsKeyName,
        BigQueryFileFormat sourceFormat,
        String createDisposition,
        String writeDisposition,
        List<String> gcsPaths,
        boolean awaitCompletion)
focal_class.return: void
focal_class.signature: void importFromGcs(
        String projectId,
        TableReference tableRef,
        @Nullable TableSchema schema,
        @Nullable TimePartitioning timePartitioning,
        @Nullable String kmsKeyName,
        BigQueryFileFormat sourceFormat,
        String createDisposition,
        String writeDisposition,
        List<String> gcsPaths,
        boolean awaitCompletion)
focal_class.class_method_signature: BigQueryHelper.exportBigQueryToGcs(
        String projectId, TableReference tableRef, List<String> gcsPaths, boolean awaitCompletion)
focal_class.full_signature: public void exportBigQueryToGcs(
        String projectId, TableReference tableRef, List<String> gcsPaths, boolean awaitCompletion)
focal_class.identifier: exportBigQueryToGcs
focal_class.modifiers: public
focal_class.parameters: (
        String projectId, TableReference tableRef, List<String> gcsPaths, boolean awaitCompletion)
focal_class.return: void
focal_class.signature: void exportBigQueryToGcs(
        String projectId, TableReference tableRef, List<String> gcsPaths, boolean awaitCompletion)
focal_class.class_method_signature: BigQueryHelper.tableExists(TableReference tableRef)
focal_class.full_signature: public boolean tableExists(TableReference tableRef)
focal_class.identifier: tableExists
focal_class.modifiers: public
focal_class.parameters: (TableReference tableRef)
focal_class.return: boolean
focal_class.signature: boolean tableExists(TableReference tableRef)
focal_class.class_method_signature: BigQueryHelper.getTable(TableReference tableRef)
focal_class.full_signature: public Table getTable(TableReference tableRef)
focal_class.identifier: getTable
focal_class.modifiers: public
focal_class.parameters: (TableReference tableRef)
focal_class.return: Table
focal_class.signature: Table getTable(TableReference tableRef)
focal_class.class_method_signature: BigQueryHelper.createJobReference(
        String projectId, String jobIdPrefix, @Nullable String location)
focal_class.full_signature: public JobReference createJobReference(
        String projectId, String jobIdPrefix, @Nullable String location)
focal_class.identifier: createJobReference
focal_class.modifiers: public
focal_class.parameters: (
        String projectId, String jobIdPrefix, @Nullable String location)
focal_class.return: JobReference
focal_class.signature: JobReference createJobReference(
        String projectId, String jobIdPrefix, @Nullable String location)
focal_class.class_method_signature: BigQueryHelper.checkJobIdEquality(Job expected, Job actual)
focal_class.full_signature: public void checkJobIdEquality(Job expected, Job actual)
focal_class.identifier: checkJobIdEquality
focal_class.modifiers: public
focal_class.parameters: (Job expected, Job actual)
focal_class.return: void
focal_class.signature: void checkJobIdEquality(Job expected, Job actual)
focal_class.class_method_signature: BigQueryHelper.insertJobOrFetchDuplicate(String projectId, Job job)
focal_class.full_signature: public Job insertJobOrFetchDuplicate(String projectId, Job job)
focal_class.identifier: insertJobOrFetchDuplicate
focal_class.modifiers: public
focal_class.parameters: (String projectId, Job job)
focal_class.return: Job
focal_class.signature: Job insertJobOrFetchDuplicate(String projectId, Job job)
focal_class.class_method_signature: BigQueryHelper.setErrorExtractor(ApiErrorExtractor errorExtractor)
focal_class.full_signature: @VisibleForTesting void setErrorExtractor(ApiErrorExtractor errorExtractor)
focal_class.identifier: setErrorExtractor
focal_class.modifiers: @VisibleForTesting
focal_class.parameters: (ApiErrorExtractor errorExtractor)
focal_class.return: void
focal_class.signature: void setErrorExtractor(ApiErrorExtractor errorExtractor)
focal_method.body: public Job insertJobOrFetchDuplicate(String projectId, Job job) throws IOException {
      checkArgument(
          job.getJobReference() != null && job.getJobReference().getJobId() != null,
          "Require non-null JobReference and JobId inside; getJobReference() == '%s'",
          job.getJobReference());
      Job response;
      try {
        response = service.jobs().insert(projectId, job).execute();
        logger.atFine().log("Successfully inserted job '%s'. Response: '%s'", job, response);
      } catch (IOException insertJobException) {
        if (errorExtractor.itemAlreadyExists(insertJobException)) {
          logger.atInfo().withCause(insertJobException).log(
              "Fetching existing job after catching exception for duplicate jobId '%s'",
              job.getJobReference().getJobId());
          try {
            response =
                service
                    .jobs()
                    .get(projectId, job.getJobReference().getJobId())
                    .setLocation(job.getJobReference().getLocation())
                    .execute();
          } catch (IOException getJobException) {
            getJobException.addSuppressed(insertJobException);
            throw new IOException(
                String.format("Failed to get duplicate job '%s'", job), getJobException);
          }
        } else {
          throw new IOException(
              String.format("Unhandled exception trying to insert job '%s'", job),
              insertJobException);
        }
      }
      checkJobIdEquality(job, response);
      return response;
    }
focal_method.class_method_signature: BigQueryHelper.insertJobOrFetchDuplicate(String projectId, Job job)
focal_method.full_signature: public Job insertJobOrFetchDuplicate(String projectId, Job job)
focal_method.identifier: insertJobOrFetchDuplicate
focal_method.invocations: checkArgument getJobReference getJobId getJobReference getJobReference execute insert jobs log atFine itemAlreadyExists log withCause atInfo getJobId getJobReference execute setLocation get jobs getJobId getJobReference getLocation getJobReference addSuppressed format format checkJobIdEquality
focal_method.modifiers: public
focal_method.parameters: (String projectId, Job job)
focal_method.return: Job
focal_method.signature: Job insertJobOrFetchDuplicate(String projectId, Job job)