Skip to content

Commit

Permalink
bigquery: make FieldValue publicly construct-able (googleapis#2891)
Browse files Browse the repository at this point in the history
so make testing easier for users. Fixes googleapis#2880.
  • Loading branch information
pongad committed Feb 12, 2018
1 parent e2f0d20 commit ce6ef37
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import static com.google.common.base.Preconditions.checkState;

import com.google.api.client.util.Data;
import com.google.api.core.BetaApi;
import com.google.common.base.MoreObjects;
import com.google.common.io.BaseEncoding;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -65,7 +65,7 @@ public enum Attribute {
}

private FieldValue(Attribute attribute, Object value) {
this.attribute = attribute;
this.attribute = checkNotNull(attribute);
this.value = value;
}

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

static FieldValue of(Attribute attribute, Object value) {
/**
* Creates an instance of {@code FieldValue}, useful for testing.
*
* <p>If the {@code attribute} is {@link Attribute#PRIMITIVE}, the {@code value} should be the
* string representation of the underlying value, eg {@code "123"} for number {@code 123}.
*
* <p>If the {@code attribute} is {@link Attribute#REPEATED} or {@link Attribute#RECORD}, the
* {@code value} should be {@code List} of {@link FieldValue}s or {@link FieldValueList},
* respectively.
*
* <p>This method is unstable. See <a
* href="https://github.com/GoogleCloudPlatform/google-cloud-java/pull/2891">this discussion</a>
* for more context.
*/
@BetaApi
public static FieldValue of(Attribute attribute, Object value) {
return new FieldValue(attribute, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.bigquery;

import com.google.api.core.BetaApi;
import com.google.common.collect.ImmutableList;
import java.io.Serializable;
import java.util.AbstractList;
Expand Down Expand Up @@ -84,11 +85,27 @@ public int size() {
return row.size();
}

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

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

Expand Down

0 comments on commit ce6ef37

Please sign in to comment.