Skip to content

Commit

Permalink
Bigquery: corrected equality check on subclasses of StringEnumValue (#…
Browse files Browse the repository at this point in the history
…4283)

* Bigquery: corrected equality check on subclasses of StringEnumValue

* update format for FieldTest.java
  • Loading branch information
charlesliqlogic authored and JesseLovelace committed Jan 9, 2019
1 parent 3d11659 commit 4dc2a5e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public Builder setType(LegacySQLTypeName type, Field... subFields) {
* Types</a>
*/
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand All @@ -377,7 +377,7 @@ public boolean shouldRetry(Throwable prevThrowable, Job prevResponse) {
* <p>Example of reloading all fields until job status is DONE.
*
* <pre>{@code
* while (job.getStatus().getState() != JobStatus.State.DONE) {
* while (!JobStatus.State.DONE.equals(job.getStatus().getState())) {
* Thread.sleep(1000L);
* job = job.reload();
* }
Expand All @@ -386,7 +386,7 @@ public boolean shouldRetry(Throwable prevThrowable, Job prevResponse) {
* <p>Example of reloading status field until job status is DONE.
*
* <pre>{@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));
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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));
}
Expand Down

0 comments on commit 4dc2a5e

Please sign in to comment.