Skip to content

Commit 30d0a2a

Browse files
committed
expected int raw type for time-millis
1 parent 5dceb77 commit 30d0a2a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/AvroGenericRecordToStorageApiProto.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static Long convertTimestamp(Object value, boolean micros) {
138138
} else {
139139
Preconditions.checkArgument(
140140
value instanceof Long, "Expecting a value as Long type (timestamp).");
141-
return ((Long) value) * (micros ? 1 : 1_000L);
141+
return (micros ? 1 : 1_000L) * ((Long) value);
142142
}
143143
}
144144

@@ -161,8 +161,15 @@ static Long convertTime(Object value, boolean micros) {
161161
return java.util.concurrent.TimeUnit.NANOSECONDS.toMicros(
162162
((java.time.LocalTime) value).toNanoOfDay());
163163
} else {
164-
Preconditions.checkArgument(value instanceof Long, "Expecting a value as Long type (time).");
165-
return (Long) value * (micros ? 1 : 1_000L);
164+
if (micros) {
165+
Preconditions.checkArgument(
166+
value instanceof Long, "Expecting a value as Long type (time).");
167+
return (Long) value;
168+
} else {
169+
Preconditions.checkArgument(
170+
value instanceof Integer, "Expecting a value as Integer type (time).");
171+
return 1_000L * (Integer) value;
172+
}
166173
}
167174
}
168175

@@ -180,7 +187,7 @@ static Long convertDateTime(Object value, boolean micros) {
180187
} else {
181188
Preconditions.checkArgument(
182189
value instanceof Long, "Expecting a value as Long type (local-timestamp).");
183-
return ((Long) value) * (micros ? 1 : 1_000L);
190+
return (micros ? 1 : 1_000L) * ((Long) value);
184191
}
185192
}
186193

sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/AvroGenericRecordToStorageApiProtoTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ enum TestEnum {
359359
LogicalTypes.decimal(2, 1)))
360360
.set("dateValue", 42)
361361
.set("timeMicrosValue", 42_000_000L)
362-
.set("timeMillisValue", 42_000L)
362+
.set("timeMillisValue", 42_000) // expects int
363363
.set("timestampMicrosValue", 42_000_000L)
364364
.set("timestampMillisValue", 42_000L)
365365
.set("localTimestampMicrosValue", 42_000_000L)

0 commit comments

Comments
 (0)