Skip to content

Commit

Permalink
batch: Add client-side validation for the table parameter in `toBig…
Browse files Browse the repository at this point in the history
…Query`.

PiperOrigin-RevId: 683193677
  • Loading branch information
Nate Schmitz authored and Google Earth Engine Authors committed Oct 7, 2024
1 parent eca1b66 commit 63c5020
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/ee/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,16 @@ def toBigQuery(
Returns:
An unstarted Task that exports the table.
"""
if table:
if (
not isinstance(table, str)
or re.fullmatch(r'.+\..+\..+', table) is None
):
raise ee_exception.EEException(
'The BigQuery table reference must be a string of the form'
' "project_id.dataset_id.table_id".'
)

config = {
'description': description,
'table': table,
Expand Down
23 changes: 23 additions & 0 deletions python/ee/tests/batch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,29 @@ def testExportTableToBigQueryAllParams(self):
task.config,
)

def testExportTableToBigQueryBadTableName(self):
"""Verifies a bad table name throws an exception."""
with apitestcase.UsingCloudApi():
with self.assertRaisesRegex(
ee.EEException,
'The BigQuery table reference must be a string of the form.*',
):
ee.batch.Export.table.toBigQuery(
collection=ee.FeatureCollection('foo'),
table=['array.instead.of.string'],
description='foo',
)

with self.assertRaisesRegex(
ee.EEException,
'The BigQuery table reference must be a string of the form.*',
):
ee.batch.Export.table.toBigQuery(
collection=ee.FeatureCollection('foo'),
table='not.the-correct-format',
description='foo',
)

def testExportVideoCloudApi(self):
"""Verifies the task created by Export.video()."""
with apitestcase.UsingCloudApi():
Expand Down

0 comments on commit 63c5020

Please sign in to comment.