damccorm commented on code in PR #37235:
URL: https://github.com/apache/beam/pull/37235#discussion_r2666136542
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/AvroGenericRecordToStorageApiProto.java:
##########
@@ -502,10 +520,42 @@ static Object mapEntryToProtoValue(
return builder.build();
}
+ private static DynamicMessage buildTimestampPicosMessage(
+ Descriptor timestampPicosDescriptor, long seconds, long picoseconds) {
+ return DynamicMessage.newBuilder(timestampPicosDescriptor)
+ .setField(
+
Preconditions.checkNotNull(timestampPicosDescriptor.findFieldByName("seconds")),
+ seconds)
+ .setField(
+
Preconditions.checkNotNull(timestampPicosDescriptor.findFieldByName("picoseconds")),
+ picoseconds)
+ .build();
+ }
+
@VisibleForTesting
- static Object scalarToProtoValue(Schema fieldSchema, Object value) {
+ static Object scalarToProtoValue(
+ @Nullable FieldDescriptor descriptor, Schema fieldSchema, Object value) {
TypeWithNullability type = TypeWithNullability.create(fieldSchema);
+ if
(TIMESTAMP_NANOS_LOGICAL_TYPE.equals(type.getType().getProp("logicalType"))) {
+ Preconditions.checkArgument(
+ value instanceof Long, "Expecting a value as Long type
(timestamp-nanos).");
+ long nanos = (Long) value;
+
+ long seconds = nanos / NANOS_PER_SECOND;
+ long nanoAdjustment = nanos % NANOS_PER_SECOND;
+
+ // Handle negative timestamps (before epoch)
+ if (nanos < 0 && nanoAdjustment != 0) {
+ seconds -= 1;
+ nanoAdjustment += NANOS_PER_SECOND;
+ }
Review Comment:
Optional - I don't think this reads clearer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]