Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 9849ce6

Browse files
committed
chore: Address PR feedback
1 parent e67b4f3 commit 9849ce6

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public Builder setPrecision(Long precision) {
265265
*/
266266
public Builder setTimestampPrecision(Long timestampPrecision) {
267267
Preconditions.checkArgument(
268-
timestampPrecision != 6L || timestampPrecision != 12L,
268+
timestampPrecision == 6L || timestampPrecision == 12L,
269269
"Timestamp Precision must be 6 (microsecond) or 12 (picosecond)");
270270
this.timestampPrecision = timestampPrecision;
271271
return this;
@@ -431,6 +431,7 @@ public String toString() {
431431
.add("maxLength", maxLength)
432432
.add("scale", scale)
433433
.add("precision", precision)
434+
.add("timestampPrecision", timestampPrecision)
434435
.add("defaultValueExpression", defaultValueExpression)
435436
.add("collation", collation)
436437
.add("rangeElementType", rangeElementType)
@@ -439,7 +440,19 @@ public String toString() {
439440

440441
@Override
441442
public int hashCode() {
442-
return Objects.hash(name, type, mode, description, policyTags, rangeElementType);
443+
return Objects.hash(
444+
name,
445+
type,
446+
mode,
447+
description,
448+
policyTags,
449+
maxLength,
450+
scale,
451+
precision,
452+
timestampPrecision,
453+
defaultValueExpression,
454+
collation,
455+
rangeElementType);
443456
}
444457

445458
@Override

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FieldTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.bigquery;
1818

1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertThrows;
2021

2122
import java.io.ByteArrayInputStream;
2223
import java.io.ByteArrayOutputStream;
@@ -213,6 +214,20 @@ public void testSubFieldWithClonedType() throws Exception {
213214
Field.of("field", clonedRecord, Field.of("subfield", LegacySQLTypeName.BOOLEAN));
214215
}
215216

217+
@Test
218+
public void setTimestampPrecisionValues() {
219+
Field.Builder builder = Field.newBuilder(FIELD_NAME1, FIELD_TYPE1);
220+
221+
// Value values: 6L or 12L
222+
builder.setTimestampPrecision(6L);
223+
builder.setTimestampPrecision(12L);
224+
225+
assertThrows(IllegalArgumentException.class, () -> builder.setTimestampPrecision(-1L));
226+
assertThrows(IllegalArgumentException.class, () -> builder.setTimestampPrecision(0L));
227+
assertThrows(IllegalArgumentException.class, () -> builder.setTimestampPrecision(5L));
228+
assertThrows(IllegalArgumentException.class, () -> builder.setTimestampPrecision(13L));
229+
}
230+
216231
private void compareFieldSchemas(Field expected, Field value) {
217232
assertEquals(expected, value);
218233
assertEquals(expected.getName(), value.getName());

0 commit comments

Comments
 (0)