From 930ad5ea52cea0d44e150c247185d4d819b56e34 Mon Sep 17 00:00:00 2001 From: Dheeraj Gharde <45272841+dgdheeraj@users.noreply.github.com> Date: Wed, 6 Jul 2022 11:26:50 +0000 Subject: [PATCH] Updated Regex and test --- sdks/python/apache_beam/io/gcp/bigquery.py | 2 +- sdks/python/apache_beam/io/gcp/bigquery_tools.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sdks/python/apache_beam/io/gcp/bigquery.py b/sdks/python/apache_beam/io/gcp/bigquery.py index c810425f9901..12a280c8c208 100644 --- a/sdks/python/apache_beam/io/gcp/bigquery.py +++ b/sdks/python/apache_beam/io/gcp/bigquery.py @@ -951,7 +951,7 @@ class _CustomBigQueryStorageSource(BoundedSource): Args: table (str, TableReference): The ID of the table. The ID must contain only letters ``a-z``, ``A-Z``, numbers ``0-9``, underscores ``_`` or white - spaces. If **dataset** argument is :data:`None` then the table + spaces. If **dataset** argument is :data:`None` then the table argument must contain the entire table reference specified as: ``'PROJECT:DATASET.TABLE'`` or must specify a TableReference. dataset (str): Optional ID of the dataset containing this table or diff --git a/sdks/python/apache_beam/io/gcp/bigquery_tools.py b/sdks/python/apache_beam/io/gcp/bigquery_tools.py index 140e59813bb1..8098209c7e01 100644 --- a/sdks/python/apache_beam/io/gcp/bigquery_tools.py +++ b/sdks/python/apache_beam/io/gcp/bigquery_tools.py @@ -254,10 +254,11 @@ def parse_table_reference(table, dataset=None, project=None): # table argument will contain a full table reference instead of just a # table name. if dataset is None: - match = re.match( - r"""^((?P.+):)?(?P\w+)\. - (?P[-\w\$]+( +\-*\w+)*)$""", - table) + regex = re.compile( + r'''^((?P.+):)?(?P\w+)\. + (?P
[-\w\$]+(\s+\-*\w+)*)$''', + re.X) + match = regex.match(table) if not match: raise ValueError( 'Expected a table reference (PROJECT:DATASET.TABLE or '