From b2ed1c56402238e5b78dfca7fc86189639603db9 Mon Sep 17 00:00:00 2001 From: Kirill Berezin <126603518+kberezin-nshl@users.noreply.github.com> Date: Fri, 23 Aug 2024 08:46:15 -0700 Subject: [PATCH] Loose BigQuery GCP project ID regex restrictions (#32178) --- .../org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.java | 9 +++++---- .../beam/sdk/io/gcp/bigquery/BigQueryHelpersTest.java | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.java b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.java index aa094ace7562..71302339af1a 100644 --- a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.java +++ b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.java @@ -574,11 +574,12 @@ public class BigQueryIO { static final JsonFactory JSON_FACTORY = Transport.getJsonFactory(); /** - * Project IDs must contain 6-63 lowercase letters, digits, or dashes. IDs must start with a - * letter and may not end with a dash. This regex isn't exact - this allows for patterns that - * would be rejected by the service, but this is sufficient for basic parsing of table references. + * Formally, project IDs must contain 6-63 lowercase letters, digits, or dashes, must start with a + * letter and may not end with a dash. This regex is used for basic parsing of table references + * rather than validation purpose, e.g. it allows looser restriction for testing on mock + * resources. It may allow for patterns that would be rejected by the service */ - private static final String PROJECT_ID_REGEXP = "[a-z][-a-z0-9:.]{4,61}[a-z0-9]"; + private static final String PROJECT_ID_REGEXP = "[a-z][-a-z0-9:.]{0,61}[a-z0-9]"; /** Regular expression that matches Dataset IDs. */ private static final String DATASET_REGEXP = "[-\\w.]{1,1024}"; diff --git a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryHelpersTest.java b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryHelpersTest.java index 6779920702dc..df96f3bc4c75 100644 --- a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryHelpersTest.java +++ b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryHelpersTest.java @@ -88,6 +88,7 @@ public void testTableUrnParsing() { public void testTableParsing_validPatterns() { BigQueryHelpers.parseTableSpec("a123-456:foo_bar.d"); BigQueryHelpers.parseTableSpec("a12345:b.c"); + BigQueryHelpers.parseTableSpec("a1:b.c"); BigQueryHelpers.parseTableSpec("b12345.c"); }