ForwardingBigQueryFileOutputFormat extends OutputFormat<K, V> { @Override public void checkOutputSpecs(JobContext job) throws FileAlreadyExistsException, IOException { Configuration conf = job.getConfiguration(); BigQueryOutputConfiguration.validateConfiguration(conf); Path outputPath = BigQueryOutputConfiguration.getGcsOutputPath(conf); logger.atInfo().log("Using output path '%s'.", outputPath); FileSystem outputFileSystem = outputPath.getFileSystem(conf); if (outputFileSystem.exists(outputPath)) { throw new IOException("The output path '" + outputPath + "' already exists."); } if (FileOutputFormat.getCompressOutput(job)) { throw new IOException("Compression isn't supported for this OutputFormat."); } try { new BigQueryFactory().getBigQueryHelper(conf); } catch (GeneralSecurityException gse) { throw new IOException("Failed to create BigQuery client", gse); } getDelegate(conf).checkOutputSpecs(job); }  @Override void checkOutputSpecs(JobContext job); @Override synchronized OutputCommitter getOutputCommitter(TaskAttemptContext context); @Override RecordWriter<K, V> getRecordWriter(TaskAttemptContext context);  }
@Test public void testCheckOutputSpecs() throws IOException { outputFormat.checkOutputSpecs(mockTaskAttemptContext); verify(mockFileOutputFormat).checkOutputSpecs(eq(mockTaskAttemptContext)); }
@Test public void testCheckOutputSpecsAlreadyExists() throws IOException { ghfs.mkdirs(TEST_OUTPUT_PATH); IOException thrown = assertThrows( IOException.class, () -> outputFormat.checkOutputSpecs(mockTaskAttemptContext)); assertThat(thrown) .hasMessageThat() .contains("The output path '" + TEST_OUTPUT_PATH + "' already exists."); }
@Test public void testCheckOutputSpecsCompressedOutput() throws IOException { FileOutputFormat.setCompressOutput(job, true); IOException thrown = assertThrows( IOException.class, () -> outputFormat.checkOutputSpecs(mockTaskAttemptContext)); assertThat(thrown) .hasMessageThat() .contains("Compression isn't supported for this OutputFormat."); }