Skip to content

Commit

Permalink
Merge pull request #527 from mziccard/add-format-to-of
Browse files Browse the repository at this point in the history
Add format parameter to ExtractJobInfo and LoadJobInfo factory methods
  • Loading branch information
ajkannan committed Jan 6, 2016
2 parents 8d37c32 + c3e808d commit 5da46e8
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ public static ExtractJobInfo of(TableId sourceTable, List<String> destinationUri
return builder(sourceTable, destinationUris).build();
}

/**
* Returns a BigQuery Extract Job for the given source table, format and destination URI. Job's id
* is chosen by the service.
*/
public static ExtractJobInfo of(TableId sourceTable, String format, String destinationUri) {
return builder(sourceTable, destinationUri).format(format).build();
}

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

/**
* Returns a BigQuery Extract Job for the given source table and destination URI. Job's id is set
* to the provided value.
Expand All @@ -279,6 +296,24 @@ public static ExtractJobInfo of(JobId jobId, TableId sourceTable, List<String> d
return builder(sourceTable, destinationUris).jobId(jobId).build();
}

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

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

@SuppressWarnings("unchecked")
static ExtractJobInfo fromPb(Job jobPb) {
return new Builder(jobPb).build();
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ public void testOf() {
job = LoadJobInfo.of(TABLE_ID, SOURCE_URI);
assertEquals(TABLE_ID, job.destinationTable());
assertEquals(ImmutableList.of(SOURCE_URI), job.sourceUris());
job = LoadJobInfo.of(TABLE_ID, CSV_OPTIONS, SOURCE_URIS);
assertEquals(TABLE_ID, job.destinationTable());
assertEquals(SOURCE_URIS, job.sourceUris());
assertEquals(FORMAT, job.format());
assertEquals(CSV_OPTIONS, job.csvOptions());
job = LoadJobInfo.of(TABLE_ID, CSV_OPTIONS, SOURCE_URI);
assertEquals(TABLE_ID, job.destinationTable());
assertEquals(ImmutableList.of(SOURCE_URI), job.sourceUris());
assertEquals(FORMAT, job.format());
assertEquals(CSV_OPTIONS, job.csvOptions());
job = LoadJobInfo.of(JOB_ID, TABLE_ID, SOURCE_URIS);
assertEquals(JOB_ID, job.jobId());
assertEquals(TABLE_ID, job.destinationTable());
Expand All @@ -110,6 +120,18 @@ public void testOf() {
assertEquals(JOB_ID, job.jobId());
assertEquals(TABLE_ID, job.destinationTable());
assertEquals(ImmutableList.of(SOURCE_URI), job.sourceUris());
job = LoadJobInfo.of(JOB_ID, TABLE_ID, CSV_OPTIONS, SOURCE_URIS);
assertEquals(JOB_ID, job.jobId());
assertEquals(TABLE_ID, job.destinationTable());
assertEquals(SOURCE_URIS, job.sourceUris());
assertEquals(FORMAT, job.format());
assertEquals(CSV_OPTIONS, job.csvOptions());
job = LoadJobInfo.of(JOB_ID, TABLE_ID, CSV_OPTIONS, SOURCE_URI);
assertEquals(JOB_ID, job.jobId());
assertEquals(TABLE_ID, job.destinationTable());
assertEquals(ImmutableList.of(SOURCE_URI), job.sourceUris());
assertEquals(FORMAT, job.format());
assertEquals(CSV_OPTIONS, job.csvOptions());
}

@Test
Expand Down

0 comments on commit 5da46e8

Please sign in to comment.