diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Field.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Field.java index 41f357e661b5..dda2d50aae9d 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Field.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Field.java @@ -125,7 +125,8 @@ public Builder setType(LegacySQLTypeName type, Field... subFields) { * Types */ public Builder setType(LegacySQLTypeName type, FieldList subFields) { - if (type == LegacySQLTypeName.RECORD) { + // LegacySQLTypeName is not an enum, cannot use reference equal. + if (LegacySQLTypeName.RECORD.equals(type)) { if (subFields == null || subFields.isEmpty()) { throw new IllegalArgumentException( "The " + type + " field must have at least one sub-field"); diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Job.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Job.java index 0643c268b7e0..9a61192c4045 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Job.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Job.java @@ -189,7 +189,7 @@ public boolean exists() { public boolean isDone() { checkNotDryRun("isDone"); Job job = bigquery.getJob(getJobId(), JobOption.fields(BigQuery.JobField.STATUS)); - return job == null || job.getStatus().getState() == JobStatus.State.DONE; + return job == null || JobStatus.State.DONE.equals(job.getStatus().getState()); } /** * Blocks until this job completes its execution, either failing or succeeding. This method @@ -293,7 +293,7 @@ public TableResult getQueryResults(QueryResultsOption... options) // Get the job resource to determine if it has errored. Job job = this; - if (job.getStatus() == null || job.getStatus().getState() != JobStatus.State.DONE) { + if (job.getStatus() == null || !JobStatus.State.DONE.equals(job.getStatus().getState())) { job = reload(); } if (job.getStatus() != null && job.getStatus().getError() != null) { @@ -362,7 +362,7 @@ public TimedAttemptSettings createNextAttempt( @Override public boolean shouldRetry(Throwable prevThrowable, Job prevResponse) { return prevResponse != null - && prevResponse.getStatus().getState() != JobStatus.State.DONE; + && !JobStatus.State.DONE.equals(prevResponse.getStatus().getState()); } }, options.getClock()); @@ -377,7 +377,7 @@ public boolean shouldRetry(Throwable prevThrowable, Job prevResponse) { *
Example of reloading all fields until job status is DONE. * *
{@code - * while (job.getStatus().getState() != JobStatus.State.DONE) { + * while (!JobStatus.State.DONE.equals(job.getStatus().getState())) { * Thread.sleep(1000L); * job = job.reload(); * } @@ -386,7 +386,7 @@ public boolean shouldRetry(Throwable prevThrowable, Job prevResponse) { *Example of reloading status field until job status is DONE. * *
{@code - * while (job.getStatus().getState() != JobStatus.State.DONE) { + * while (!JobStatus.State.DONE.equals(job.getStatus().getState())) { * Thread.sleep(1000L); * job = job.reload(BigQuery.JobOption.fields(BigQuery.JobField.STATUS)); * } diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FieldTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FieldTest.java index ffa545cf91f6..4ba5ad0929a0 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FieldTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FieldTest.java @@ -18,6 +18,11 @@ import static org.junit.Assert.assertEquals; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import org.junit.Test; public class FieldTest { @@ -92,6 +97,22 @@ public void testToAndFromPb() { compareFieldSchemas(field, Field.fromPb(field.toPb())); } + @Test + public void testSubFieldWithClonedType() throws Exception { + LegacySQLTypeName record = LegacySQLTypeName.RECORD; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(record); + oos.flush(); + oos.close(); + InputStream is = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(is); + LegacySQLTypeName clonedRecord = (LegacySQLTypeName) ois.readObject(); + ois.close(); + + Field.of("field", clonedRecord, Field.of("subfield", LegacySQLTypeName.BOOLEAN)); + } + private void compareFieldSchemas(Field expected, Field value) { assertEquals(expected, value); assertEquals(expected.getName(), value.getName()); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/JobSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/JobSnippets.java index 11729dd81db1..f9fb7b5fe376 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/JobSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/JobSnippets.java @@ -113,7 +113,7 @@ public boolean waitForWithOptions() throws InterruptedException { // [TARGET reload(JobOption...)] public JobStatus.State reload() throws InterruptedException { // [START ] - while (job.getStatus().getState() != JobStatus.State.DONE) { + while (!JobStatus.State.DONE.equals(job.getStatus().getState())) { Thread.sleep(1000L); job = job.reload(); } @@ -125,7 +125,7 @@ public JobStatus.State reload() throws InterruptedException { // [TARGET reload(JobOption...)] public JobStatus.State reloadStatus() throws InterruptedException { // [START ] - while (job.getStatus().getState() != JobStatus.State.DONE) { + while (!JobStatus.State.DONE.equals(job.getStatus().getState())) { Thread.sleep(1000L); job = job.reload(BigQuery.JobOption.fields(BigQuery.JobField.STATUS)); }