/** Creates a builder for a BigQuery Load Configuration given the destination table and format. */ public static Builder newBuilder(TableId destinationTable, FormatOptions format) { return newBuilder(destinationTable).setFormatOptions(format); }
@Test public void testSetProjectIdDoNotOverride() { WriteChannelConfiguration configuration = WriteChannelConfiguration.of(TABLE_ID).setProjectId("project"); configuration.setProjectId("different-project").toBuilder(); assertEquals("project", configuration.getDestinationTable().getProject()); }
WriteChannelConfiguration setProjectId(String projectId) { if (Strings.isNullOrEmpty(getDestinationTable().getProject())) { return toBuilder().setDestinationTable(getDestinationTable().setProjectId(projectId)).build(); } return this; }
@Test public void testOf() { WriteChannelConfiguration configuration = WriteChannelConfiguration.of(TABLE_ID); assertEquals(TABLE_ID, configuration.getDestinationTable()); configuration = WriteChannelConfiguration.of(TABLE_ID, CSV_OPTIONS); assertEquals(TABLE_ID, configuration.getDestinationTable()); assertEquals(FORMAT, configuration.getFormat()); assertEquals(CSV_OPTIONS, configuration.getCsvOptions()); }
private void compareLoadConfiguration( WriteChannelConfiguration expected, WriteChannelConfiguration value) { assertEquals(expected, value); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); assertEquals(expected.getDestinationTable(), value.getDestinationTable()); assertEquals(expected.getCreateDisposition(), value.getCreateDisposition()); assertEquals(expected.getWriteDisposition(), value.getWriteDisposition()); assertEquals(expected.getNullMarker(), value.getNullMarker()); assertEquals(expected.getCsvOptions(), value.getCsvOptions()); assertEquals(expected.getFormat(), value.getFormat()); assertEquals(expected.ignoreUnknownValues(), value.ignoreUnknownValues()); assertEquals(expected.getMaxBadRecords(), value.getMaxBadRecords()); assertEquals(expected.getDatastoreBackupOptions(), value.getDatastoreBackupOptions()); assertEquals(expected.getSchema(), value.getSchema()); assertEquals(expected.getSchemaUpdateOptions(), value.getSchemaUpdateOptions()); assertEquals(expected.getAutodetect(), value.getAutodetect()); assertEquals(expected.getTimePartitioning(), value.getTimePartitioning()); assertEquals(expected.getClustering(), value.getClustering()); } }
@Test public void testBuilder() { assertEquals(TABLE_ID, LOAD_CONFIGURATION_CSV.getDestinationTable()); assertEquals(CREATE_DISPOSITION, LOAD_CONFIGURATION_CSV.getCreateDisposition()); assertEquals(WRITE_DISPOSITION, LOAD_CONFIGURATION_CSV.getWriteDisposition()); assertEquals(NULL_MARKER, LOAD_CONFIGURATION_CSV.getNullMarker()); assertEquals(CSV_OPTIONS, LOAD_CONFIGURATION_CSV.getCsvOptions()); assertEquals(FORMAT, LOAD_CONFIGURATION_CSV.getFormat()); assertEquals(IGNORE_UNKNOWN_VALUES, LOAD_CONFIGURATION_CSV.ignoreUnknownValues()); assertEquals(MAX_BAD_RECORDS, LOAD_CONFIGURATION_CSV.getMaxBadRecords()); assertEquals(TABLE_SCHEMA, LOAD_CONFIGURATION_CSV.getSchema()); assertEquals(BACKUP_OPTIONS, LOAD_CONFIGURATION_BACKUP.getDatastoreBackupOptions()); assertEquals(SCHEMA_UPDATE_OPTIONS, LOAD_CONFIGURATION_CSV.getSchemaUpdateOptions()); assertEquals(SCHEMA_UPDATE_OPTIONS, LOAD_CONFIGURATION_BACKUP.getSchemaUpdateOptions()); WriteChannelConfiguration.Builder builder = WriteChannelConfiguration.newBuilder(TABLE_ID, CSV_OPTIONS) .setCreateDisposition(CREATE_DISPOSITION) .setWriteDisposition(WRITE_DISPOSITION) .setAutodetect(AUTODETECT); WriteChannelConfiguration loadConfigurationCSV = builder.build(); assertEquals(TABLE_ID, loadConfigurationCSV.getDestinationTable()); assertEquals(CREATE_DISPOSITION, loadConfigurationCSV.getCreateDisposition()); assertEquals(WRITE_DISPOSITION, loadConfigurationCSV.getWriteDisposition()); assertEquals(NULL_MARKER, loadConfigurationCSV.getNullMarker()); assertEquals(CSV_OPTIONS, loadConfigurationCSV.getCsvOptions()); assertEquals(FORMAT, loadConfigurationCSV.getFormat()); assertEquals(IGNORE_UNKNOWN_VALUES, loadConfigurationCSV.ignoreUnknownValues()); assertEquals(MAX_BAD_RECORDS, loadConfigurationCSV.getMaxBadRecords()); assertEquals(TABLE_SCHEMA, loadConfigurationCSV.getSchema());
@Test public void testToPbAndFromPb() { assertNull(LOAD_CONFIGURATION_CSV.toPb().getLoad().getSourceUris()); compareLoadConfiguration( LOAD_CONFIGURATION_CSV, WriteChannelConfiguration.fromPb(LOAD_CONFIGURATION_CSV.toPb())); WriteChannelConfiguration configuration = WriteChannelConfiguration.of(TABLE_ID); compareLoadConfiguration(configuration, WriteChannelConfiguration.fromPb(configuration.toPb())); }
loadConfigurationPb.setNullMarker(nullMarker); if (getCsvOptions() != null) { CsvOptions csvOptions = getCsvOptions(); loadConfigurationPb .setFieldDelimiter(csvOptions.getFieldDelimiter()) if (getDatastoreBackupOptions() != null) { DatastoreBackupOptions backupOptions = getDatastoreBackupOptions(); loadConfigurationPb.setProjectionFields(backupOptions.getProjectionFields());
@Override public TableDataWriteChannel writer( JobId jobId, WriteChannelConfiguration writeChannelConfiguration) { return new TableDataWriteChannel( getOptions(), jobId.setProjectId(getOptions().getProjectId()), writeChannelConfiguration.setProjectId(getOptions().getProjectId())); }
WriteChannelConfiguration setProjectId(String projectId) { return toBuilder().destinationTable(destinationTable().setProjectId(projectId)).build(); }
@Override public WriteChannelConfiguration build() { return new WriteChannelConfiguration(this); } }
@Override public String toString() { return toStringHelper().toString(); }
@Override Tuple<WriteChannelConfiguration, String> parse(String... args) throws Exception { if (args.length == 4) { String dataset = args[0]; String table = args[1]; String format = args[2]; TableId tableId = TableId.of(dataset, table); WriteChannelConfiguration configuration = WriteChannelConfiguration.of(tableId, FormatOptions.of(format)); return Tuple.of(configuration, args[3]); } throw new IllegalArgumentException("Missing required arguments."); }
@Test public void testToBuilder() { compareLoadConfiguration(LOAD_CONFIGURATION_CSV, LOAD_CONFIGURATION_CSV.toBuilder().build()); WriteChannelConfiguration configuration = LOAD_CONFIGURATION_CSV .toBuilder() .setDestinationTable(TableId.of("dataset", "newTable")) .build(); assertEquals("newTable", configuration.getDestinationTable().getTable()); configuration = configuration.toBuilder().setDestinationTable(TABLE_ID).build(); compareLoadConfiguration(LOAD_CONFIGURATION_CSV, configuration); }
loadConfigurationPb.setNullMarker(nullMarker); if (getCsvOptions() != null) { CsvOptions csvOptions = getCsvOptions(); loadConfigurationPb .setFieldDelimiter(csvOptions.getFieldDelimiter()) if (getDatastoreBackupOptions() != null) { DatastoreBackupOptions backupOptions = getDatastoreBackupOptions(); loadConfigurationPb.setProjectionFields(backupOptions.getProjectionFields());
@Override public TableDataWriteChannel writer(WriteChannelConfiguration writeChannelConfiguration) { return new TableDataWriteChannel(options(), writeChannelConfiguration.setProjectId(options().projectId())); }
@Override public WriteChannelConfiguration build() { return new WriteChannelConfiguration(this); } }
@Override public String toString() { return toStringHelper().toString(); }