Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions providers/src/airflow/providers/google/ads/hooks/ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(
self.authentication_method: Literal["service_account", "developer_token"] = "service_account"

def search(
self, client_ids: list[str], query: str, page_size: int = 10000, **kwargs
self, client_ids: list[str], query: str, **kwargs
) -> list[GoogleAdsRow]:
"""
Pull data from the Google Ads API.
Expand All @@ -132,16 +132,15 @@ def search(

:param client_ids: Google Ads client ID(s) to query the API for.
:param query: Google Ads Query Language query.
:param page_size: Number of results to return per page. Max 10000.
:return: Google Ads API response, converted to Google Ads Row objects.
"""
data_proto_plus = self._search(client_ids, query, page_size, **kwargs)
data_proto_plus = self._search(client_ids, query, **kwargs)
data_native_pb = [row._pb for row in data_proto_plus]

return data_native_pb

def search_proto_plus(
self, client_ids: list[str], query: str, page_size: int = 10000, **kwargs
self, client_ids: list[str], query: str, **kwargs
) -> list[GoogleAdsRow]:
"""
Pull data from the Google Ads API.
Expand All @@ -151,10 +150,9 @@ def search_proto_plus(

:param client_ids: Google Ads client ID(s) to query the API for.
:param query: Google Ads Query Language query.
:param page_size: Number of results to return per page. Max 10000.
:return: Google Ads API response, converted to Google Ads Row objects
"""
return self._search(client_ids, query, page_size, **kwargs)
return self._search(client_ids, query, **kwargs)

def list_accessible_customers(self) -> list[str]:
"""
Expand Down Expand Up @@ -266,14 +264,13 @@ def _update_config_with_secret(self, secrets_temp: IO[str]) -> None:
self.google_ads_config["json_key_file_path"] = secrets_temp.name

def _search(
self, client_ids: list[str], query: str, page_size: int = 10000, **kwargs
self, client_ids: list[str], query: str, **kwargs
) -> list[GoogleAdsRow]:
"""
Pull data from the Google Ads API.

:param client_ids: Google Ads client ID(s) to query the API for.
:param query: Google Ads Query Language query.
:param page_size: Number of results to return per page. Max 10000.

:return: Google Ads API response, converted to Google Ads Row objects
"""
Expand All @@ -282,7 +279,7 @@ def _search(
iterators = []
for client_id in client_ids:
iterator = service.search(
request={"customer_id": client_id, "query": query, "page_size": page_size}
request={"customer_id": client_id, "query": query}
)
iterators.append(iterator)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class GoogleAdsToGcsOperator(BaseOperator):
:param obj: GCS path to save the object. Must be the full file path (ex. `path/to/file.txt`)
:param gcp_conn_id: Airflow Google Cloud connection ID
:param google_ads_conn_id: Airflow Google Ads connection ID
:param page_size: The number of results per API page request. Max 10,000
:param gzip: Option to compress local file or file data for upload
:param impersonation_chain: Optional service account to impersonate using short-term
credentials, or chained list of accounts required to get the access_token
Expand Down Expand Up @@ -83,7 +82,6 @@ def __init__(
obj: str,
gcp_conn_id: str = "google_cloud_default",
google_ads_conn_id: str = "google_ads_default",
page_size: int = 10000,
gzip: bool = False,
impersonation_chain: str | Sequence[str] | None = None,
api_version: str | None = None,
Expand All @@ -97,7 +95,6 @@ def __init__(
self.obj = obj
self.gcp_conn_id = gcp_conn_id
self.google_ads_conn_id = google_ads_conn_id
self.page_size = page_size
self.gzip = gzip
self.impersonation_chain = impersonation_chain
self.api_version = api_version
Expand All @@ -108,7 +105,7 @@ def execute(self, context: Context) -> None:
google_ads_conn_id=self.google_ads_conn_id,
api_version=self.api_version,
)
rows = service.search(client_ids=self.client_ids, query=self.query, page_size=self.page_size)
rows = service.search(client_ids=self.client_ids, query=self.query)

try:
getter = attrgetter(*self.attributes)
Expand Down
3 changes: 1 addition & 2 deletions providers/tests/google/ads/hooks/test_ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ def test_search(self, mock_client, mock_hook):
# avoid additional __iter__ calls
mock_hook._extract_rows = list
query = "QUERY"
mock_hook.search(client_ids=client_ids, query=query, page_size=2)
mock_hook.search(client_ids=client_ids, query=query)
for i, client_id in enumerate(client_ids):
name, args, kwargs = service.search.mock_calls[i]
assert kwargs["request"]["customer_id"] == client_id
assert kwargs["request"]["query"] == query
assert kwargs["request"]["page_size"] == 2

def test_extract_rows(self, mock_hook):
iterators = [[1, 2, 3], [4, 5, 6]]
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/google/ads/transfers/test_ads_to_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_execute(self, mock_gcs_hook, mock_ads_hook):
api_version=api_version,
)
mock_ads_hook.return_value.search.assert_called_once_with(
client_ids=CLIENT_IDS, query=QUERY, page_size=10000
client_ids=CLIENT_IDS, query=QUERY
)
mock_gcs_hook.assert_called_once_with(
gcp_conn_id=gcp_conn_id,
Expand Down