From 0a5962034bace33b6f1705a0ee32048d0762ed6e Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 6 Jan 2016 15:18:58 +0100 Subject: [PATCH 1/2] Add more factory methods to Load and ExtractJobInfo --- .../gcloud/bigquery/ExtractJobInfo.java | 35 +++++++++++++++++++ .../google/gcloud/bigquery/LoadJobInfo.java | 35 +++++++++++++++++++ .../com/google/gcloud/bigquery/Table.java | 12 +++---- .../gcloud/bigquery/ExtractJobInfoTest.java | 19 ++++++++++ .../gcloud/bigquery/LoadJobInfoTest.java | 22 ++++++++++++ 5 files changed, 115 insertions(+), 8 deletions(-) diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExtractJobInfo.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExtractJobInfo.java index 268672b04d68..effdab84f265 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExtractJobInfo.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExtractJobInfo.java @@ -263,6 +263,23 @@ public static ExtractJobInfo of(TableId sourceTable, List 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 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. @@ -279,6 +296,24 @@ public static ExtractJobInfo of(JobId jobId, TableId sourceTable, List 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 destinationUris) { + return builder(sourceTable, destinationUris).format(format).jobId(jobId).build(); + } + @SuppressWarnings("unchecked") static ExtractJobInfo fromPb(Job jobPb) { return new Builder(jobPb).build(); diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/LoadJobInfo.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/LoadJobInfo.java index df78b7ecec2f..1120bbbacf3f 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/LoadJobInfo.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/LoadJobInfo.java @@ -407,6 +407,23 @@ public static LoadJobInfo of(TableId destinationTable, List 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 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. @@ -423,6 +440,24 @@ public static LoadJobInfo of(JobId jobId, TableId destinationTable, List 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 sourceUris) { + return builder(destinationTable, sourceUris).formatOptions(format).jobId(jobId).build(); + } + @SuppressWarnings("unchecked") static LoadJobInfo fromPb(Job jobPb) { return new Builder(jobPb).build(); diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Table.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Table.java index fec3e0c03a90..fd9a96e132b6 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Table.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Table.java @@ -231,10 +231,8 @@ Job extract(String format, String destinationUri, BigQuery.JobOption... options) */ Job extract(String format, List 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)); } /** @@ -264,10 +262,8 @@ Job load(FormatOptions format, String sourceUri, BigQuery.JobOption... options) */ Job load(FormatOptions format, List 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)); } /** diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExtractJobInfoTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExtractJobInfoTest.java index e73975c6c3ab..bb47112b6410 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExtractJobInfoTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExtractJobInfoTest.java @@ -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"); @@ -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()); @@ -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 diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/LoadJobInfoTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/LoadJobInfoTest.java index bb2a263fc3e0..06ce0b42ad4b 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/LoadJobInfoTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/LoadJobInfoTest.java @@ -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()); @@ -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 From c3e808db13527ecc37005cdb5b032b41d00053e9 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 6 Jan 2016 15:25:57 +0100 Subject: [PATCH 2/2] Fix self reference in QueryJobInfo.Priority javadoc --- .../main/java/com/google/gcloud/bigquery/QueryJobInfo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/QueryJobInfo.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/QueryJobInfo.java index dd09d7010a50..5a8b822e87ef 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/QueryJobInfo.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/QueryJobInfo.java @@ -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 }