Add format parameter to ExtractJobInfo and LoadJobInfo factory methods by mziccard · Pull Request #527 · googleapis/google-cloud-java · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,23 @@ public static LoadJobInfo of(TableId destinationTable, List<String> sourceUris)
return builder(destinationTable, sourceUris).build();
}

/**
* Returns a BigQuery Load Job for the given destination table, format and source URI. Job's id is
* chosen by the service.
*/
public static LoadJobInfo of(TableId destinationTable, FormatOptions format, String sourceUri) {
return builder(destinationTable, sourceUri).formatOptions(format).build();
}

/**
* Returns a BigQuery Load Job for the given destination table, format and source URIs. Job's id
* is chosen by the service.
*/
public static LoadJobInfo of(TableId destinationTable, FormatOptions format,
List<String> sourceUris) {
return builder(destinationTable, sourceUris).formatOptions(format).build();
}

/**
* Returns a BigQuery Load Job for the given destination table and source URI. Job's id is set to
* the provided value.
Expand All @@ -423,6 +440,24 @@ public static LoadJobInfo of(JobId jobId, TableId destinationTable, List<String>
return builder(destinationTable, sourceUris).jobId(jobId).build();
}

/**
* Returns a BigQuery Load Job for the given destination table, format, and source URI. Job's id
* is set to the provided value.
*/
public static LoadJobInfo of(JobId jobId, TableId destinationTable, FormatOptions format,
String sourceUri) {
return builder(destinationTable, sourceUri).formatOptions(format).jobId(jobId).build();
}

/**
* Returns a BigQuery Load Job for the given destination table, format and source URIs. Job's id
* is set to the provided value.
*/
public static LoadJobInfo of(JobId jobId, TableId destinationTable, FormatOptions format,
List<String> sourceUris) {
return builder(destinationTable, sourceUris).formatOptions(format).jobId(jobId).build();
}

@SuppressWarnings("unchecked")
static LoadJobInfo fromPb(Job jobPb) {
return new Builder(jobPb).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public enum Priority {

/**
* Query is queued and started as soon as idle resources are available, usually within a few
* minutes. If a {@link Priority#BATCH} query hasn't started within 3 hours, its priority is
* changed to {@link Priority#INTERACTIVE}.
* minutes. If the query hasn't started within 3 hours, its priority is changed to
* {@link Priority#INTERACTIVE}.
*/
BATCH
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,8 @@ Job extract(String format, String destinationUri, BigQuery.JobOption... options)
*/
Job extract(String format, List<String> destinationUris, BigQuery.JobOption... options)
throws BigQueryException {
ExtractJobInfo job = ExtractJobInfo.builder(info.tableId(), destinationUris)
.format(format)
.build();
return new Job(bigquery, bigquery.create(job, options));
return new Job(bigquery,
bigquery.create(ExtractJobInfo.of(info.tableId(), format, destinationUris), options));
}

/**
Expand Down Expand Up @@ -264,10 +262,8 @@ Job load(FormatOptions format, String sourceUri, BigQuery.JobOption... options)
*/
Job load(FormatOptions format, List<String> sourceUris, BigQuery.JobOption... options)
throws BigQueryException {
LoadJobInfo job = LoadJobInfo.builder(info.tableId(), sourceUris)
.formatOptions(format)
.build();
return new Job(bigquery, bigquery.create(job, options));
return new Job(bigquery, bigquery.create(LoadJobInfo.of(info.tableId(), format, sourceUris),
options));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ExtractJobInfoTest {
private static final TableId TABLE_ID = TableId.of("dataset", "table");
private static final String FIELD_DELIMITER = ",";
private static final String FORMAT = "CSV";
private static final String JSON_FORMAT = "NEWLINE_DELIMITED_JSON";
private static final Boolean PRINT_HEADER = true;
private static final String COMPRESSION = "GZIP";
private static final JobId JOB_ID = JobId.of("job");
Expand Down Expand Up @@ -95,6 +96,14 @@ public void testOf() {
job = ExtractJobInfo.of(TABLE_ID, DESTINATION_URI);
assertEquals(TABLE_ID, job.sourceTable());
assertEquals(ImmutableList.of(DESTINATION_URI), job.destinationUris());
job = ExtractJobInfo.of(TABLE_ID, JSON_FORMAT, DESTINATION_URIS);
assertEquals(TABLE_ID, job.sourceTable());
assertEquals(DESTINATION_URIS, job.destinationUris());
assertEquals(JSON_FORMAT, job.format());
job = ExtractJobInfo.of(TABLE_ID, JSON_FORMAT, DESTINATION_URI);
assertEquals(TABLE_ID, job.sourceTable());
assertEquals(ImmutableList.of(DESTINATION_URI), job.destinationUris());
assertEquals(JSON_FORMAT, job.format());
job = ExtractJobInfo.of(JOB_ID, TABLE_ID, DESTINATION_URIS);
assertEquals(JOB_ID, job.jobId());
assertEquals(TABLE_ID, job.sourceTable());
Expand All @@ -103,6 +112,16 @@ public void testOf() {
assertEquals(JOB_ID, job.jobId());
assertEquals(TABLE_ID, job.sourceTable());
assertEquals(ImmutableList.of(DESTINATION_URI), job.destinationUris());
job = ExtractJobInfo.of(JOB_ID, TABLE_ID, JSON_FORMAT, DESTINATION_URIS);
assertEquals(JOB_ID, job.jobId());
assertEquals(TABLE_ID, job.sourceTable());
assertEquals(DESTINATION_URIS, job.destinationUris());
assertEquals(JSON_FORMAT, job.format());
job = ExtractJobInfo.of(JOB_ID, TABLE_ID, JSON_FORMAT, DESTINATION_URI);
assertEquals(JOB_ID, job.jobId());
assertEquals(TABLE_ID, job.sourceTable());
assertEquals(ImmutableList.of(DESTINATION_URI), job.destinationUris());
assertEquals(JSON_FORMAT, job.format());
}

@Test
Expand Down