2222import warnings
2323from typing import Sequence
2424
25- from google .cloud .bigtable import Client
25+ from google .cloud .bigtable import Client , enums
2626from google .cloud .bigtable .cluster import Cluster
2727from google .cloud .bigtable .column_family import ColumnFamily , GarbageCollectionRule
2828from google .cloud .bigtable .instance import Instance
2929from google .cloud .bigtable .table import ClusterState , Table
30- from google .cloud .bigtable_admin_v2 import enums
3130
3231from airflow .providers .google .common .consts import CLIENT_INFO
3332from airflow .providers .google .common .hooks .base_google import GoogleBaseHook
@@ -56,9 +55,9 @@ def __init__(
5655 delegate_to = delegate_to ,
5756 impersonation_chain = impersonation_chain ,
5857 )
59- self ._client = None
58+ self ._client : Client | None = None
6059
61- def _get_client (self , project_id : str ):
60+ def _get_client (self , project_id : str ) -> Client :
6261 if not self ._client :
6362 self ._client = Client (
6463 project = project_id ,
@@ -69,7 +68,7 @@ def _get_client(self, project_id: str):
6968 return self ._client
7069
7170 @GoogleBaseHook .fallback_to_default_project_id
72- def get_instance (self , instance_id : str , project_id : str ) -> Instance :
71+ def get_instance (self , instance_id : str , project_id : str ) -> Instance | None :
7372 """
7473 Retrieves and returns the specified Cloud Bigtable instance if it exists.
7574 Otherwise, returns None.
@@ -113,10 +112,10 @@ def create_instance(
113112 project_id : str ,
114113 replica_clusters : list [dict [str , str ]] | None = None ,
115114 instance_display_name : str | None = None ,
116- instance_type : enums .Instance .Type = enums .Instance .Type .TYPE_UNSPECIFIED ,
115+ instance_type : enums .Instance .Type = enums .Instance .Type .UNSPECIFIED , # type: ignore[assignment]
117116 instance_labels : dict | None = None ,
118117 cluster_nodes : int | None = None ,
119- cluster_storage_type : enums .StorageType = enums .StorageType .STORAGE_TYPE_UNSPECIFIED ,
118+ cluster_storage_type : enums .StorageType = enums .StorageType .UNSPECIFIED , # type: ignore[assignment]
120119 timeout : float | None = None ,
121120 ) -> Instance :
122121 """
@@ -142,9 +141,6 @@ def create_instance(
142141 :param timeout: (optional) timeout (in seconds) for instance creation.
143142 If None is not specified, Operator will wait indefinitely.
144143 """
145- cluster_storage_type = enums .StorageType (cluster_storage_type )
146- instance_type = enums .Instance .Type (instance_type )
147-
148144 instance = Instance (
149145 instance_id ,
150146 self ._get_client (project_id = project_id ),
@@ -200,8 +196,6 @@ def update_instance(
200196 :param timeout: (optional) timeout (in seconds) for instance update.
201197 If None is not specified, Operator will wait indefinitely.
202198 """
203- instance_type = enums .Instance .Type (instance_type )
204-
205199 instance = Instance (
206200 instance_id = instance_id ,
207201 client = self ._get_client (project_id = project_id ),
@@ -253,7 +247,10 @@ def delete_table(self, instance_id: str, table_id: str, project_id: str) -> None
253247 BigTable exists. If set to None or missing,
254248 the default project_id from the Google Cloud connection is used.
255249 """
256- table = self .get_instance (instance_id = instance_id , project_id = project_id ).table (table_id = table_id )
250+ instance = self .get_instance (instance_id = instance_id , project_id = project_id )
251+ if instance is None :
252+ raise RuntimeError ("Instance %s did not exist; unable to delete table %s" % instance_id , table_id )
253+ table = instance .table (table_id = table_id )
257254 table .delete ()
258255
259256 @staticmethod
0 commit comments