Skip to content

Commit ce6ef37

Browse files
authored
bigquery: make FieldValue publicly construct-able (#2891)
so make testing easier for users. Fixes #2880.
1 parent e2f0d20 commit ce6ef37

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FieldValue.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import static com.google.common.base.Preconditions.checkState;
2121

2222
import com.google.api.client.util.Data;
23+
import com.google.api.core.BetaApi;
2324
import com.google.common.base.MoreObjects;
2425
import com.google.common.io.BaseEncoding;
25-
2626
import java.io.Serializable;
2727
import java.util.List;
2828
import java.util.Map;
@@ -65,7 +65,7 @@ public enum Attribute {
6565
}
6666

6767
private FieldValue(Attribute attribute, Object value) {
68-
this.attribute = attribute;
68+
this.attribute = checkNotNull(attribute);
6969
this.value = value;
7070
}
7171

@@ -251,7 +251,22 @@ public final boolean equals(Object obj) {
251251
return attribute == other.attribute && Objects.equals(value, other.value);
252252
}
253253

254-
static FieldValue of(Attribute attribute, Object value) {
254+
/**
255+
* Creates an instance of {@code FieldValue}, useful for testing.
256+
*
257+
* <p>If the {@code attribute} is {@link Attribute#PRIMITIVE}, the {@code value} should be the
258+
* string representation of the underlying value, eg {@code "123"} for number {@code 123}.
259+
*
260+
* <p>If the {@code attribute} is {@link Attribute#REPEATED} or {@link Attribute#RECORD}, the
261+
* {@code value} should be {@code List} of {@link FieldValue}s or {@link FieldValueList},
262+
* respectively.
263+
*
264+
* <p>This method is unstable. See <a
265+
* href="https://github.com/GoogleCloudPlatform/google-cloud-java/pull/2891">this discussion</a>
266+
* for more context.
267+
*/
268+
@BetaApi
269+
public static FieldValue of(Attribute attribute, Object value) {
255270
return new FieldValue(attribute, value);
256271
}
257272

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FieldValueList.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.bigquery;
1818

19+
import com.google.api.core.BetaApi;
1920
import com.google.common.collect.ImmutableList;
2021
import java.io.Serializable;
2122
import java.util.AbstractList;
@@ -84,11 +85,27 @@ public int size() {
8485
return row.size();
8586
}
8687

87-
static FieldValueList of(List<FieldValue> row, FieldList schema) {
88+
/**
89+
* Creates an instance of {@code FieldValueList}, useful for testing.
90+
*
91+
* <p>This method is unstable. See <a
92+
* href="https://github.com/GoogleCloudPlatform/google-cloud-java/pull/2891">this discussion</a>
93+
* for more context.
94+
*/
95+
@BetaApi
96+
public static FieldValueList of(List<FieldValue> row, FieldList schema) {
8897
return new FieldValueList(row, schema);
8998
}
9099

91-
static FieldValueList of(List<FieldValue> row, Field... schema) {
100+
/**
101+
* Creates an instance of {@code FieldValueList}, useful for testing.
102+
*
103+
* <p>This method is unstable. See <a
104+
* href="https://github.com/GoogleCloudPlatform/google-cloud-java/pull/2891">this discussion</a>
105+
* for more context.
106+
*/
107+
@BetaApi
108+
public static FieldValueList of(List<FieldValue> row, Field... schema) {
92109
return of(row, schema.length > 0 ? FieldList.of(schema) : null);
93110
}
94111

0 commit comments

Comments
 (0)