Skip to content

Commit 5ad05ec

Browse files
committed
chore: Address GCA comments
1 parent 8ce6df5 commit 5ad05ec

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ public abstract class QueryParameterValue implements Serializable {
106106
.optionalEnd()
107107
.toFormatter()
108108
.withZone(ZoneOffset.UTC);
109-
// Regex to identify >9 digits in the fraction part (e.g. .123456789123)
110-
// Matches the dot, followed by 10-12 digits, followed by non-digits (like +00) or end of string
109+
// Regex to identify >9 digits in the fraction part (e.g. `.123456789123`)
110+
// Matches the dot, followed by 10+ digits, followed by non-digits (like +00) or end of string
111111
private static final Pattern ISO8601_TIMESTAMP_HIGH_PRECISION_PATTERN =
112-
Pattern.compile("(\\.\\d{10,12})(?:\\D|$)");
112+
Pattern.compile("(\\.\\d{10,})(?:\\D|$)");
113113

114114
private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
115115
private static final DateTimeFormatter timeFormatter =
@@ -556,6 +556,13 @@ static void validateTimestamp(String timestamp) {
556556
// Group 1 is the fractional part including the dot (e.g., ".123456789123")
557557
String fraction = matcher.group(1);
558558

559+
// The fraction part includes the dot, so we check its length.
560+
// It should be at most 13 characters long (. + 12 digits).
561+
if (fraction.length() > 13) {
562+
throw new IllegalArgumentException(
563+
"Fractional portion of ISO8601 supports up to picosecond (12 digits)");
564+
}
565+
559566
// Truncate to . + 9 digits
560567
String truncatedFraction = fraction.substring(0, 10);
561568
// Replace the entire fractional portion with the nanosecond portion. Digits exceeding the
@@ -566,12 +573,6 @@ static void validateTimestamp(String timestamp) {
566573
// It is valid as long as DateTimeFormatter doesn't throw an exception AND
567574
// the fractional portion past nanosecond precision is valid (up to picosecond)
568575
checkFormat(truncatedTimestamp, TIMESTAMP_VALIDATOR);
569-
long value = Long.parseLong(fraction.substring(10));
570-
// Picosecond supports the next three digits (0 - 999)
571-
if (value >= 1000) {
572-
throw new IllegalArgumentException(
573-
"Fractional portion of ISO8601 supports up to picosecond (12 digits)");
574-
}
575576
return;
576577
}
577578

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,10 @@ public void testInvalidTimestampStringValues() {
404404
// Fractional part has picosecond length, but fractional part is not a valid number
405405
assertThrows(
406406
IllegalArgumentException.class,
407-
() -> QueryParameterValue.timestamp("2014-08-19T12:34:00.123456789abc+00:00"));
407+
() -> QueryParameterValue.timestamp("2014-08-19 12:34:00.123456789abc+00:00"));
408408
assertThrows(
409409
IllegalArgumentException.class,
410-
() -> QueryParameterValue.timestamp("2014-08-19T12:34:00.123456abc789+00:00"));
410+
() -> QueryParameterValue.timestamp("2014-08-19 12:34:00.123456abc789+00:00"));
411411
}
412412

413413
@Test

0 commit comments

Comments
 (0)