1
0
mirror of synced 2025-12-23 21:03:15 -05:00

Source Google Ads: improve GAQL parser error messages (#25947)

Signed-off-by: Sergey Chvalyuk <grubberr@gmail.com>
This commit is contained in:
Serhii Chvaliuk
2023-05-16 14:46:05 +03:00
committed by GitHub
parent d756940092
commit 08fe992c43
8 changed files with 22 additions and 11 deletions

View File

@@ -14139,7 +14139,7 @@
"sourceDefinitionId": "253487c0-2246-43ba-a21f-5116b20a2c50",
"name": "Google Ads",
"dockerRepository": "airbyte/source-google-ads",
"dockerImageTag": "0.2.17",
"dockerImageTag": "0.2.18",
"documentationUrl": "https://docs.airbyte.com/integrations/sources/google-ads",
"icon": "google-adwords.svg",
"sourceType": "api",

View File

@@ -805,7 +805,7 @@
- name: Google Ads
sourceDefinitionId: 253487c0-2246-43ba-a21f-5116b20a2c50
dockerRepository: airbyte/source-google-ads
dockerImageTag: 0.2.17
dockerImageTag: 0.2.18
documentationUrl: https://docs.airbyte.com/integrations/sources/google-ads
icon: google-adwords.svg
sourceType: api

View File

@@ -5795,7 +5795,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-google-ads:0.2.17"
- dockerImage: "airbyte/source-google-ads:0.2.18"
spec:
documentationUrl: "https://docs.airbyte.com/integrations/sources/google-ads"
connectionSpecification:

View File

@@ -13,5 +13,5 @@ COPY main.py ./
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
LABEL io.airbyte.version=0.2.17
LABEL io.airbyte.version=0.2.18
LABEL io.airbyte.name=airbyte/source-google-ads

View File

@@ -6,7 +6,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 253487c0-2246-43ba-a21f-5116b20a2c50
dockerImageTag: 0.2.17
dockerImageTag: 0.2.18
dockerRepository: airbyte/source-google-ads
githubIssueLabel: source-google-ads
icon: google-adwords.svg

View File

@@ -28,7 +28,7 @@ class GAQL:
r"""\s*
SELECT\s+(?P<FieldNames>\S.*)
\s+
FROM\s+(?P<ResourceName>[a-z]([a-zA-Z_])*)
FROM\s+(?P<ResourceNames>[a-z][a-zA-Z_]*(\s*,\s*[a-z][a-zA-Z_]*)*)
\s*
(\s+WHERE\s+(?P<WhereClause>\S.*?))?
(\s+ORDER\s+BY\s+(?P<OrderByClause>\S.*?))?
@@ -57,7 +57,12 @@ class GAQL:
if not cls.REGEX_FIELD_NAME.match(field):
raise query_error
resource_name = m.group("ResourceName")
resource_names = re.split(r"\s*,\s*", m.group("ResourceNames"))
if len(resource_names) > 1:
message = f"Incorrect GAQL query: multiple resources '{', '.join(resource_names)}' is not allowed"
raise AirbyteTracedException(message=message, internal_message=message, failure_type=FailureType.config_error)
resource_name = resource_names[0]
where = cls._normalize(m.group("WhereClause") or "")
order_by = cls._normalize(m.group("OrderByClause") or "")
limit = m.group("LimitClause")

View File

@@ -3,6 +3,7 @@
#
import pytest
from airbyte_cdk.utils import AirbyteTracedException
from source_google_ads.utils import GAQL
@@ -70,17 +71,21 @@ def test_parse_GAQL_ok():
def test_parse_GAQL_fail():
with pytest.raises(Exception) as e:
with pytest.raises(AirbyteTracedException) as e:
GAQL.parse("SELECT field1, field2 FROM x_Table2")
assert str(e.value) == "Incorrect GAQL query statement: 'SELECT field1, field2 FROM x_Table2'"
with pytest.raises(Exception) as e:
with pytest.raises(AirbyteTracedException) as e:
GAQL.parse("SELECT field1, field2 FROM x_Table WHERE ")
with pytest.raises(Exception) as e:
with pytest.raises(AirbyteTracedException) as e:
GAQL.parse("SELECT field1, , field2 FROM table")
with pytest.raises(Exception) as e:
with pytest.raises(AirbyteTracedException) as e:
GAQL.parse("SELECT fie ld1, field2 FROM table")
with pytest.raises(AirbyteTracedException) as e:
GAQL.parse("SELECT field1, field2 FROM customer, campaign_labels")
assert str(e.value) == "Incorrect GAQL query: multiple resources 'customer, campaign_labels' is not allowed"
@pytest.mark.parametrize(
"query, fields",

View File

@@ -141,6 +141,7 @@ Due to a limitation in the Google Ads API which does not allow getting performan
| Version | Date | Pull Request | Subject |
|:---------|:-----------|:---------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------|
| `0.2.18` | 2023-05-15 | [25947](https://github.com/airbytehq/airbyte/pull/25947) | Improve GAQL parser error message if multiple resources provided |
| `0.2.17` | 2023-05-11 | [25987](https://github.com/airbytehq/airbyte/pull/25987) | Categorized Config Errors Accurately |
| `0.2.16` | 2023-05-10 | [25965](https://github.com/airbytehq/airbyte/pull/25965) | Fix Airbyte date-time data-types |
| `0.2.14` | 2023-03-21 | [24945](https://github.com/airbytehq/airbyte/pull/24945) | for custom google query fixed schema type for "data_type: ENUM" and "is_repeated: true" to array of strings |