damccorm commented on code in PR #37235:
URL: https://github.com/apache/beam/pull/37235#discussion_r2666139154
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java:
##########
@@ -587,7 +587,17 @@ private static List<TableFieldSchema>
toTableFieldSchema(Schema schema) {
field.setFields(toTableFieldSchema(mapSchema));
field.setMode(Mode.REPEATED.toString());
}
- field.setType(toStandardSQLTypeName(type).toString());
+ Schema.LogicalType<?, ?> logicalType = type.getLogicalType();
+ if (logicalType != null &&
Timestamp.IDENTIFIER.equals(logicalType.getIdentifier())) {
+ int precision =
Preconditions.checkArgumentNotNull(logicalType.getArgument());
+ if (precision != 9) {
+ throw new IllegalArgumentException(
+ "Unsupported precision for Timestamp logical type " + precision);
+ }
+
field.setType(StandardSQLTypeName.TIMESTAMP.toString()).setTimestampPrecision(12L);
Review Comment:
Same as previous
##########
sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryTimestampPicosIT.java:
##########
@@ -392,6 +398,112 @@ public void testReadWithNanosPrecision_Arrow() {
runReadTest(TimestampPrecision.NANOS, DataFormat.ARROW, expectedOutput,
simpleTableSpec);
}
+ // Schema with custom timestamp-nanos logical type
+ private static org.apache.avro.Schema createTimestampNanosAvroSchema() {
+ org.apache.avro.Schema longSchema =
+ org.apache.avro.Schema.create(org.apache.avro.Schema.Type.LONG);
+ longSchema.addProp("logicalType", "timestamp-nanos");
+ return org.apache.avro.SchemaBuilder.record("TimestampNanosRecord")
+ .fields()
+ .name("ts_nanos")
+ .type(longSchema)
+ .noDefault()
+ .endRecord();
+ }
+
+ private static final java.time.Instant TEST_INSTANT =
+ java.time.Instant.parse("2024-01-15T10:30:45.123456789Z");
+
+ private static final org.apache.avro.Schema TIMESTAMP_NANOS_AVRO_SCHEMA =
+ createTimestampNanosAvroSchema();
+
+ @Test
+ public void testWriteGenericRecordTimestampNanos() throws Exception {
+ String tableSpec =
+ String.format("%s:%s.%s", project, DATASET_ID,
"generic_record_ts_nanos_test");
+
+ // Create GenericRecord with timestamp-nanos value
+ GenericRecord record =
+ new GenericRecordBuilder(TIMESTAMP_NANOS_AVRO_SCHEMA)
+ .set(
+ "ts_nanos", TEST_INSTANT.getEpochSecond() * 1_000_000_000L +
TEST_INSTANT.getNano())
Review Comment:
Same as previous
--
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]