Skip to content

Commit 8c22721

Browse files
b-perMichelleArk
andauthored
Fix dbt parse regression from BigFrames imports (#1605)
Co-authored-by: Michelle Ark <MichelleArk@users.noreply.github.com>
1 parent bee8b44 commit 8c22721

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: Fixes
2+
body: Lazy-load aiplatform and nbformat imports to fix dbt parse performance regression
3+
introduced in 1.9.2 by BigFrames support.
4+
time: 2026-02-06T12:00:00.000000-08:00
5+
custom:
6+
Author: "b-per"
7+
Issue: "1604"

dbt-bigquery/src/dbt/adapters/bigquery/clients.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
from typing import Optional
1+
from __future__ import annotations
2+
3+
from typing import Optional, TYPE_CHECKING
4+
5+
# Lazy-loaded inside create_notebook_client() to avoid slowing down every
6+
# `dbt parse` invocation. See: https://github.com/dbt-labs/dbt-adapters/issues/1604
7+
if TYPE_CHECKING:
8+
from google.cloud import aiplatform_v1
29

310
from google.api_core.client_info import ClientInfo
411
from google.api_core.client_options import ClientOptions
512
from google.auth.exceptions import DefaultCredentialsError
6-
from google.cloud import aiplatform_v1
713
from google.cloud.bigquery import Client as BigQueryClient, DEFAULT_RETRY as BQ_DEFAULT_RETRY
814
from google.cloud.dataproc_v1 import BatchControllerClient, JobControllerClient
915
from google.cloud.storage import Client as StorageClient
@@ -78,6 +84,8 @@ def _dataproc_endpoint(credentials: BigQueryCredentials) -> str:
7884
def create_notebook_client(
7985
credentials: GoogleCredentials, region: Optional[str]
8086
) -> aiplatform_v1.NotebookServiceClient:
87+
from google.cloud import aiplatform_v1
88+
8189
api_endpoint = f"{region}-aiplatform.googleapis.com"
8290
notebook_client = aiplatform_v1.NotebookServiceClient(
8391
credentials=credentials,

dbt-bigquery/src/dbt/adapters/bigquery/python_submissions.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
from __future__ import annotations
2+
13
import inspect
24
import json
35
import re
46
import time
5-
from typing import Any, Dict, Optional, Union
7+
from typing import Any, Dict, Optional, TYPE_CHECKING, Union
68
import uuid
79

10+
# These imports are heavy and only needed for BigFrames Python models.
11+
# They are lazy-loaded inside BigFramesHelper methods to avoid slowing
12+
# down every `dbt parse` invocation. See: https://github.com/dbt-labs/dbt-adapters/issues/1604
13+
if TYPE_CHECKING:
14+
from google.cloud import aiplatform_v1
15+
from google.cloud.aiplatform import gapic as aiplatform_gapic # noqa: F401
16+
817
from dbt.adapters.base import PythonJobHelper, PythonSubmissionResult
918
from dbt.adapters.bigquery import BigQueryCredentials
1019
from dbt.adapters.bigquery.clients import (
@@ -24,12 +33,9 @@
2433

2534
from google.api_core.operation import Operation
2635
from google.auth.transport.requests import Request
27-
from google.cloud import aiplatform_v1
28-
from google.cloud.aiplatform import gapic as aiplatform_gapic
2936
from google.cloud.dataproc_v1 import CreateBatchRequest, Job, RuntimeConfig
3037
from google.cloud.dataproc_v1.types.batches import Batch
3138
from google.protobuf.json_format import ParseDict
32-
import nbformat
3339

3440
_logger = AdapterLogger("BigQuery")
3541

@@ -231,13 +237,17 @@ def _get_token(self) -> str:
231237
return creds.token
232238

233239
def _py_to_ipynb(self, compiled_code: str) -> str:
240+
import nbformat
241+
234242
notebook = nbformat.v4.new_notebook()
235243
# Put all codes in one cell.
236244
notebook.cells.append(nbformat.v4.new_code_cell(compiled_code))
237245

238246
return nbformat.writes(notebook, nbformat.NO_CONVERT)
239247

240248
def _get_notebook_template_id(self) -> str:
249+
from google.cloud import aiplatform_v1
250+
241251
# If user specifies a runtime template id, use it.
242252
if self._notebook_template_id:
243253
return self._notebook_template_id
@@ -266,6 +276,8 @@ def _get_notebook_template_id(self) -> str:
266276
return self._create_notebook_template()
267277

268278
def _create_notebook_template(self) -> str:
279+
from google.cloud import aiplatform_v1
280+
269281
# Construct the full network and subnetwork resource names.
270282
network_full_name = f"projects/{self._project}/global/networks/{_NETWORK_NAME}"
271283
subnetwork_full_name = (
@@ -308,6 +320,8 @@ def _extract_template_id(self, template_name: str) -> str:
308320
def _config_notebook_job(
309321
self, notebook_template_id: str
310322
) -> aiplatform_v1.NotebookExecutionJob:
323+
from google.cloud import aiplatform_v1
324+
311325
notebook_execution_job = aiplatform_v1.NotebookExecutionJob()
312326
notebook_execution_job.notebook_runtime_template_resource_name = (
313327
f"projects/{self._project}/locations/{self._region}/"
@@ -471,6 +485,8 @@ def submit(self, compiled_code: str) -> PythonSubmissionResult:
471485

472486
def _track_notebook_job_status(self, job_name: str) -> aiplatform_v1.NotebookExecutionJob:
473487
"""Tracks the notebook job until it completes or times out."""
488+
from google.cloud.aiplatform import gapic as aiplatform_gapic # noqa: F811
489+
474490
max_wait_time = self._polling_retry.timeout
475491
elapsed = 0
476492

@@ -505,6 +521,8 @@ def _track_notebook_job_status(self, job_name: str) -> aiplatform_v1.NotebookExe
505521
def _submit_bigframes_job(
506522
self, notebook_template_id: str
507523
) -> aiplatform_v1.NotebookExecutionJob:
524+
from google.cloud import aiplatform_v1 # noqa: F811
525+
from google.cloud.aiplatform import gapic as aiplatform_gapic # noqa: F811
508526

509527
notebook_execution_job = self._config_notebook_job(notebook_template_id)
510528

0 commit comments

Comments
 (0)