Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add format parameter to ExtractJobInfo and LoadJobInfo factory methods #527

Merged
merged 2 commits into from
Jan 6, 2016
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 @@ -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