Skip to content

Commit

Permalink
🎉 Source Facebook Marketing: fix schema for 'breakdowns' fields (#8742)
Browse files Browse the repository at this point in the history
* fix schema for 'breakdowns' and 'action_breakdowns fields

Signed-off-by: Sergey Chvalyuk <grubberr@gmail.com>
  • Loading branch information
grubberr authored Dec 17, 2021
1 parent 212c1ff commit 0d7101e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
- name: Facebook Marketing
sourceDefinitionId: e7778cfc-e97c-4458-9ecb-b4f2bba8946c
dockerRepository: airbyte/source-facebook-marketing
dockerImageTag: 0.2.27
dockerImageTag: 0.2.28
documentationUrl: https://docs.airbyte.io/integrations/sources/facebook-marketing
icon: facebook.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-facebook-marketing:0.2.27"
- dockerImage: "airbyte/source-facebook-marketing:0.2.28"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/facebook-marketing"
changelogUrl: "https://docs.airbyte.io/integrations/sources/facebook-marketing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.2.27
LABEL io.airbyte.version=0.2.28
LABEL io.airbyte.name=airbyte/source-facebook-marketing
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"properties": {
"action_device": { "type": ["null", "string"] },
"action_canvas_component_name": { "type": ["null", "string"] },
"action_carousel_card_id": { "type": ["null", "string"] },
"action_carousel_card_name": { "type": ["null", "string"] },
"action_destination": { "type": ["null", "string"] },
"action_reaction": { "type": ["null", "string"] },
"action_target_id": { "type": ["null", "string"] },
"action_type": { "type": ["null", "string"] },
"action_video_sound": { "type": ["null", "string"] },
"action_video_type": { "type": ["null", "string"] }
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{
"properties": {
"action_device": { "type": ["null", "string"] },
"action_canvas_component_name": { "type": ["null", "string"] },
"action_carousel_card_id": { "type": ["null", "string"] },
"action_carousel_card_name": { "type": ["null", "string"] },
"action_destination": { "type": ["null", "string"] },
"action_reaction": { "type": ["null", "string"] },
"action_target_id": { "type": ["null", "string"] },
"action_type": { "type": ["null", "string"] },
"action_video_sound": { "type": ["null", "string"] },
"action_video_type": { "type": ["null", "string"] },
"ad_format_asset": { "type": ["null", "string"] },
"age": { "type": ["null", "string"] },
"app_id": { "type": ["null", "string"] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,10 @@ def _update_insights_streams(self, insights, args, streams) -> List[Type[Stream]

def _check_custom_insights_entries(self, insights: List[Mapping[str, Any]]):

default_fields = list(
ResourceSchemaLoader(package_name_from_class(self.__class__)).get_schema("ads_insights").get("properties", {}).keys()
)
default_breakdowns = list(
ResourceSchemaLoader(package_name_from_class(self.__class__)).get_schema("ads_insights_breakdowns").get("properties", {}).keys()
)
default_actions_breakdowns = [e for e in default_breakdowns if "action_" in e]
loader = ResourceSchemaLoader(package_name_from_class(self.__class__))
default_fields = list(loader.get_schema("ads_insights").get("properties", {}).keys())
default_breakdowns = list(loader.get_schema("ads_insights_breakdowns").get("properties", {}).keys())
default_action_breakdowns = list(loader.get_schema("ads_insights_action_breakdowns").get("properties", {}).keys())

for insight in insights:
if insight.get("fields"):
Expand All @@ -224,7 +221,7 @@ def _check_custom_insights_entries(self, insights: List[Mapping[str, Any]]):
message = f"{value} is not a valid breakdown name"
raise Exception("Config validation error: " + message) from None
if insight.get("action_breakdowns"):
value_checked, value = self._check_values(default_actions_breakdowns, insight.get("action_breakdowns"))
value_checked, value = self._check_values(default_action_breakdowns, insight.get("action_breakdowns"))
if not value_checked:
message = f"{value} is not a valid action_breakdown name"
raise Exception("Config validation error: " + message) from None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,13 @@ def get_json_schema(self) -> Mapping[str, Any]:
"""Add fields from breakdowns to the stream schema
:return: A dict of the JSON schema representing this stream.
"""
schema = ResourceSchemaLoader(package_name_from_class(self.__class__)).get_schema("ads_insights")
loader = ResourceSchemaLoader(package_name_from_class(self.__class__))
schema = loader.get_schema("ads_insights")
if self._fields:
schema["properties"] = {k: v for k, v in schema["properties"].items() if k in self._fields}
schema["properties"].update(self._schema_for_breakdowns())
if self.breakdowns:
breakdowns_properties = loader.get_schema("ads_insights_breakdowns")["properties"]
schema["properties"].update({prop: breakdowns_properties[prop] for prop in self.breakdowns})
return schema

@cached_property
Expand All @@ -416,25 +419,6 @@ def fields(self) -> List[str]:
schema = ResourceSchemaLoader(package_name_from_class(self.__class__)).get_schema("ads_insights")
return list(schema.get("properties", {}).keys())

def _schema_for_breakdowns(self) -> Mapping[str, Any]:
"""Breakdown fields and their type"""
schemas = {
"age": {"type": ["null", "integer", "string"]},
"gender": {"type": ["null", "string"]},
"country": {"type": ["null", "string"]},
"dma": {"type": ["null", "string"]},
"region": {"type": ["null", "string"]},
"impression_device": {"type": ["null", "string"]},
"placement": {"type": ["null", "string"]},
"platform_position": {"type": ["null", "string"]},
"publisher_platform": {"type": ["null", "string"]},
}
breakdowns = self.breakdowns[:]
if "platform_position" in breakdowns:
breakdowns.append("placement")

return {breakdown: schemas[breakdown] for breakdown in self.breakdowns}

def _date_ranges(self, stream_state: Mapping[str, Any]) -> Iterator[dict]:
"""Iterate over period between start_date/state and now
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/facebook-marketing.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ As a summary, custom insights allows to replicate only some fields, resulting in

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.2.28 | 2021-12-13 | [8742](https://github.com/airbytehq/airbyte/pull/8742) | Fix for schema generation related to "breakdown" fields |
| 0.2.27 | 2021-11-29 | [8257](https://github.com/airbytehq/airbyte/pull/8257) | Add fields to Campaign stream |
| 0.2.26 | 2021-11-19 | [7855](https://github.com/airbytehq/airbyte/pull/7855) | Add Video stream |
| 0.2.25 | 2021-11-12 | [7904](https://github.com/airbytehq/airbyte/pull/7904) | Implement retry logic for async jobs |
Expand Down

0 comments on commit 0d7101e

Please sign in to comment.