Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ff1ebc6

Browse files
authoredApr 19, 2024
feat: Add support for inserting Range values (#3246)
* feat: Add support for inserting Range values * fix: IT assert to use size instead of const
1 parent ee94a6e commit ff1ebc6

File tree

3 files changed

+246
-108
lines changed

3 files changed

+246
-108
lines changed
 

‎google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Range.java

+13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.auto.value.AutoValue;
2121
import com.google.cloud.bigquery.FieldValue.Attribute;
22+
import com.google.common.collect.ImmutableMap;
2223
import java.io.Serializable;
2324
import javax.annotation.Nullable;
2425

@@ -44,6 +45,18 @@ public FieldValue getEnd() {
4445
@Nullable
4546
abstract String getEndInner();
4647

48+
/** Returns the start and end values of this range. */
49+
public ImmutableMap<String, String> getValues() {
50+
ImmutableMap.Builder<String, String> result = ImmutableMap.builder();
51+
if (!getStart().isNull()) {
52+
result.put("start", getStart().getStringValue());
53+
}
54+
if (!getEnd().isNull()) {
55+
result.put("end", getEnd().getStringValue());
56+
}
57+
return result.build();
58+
}
59+
4760
/** Returns the type of the range. */
4861
@Nullable
4962
public abstract FieldElementType getType();

‎google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RangeTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.junit.Assert.assertEquals;
1919
import static org.junit.Assert.assertTrue;
2020

21+
import com.google.common.collect.ImmutableMap;
2122
import org.junit.Test;
2223

2324
public class RangeTest {
@@ -77,6 +78,17 @@ public void testToBuilder() {
7778
compareRange(RANGE_TIMESTAMP, RANGE_TIMESTAMP.toBuilder().build());
7879
}
7980

81+
@Test
82+
public void testGetValues() {
83+
compareRange(null, null, Range.of("[null, NULL)").getValues());
84+
compareRange(null, null, Range.of("[unbounded, UNBOUNDED)").getValues());
85+
compareRange(null, null, Range.of("[nUlL, uNbOuNdEd)").getValues());
86+
87+
compareRange(null, "2020-12-31", Range.of("[null, 2020-12-31)").getValues());
88+
compareRange("2020-01-01", null, Range.of("[2020-01-01, null)").getValues());
89+
compareRange("2020-01-01", "2020-12-31", Range.of("[2020-01-01, 2020-12-31)").getValues());
90+
}
91+
8092
private static void compareRange(Range expected, Range value) {
8193
assertEquals(expected.getStart(), value.getStart());
8294
assertEquals(expected.getEnd(), value.getEnd());
@@ -97,4 +109,10 @@ private static void compareRange(String expectedStart, String expectedEnd, Range
97109
assertEquals(expectedEnd, range.getEnd().getStringValue());
98110
}
99111
}
112+
113+
private static void compareRange(
114+
String expectedStart, String expectedEnd, ImmutableMap<String, String> values) {
115+
assertEquals(expectedStart, values.get("start"));
116+
assertEquals(expectedEnd, values.get("end"));
117+
}
100118
}
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.