Skip to content

Commit f745ba8

Browse files
[executors] feat: use GOOGLE_CLOUD_PROJECT to initialize BigQueryExecutor
1 parent 507f60c commit f745ba8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

libs/garf_executors/garf_executors/bq_executor.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""Module for executing queries in BigQuery."""
14+
"""Executes queries in BigQuery."""
1515

1616
from __future__ import annotations
1717

18+
import os
19+
1820
try:
1921
from google.cloud import bigquery # type: ignore
2022
except ImportError as e:
@@ -46,13 +48,22 @@ class BigQueryExecutor(executor.Executor, query_editor.TemplateProcessorMixin):
4648
client: BigQuery client.
4749
"""
4850

49-
def __init__(self, project_id: str, location: str | None = None) -> None:
51+
def __init__(
52+
self,
53+
project_id: str | None = os.getenv('GOOGLE_CLOUD_PROJECT'),
54+
location: str | None = None,
55+
) -> None:
5056
"""Initializes BigQueryExecutor.
5157
5258
Args:
5359
project_id: Google Cloud project id.
5460
location: BigQuery dataset location.
5561
"""
62+
if not project_id:
63+
raise BigQueryExecutorError(
64+
'project_id is required. Either provide it as project_id parameter '
65+
'or GOOGLE_CLOUD_PROJECT env variable.'
66+
)
5667
self.project_id = project_id
5768
self.location = location
5869

0 commit comments

Comments
 (0)