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

Bigquery: corrected equality check on subclasses of StringEnumValue #4283

Merged
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 @@ -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