Skip to content

Commit 30bab50

Browse files
committed
Add support for Bigquery reservations in config
1 parent b54d6f1 commit 30bab50

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

sqlmesh/core/config/connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ class BigQueryConnectionConfig(ConnectionConfig):
10581058
job_retry_deadline_seconds: t.Optional[int] = None
10591059
priority: t.Optional[BigQueryPriority] = None
10601060
maximum_bytes_billed: t.Optional[int] = None
1061+
reservation_id: t.Optional[str] = None
10611062

10621063
concurrent_tasks: int = 1
10631064
register_comments: bool = True
@@ -1167,6 +1168,7 @@ def _extra_engine_config(self) -> t.Dict[str, t.Any]:
11671168
"job_retry_deadline_seconds",
11681169
"priority",
11691170
"maximum_bytes_billed",
1171+
"reservation_id",
11701172
}
11711173
}
11721174

sqlmesh/core/engine_adapter/bigquery.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,13 @@ def _execute(
11061106
else []
11071107
)
11081108

1109+
# Create job config with reservation support
11091110
job_config = QueryJobConfig(**self._job_params, connection_properties=connection_properties)
1111+
1112+
# Set reservation directly on the job_config object if specified
1113+
reservation_id = self._extra_config.get("reservation_id")
1114+
if reservation_id:
1115+
job_config.reservation = reservation_id
11101116
self._query_job = self._db_call(
11111117
self.client.query,
11121118
query=sql,

tests/core/test_connection_config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,21 @@ def test_bigquery(make_config):
10421042
assert config.get_catalog() == "project"
10431043
assert config.is_recommended_for_state_sync is False
10441044

1045+
# Test reservation_id
1046+
config_with_reservation = make_config(
1047+
type="bigquery",
1048+
project="project",
1049+
reservation_id="projects/my-project/locations/us-central1/reservations/my-reservation",
1050+
check_import=False,
1051+
)
1052+
assert isinstance(config_with_reservation, BigQueryConnectionConfig)
1053+
assert config_with_reservation.reservation_id == "projects/my-project/locations/us-central1/reservations/my-reservation"
1054+
1055+
# Test that reservation_id is included in _extra_engine_config
1056+
extra_config = config_with_reservation._extra_engine_config
1057+
assert "reservation_id" in extra_config
1058+
assert extra_config["reservation_id"] == "projects/my-project/locations/us-central1/reservations/my-reservation"
1059+
10451060
with pytest.raises(ConfigError, match="you must also specify the `project` field"):
10461061
make_config(type="bigquery", execution_project="execution_project", check_import=False)
10471062

0 commit comments

Comments
 (0)