ofer_kulka
12/03/2020, 6:30 PMtap facebook-ads
and loader target-snowflake
to pull facebook-ads api data into our data warehouse.
We are running into an error which suggests one or more of the field-names in the table ADS_INSIGHTS__UNIQUE_ACTIONS
cannot be pulled because it begins with a numeric character.
target-snowflake | target_snowflake.exceptions.SnowflakeError: ('Exception writing records', SQLError('Identifier must only contain alphanumerics, or underscores, and start with alphas. Got `a` for `1D_CLICK`',))
In order to bypass the error, we tried to exclude the table from being pulled entirely but the error persists no matter what patterns we try to define in order to exclude the table (meaning the table is pulled regardless of what exclusion syntax we include).
We have configured the tap
the following way (last version):
meltano select --list tap-facebook
Legend:
selected
excluded
automatic
Enabled patterns:
ads_insights_age_and_gender.*
ads_insights_region.*
ads_insights_country.*
ads_insights_platform_and_device.*
ads_insights.engagement_rate_ranking
ads_insights.cost_per_unique_click
ads_insights.reach
ads_insights.inline_link_clicks
ads_insights.account_id
ads_insights.adset_id
ads_insights.video_p50_watched_actions
ads_insights.video_30_sec_watched_actions
ads_insights.date_stop
ads_insights.clicks
ads_insights.video_p25_watched_actions
ads_insights.canvas_avg_view_time
ads_insights.quality_ranking
ads_insights.ad_name
ads_insights.conversion_rate_ranking
ads_insights.outbound_clicks
ads_insights.video_play_curve_actions
ads_insights.unique_inline_link_click_ctr
ads_insights.cost_per_unique_inline_link_click
ads_insights.inline_post_engagement
ads_insights.website_ctr
ads_insights.unique_actions
ads_insights.spend
ads_insights.adset_name
ads_insights.action_values
ads_insights.actions
ads_insights.impressions
ads_insights.canvas_avg_view_percent
ads_insights.unique_clicks
ads_insights.video_p100_watched_actions
ads_insights.account_name
ads_insights.cost_per_action_type
ads_insights.objective
ads_insights.ctr
ads_insights.cpp
ads_insights.ad_id
ads_insights.inline_link_click_ctr
ads_insights.unique_inline_link_clicks
ads_insights.campaign_name
ads_insights.social_spend
ads_insights.cpm
ads_insights.cost_per_inline_link_click
ads_insights.unique_ctr
ads_insights.campaign_id
ads_insights.cost_per_inline_post_engagement
ads_insights.frequency
ads_insights.date_start
ads_insights.unique_link_clicks_ctr
ads_insights.video_p75_watched_actions
ads_insights.cpc
!*.*unique_actions*.*
"table": "ADS_INSIGHTS__UNIQUE_ACTIONS", "status": "failed"
"path": ["ads_insights", "unique_actions"]
Please see the log below:douwe_maan
12/03/2020, 6:37 PM!*.*unique_actions*.*
rule from taking effect.douwe_maan
12/03/2020, 6:38 PMmeltano.yml
:
extractors:
- name: tap-facebook
# ...
metadata:
'*':
'*.*':
inclusion: available
douwe_maan
12/03/2020, 6:39 PMmeltano select tap-facebook --list
and ads_insights.unique_actions
and its subprops should no longer show up under "Selected attributes"douwe_maan
12/03/2020, 6:40 PM!*.*unique_actions*.*
to !*.unique_actions
douwe_maan
12/03/2020, 6:42 PMdouwe_maan
12/03/2020, 6:43 PM- !*.*.1d_click
- !*.*.7d_click
- !*.*.28d_click
- !*.*.1d_view
- !*.*.7d_view
- !*.*.28d_view
douwe_maan
12/03/2020, 6:43 PMofer_kulka
12/03/2020, 7:08 PMads_insights__unique_actions
, perhaps that is one of our mistakes.
This is a piece of the log file that caught our attention:
"table": "ADS_INSIGHTS__UNIQUE_ACTIONS", "status": "failed"
"path": ["ads_insights", "unique_actions"]
But perhaps it's our incorrect interpretation of which object the error is occurring against.
Definitely could also go via the route of excluding the number fields, does the transformation feature convert them into non number field-names?
- !*.*.1d_click
- !*.*.7d_click
- !*.*.28d_click
- !*.*.1d_view
- !*.*.7d_view
- !*.*.28d_view
douwe_maan
12/03/2020, 7:16 PMads_insights
stream has a unique_actions
property containing an array of objects with 1d_click
(etc) subproperties. It looks like target-snowflake is flattening ads_insights.unique_actions
into its own ADS_INSIGHTS__UNIQUE_ACTIONS
table with 1d_click
(etc) columns, while other targets may leave a unique_actions
column on the ads_insights
table with a (JSON-encoded) array valuedouwe_maan
12/03/2020, 7:17 PM1d_click
is not a direct subproperty of unique_actions
, the selection rules I suggested above may not actually work, because Meltano doesn't currently drill down into array valuesdouwe_maan
12/03/2020, 7:18 PM!*.unique_actions
should still work to drop that field entirely, and prevent a table from being created for it, and you'd want to do the same for the other stream properties that use that ads_action_stats.json
douwe_maan
12/03/2020, 7:23 PMumut_yalcinkaya
12/04/2020, 7:33 AMmetadata
field:
metadata:
'*':
'*.*':
inclusion: available
I've just excluded:
- !*.*.1d_click
- !*.*.7d_click
- !*.*.28d_click
- !*.*.1d_view
- !*.*.7d_view
- !*.*.28d_view
umut_yalcinkaya
12/04/2020, 7:36 AMyaml.constructor.ConstructorError: could not determine a constructor for the tag '!*.*.1d_click'
in "/project/meltano.yml", line 97, column 7
douwe_maan
12/04/2020, 3:45 PM!*.*...
patterns in double quotes; it looks like YAML is currently trying to parse them as something other than stringsumut_yalcinkaya
12/04/2020, 7:58 PMexclude
statements. Is it possible to make a small call to check with you on Monday ? We are about run elt
jobs in production.douwe_maan
12/04/2020, 8:33 PMSeems like workaround is useless. Generally, something wrong withDid you see https://meltano.slack.com/archives/C013EKWA2Q1/p1607023075197800?thread_ts=1607020241.194800&cid=C013EKWA2Q1 and https://meltano.slack.com/archives/C013EKWA2Q1/p1607023126198000?thread_ts=1607020241.194800&cid=C013EKWA2Q1?statements.exclude
douwe_maan
12/04/2020, 8:34 PMIs it possible to make a small call to check with you on Monday?Gladly, do you see a time on https://calendly.com/douwem/half-hour-meeting?month=2020-12&date=2020-12-07 that might work?
umut_yalcinkaya
12/07/2020, 9:10 AMofer_kulka
12/07/2020, 1:53 PMdouwe_maan
12/07/2020, 6:06 PMofer_kulka
12/07/2020, 6:38 PMdouwe_maan
12/07/2020, 6:58 PMdouwe_maan
12/07/2020, 6:59 PMofer_kulka
12/08/2020, 8:42 AMdouwe_maan
12/08/2020, 2:58 PMofer_kulka
12/08/2020, 3:16 PMdouwe_maan
12/08/2020, 5:02 PMdouwe_maan
12/08/2020, 5:02 PMofer_kulka
12/08/2020, 5:04 PMdouwe_maan
12/08/2020, 6:22 PMdouwe_maan
12/08/2020, 6:23 PMofer_kulka
12/08/2020, 6:49 PMdouwe_maan
12/08/2020, 9:38 PMdouwe_maan
12/08/2020, 9:44 PM@deselected-fields
from the pip_url
again!douwe_maan
12/08/2020, 9:50 PMumut_yalcinkaya
12/10/2020, 7:17 AMtarget-snowflake | INFO MillisLoggingCursor: 86 millis spent executing: \n SHOW TABLES LIKE 'ADS_INSIGHTS_AGE_AND_GENDER' IN SCHEMA "MARKETING"."ANALYTICS" \n
target-snowflake | INFO MillisLoggingCursor: 551 millis spent executing: \n SELECT column_name, data_type, is_nullable \n FROM "MARKETING".information_schema.columns \n WHERE table_schema = 'ANALYTICS' AND table_name = 'ADS_INSIGHTS_AGE_AND_GENDER' \n
target-snowflake | INFO MillisLoggingCursor: 58 millis spent executing: ROLLBACK
target-snowflake | ERROR Exception writing records
target-snowflake | Traceback (most recent call last):
target-snowflake | File "/app/.meltano/loaders/target-snowflake/venv/lib/python3.8/site-packages/target_snowflake/snowflake.py", line 119, in write_batch
target-snowflake | json_schema.get_type(current_table_schema['schema']['properties'][key_property]),
target-snowflake | KeyError: 'age'
target-snowflake | CRITICAL ('Exception writing records', KeyError('age'))
target-snowflake | INFO MillisLoggingCursor: 60 millis spent executing: ROLLBACK
target-snowflake | Traceback (most recent call last):
target-snowflake | File "/app/.meltano/loaders/target-snowflake/venv/lib/python3.8/site-packages/target_snowflake/snowflake.py", line 119, in write_batch
target-snowflake | json_schema.get_type(current_table_schema['schema']['properties'][key_property]),
target-snowflake | KeyError: 'age'
target-snowflake |
target-snowflake | During handling of the above exception, another exception occurred:
target-snowflake |
target-snowflake | Traceback (most recent call last):
target-snowflake | File "/app/.meltano/loaders/target-snowflake/venv/bin/target-snowflake", line 8, in <module>
target-snowflake | sys.exit(cli())
target-snowflake | File "/app/.meltano/loaders/target-snowflake/venv/lib/python3.8/site-packages/target_snowflake/__init__.py", line 57, in cli
target-snowflake | main(args.config)
target-snowflake | File "/app/.meltano/loaders/target-snowflake/venv/lib/python3.8/site-packages/target_snowflake/__init__.py", line 51, in main
target-snowflake | target_tools.main(target)
target-snowflake | File "/app/.meltano/loaders/target-snowflake/venv/lib/python3.8/site-packages/target_postgres/target_tools.py", line 28, in main
target-snowflake | stream_to_target(input_stream, target, config=config)
target-snowflake | File "/app/.meltano/loaders/target-snowflake/venv/lib/python3.8/site-packages/target_postgres/target_tools.py", line 77, in stream_to_target
target-snowflake | raise e
target-snowflake | File "/app/.meltano/loaders/target-snowflake/venv/lib/python3.8/site-packages/target_postgres/target_tools.py", line 70, in stream_to_target
target-snowflake | state_tracker.flush_streams(force=True)
target-snowflake | File "/app/.meltano/loaders/target-snowflake/venv/lib/python3.8/site-packages/target_postgres/stream_tracker.py", line 47, in flush_streams
target-snowflake | self._write_batch_and_update_watermarks(stream)
target-snowflake | File "/app/.meltano/loaders/target-snowflake/venv/lib/python3.8/site-packages/target_postgres/stream_tracker.py", line 67, in _write_batch_and_update_watermarks
target-snowflake | self.target.write_batch(stream_buffer)
target-snowflake | File "/app/.meltano/loaders/target-snowflake/venv/lib/python3.8/site-packages/target_snowflake/snowflake.py", line 164, in write_batch
target-snowflake | raise SnowflakeError(message, ex)
target-snowflake | target_snowflake.exceptions.SnowflakeError: ('Exception writing records', KeyError('age'))
meltano | Loading failed (1): target_snowflake.exceptions.SnowflakeError: ('Exception writing records', KeyError('age'))
meltano | ELT could not be completed: Target failed
umut_yalcinkaya
12/10/2020, 7:17 AM@deselected-fields
and run meltano elt tap-facebook target-snowflake
. So it prompts below message. Seems like a key error when parsing age
field on ADS_INSIGHTS_AGE_AND_GENDER
table.ofer_kulka
12/10/2020, 5:27 PMdouwe_maan
12/10/2020, 5:31 PMage
property in the schema doesn't match the type that was actually created in the DBdouwe_maan
12/10/2020, 5:31 PMdouwe_maan
12/10/2020, 5:32 PMmeltano elt
in debug mode using meltano --log-level=debug elt
so that we get to see the offending SCHEMA
message for ADS_INSIGHTS_AGE_AND_GENDER?douwe_maan
12/10/2020, 5:34 PMprint
statements ahead of https://github.com/datamill-co/target-snowflake/blob/master/target_snowflake/snowflake.py#L114 so that we can find out what is actually contained in current_table_schema
at the time the error is raised, and what the values of self.json_schema_to_sql_type(remote_column_schema)
and self.json_schema_to_sql_type(stream_buffer.schema['properties'][key_property])
aredouwe_maan
12/10/2020, 5:48 PMumut_yalcinkaya
12/10/2020, 6:24 PMmeltano --log-level=debug elt tap-facebook target-snowflake
. As @ofer_kulka said, dropping destination schema working around the issue.
https://meltano.slack.com/archives/C013EKWA2Q1/p1607621277222300?thread_ts=1607020241.194800&cid=C013EKWA2Q1douwe_maan
12/10/2020, 6:25 PMSCHEMA
message for the ADS_INSIGHTS_AGE_AND_GENDER
stream that was printed in a tap-facebook (out)
line?douwe_maan
12/10/2020, 6:28 PMdouwe_maan
12/10/2020, 6:28 PMofer_kulka
12/10/2020, 8:01 PMdouwe_maan
12/10/2020, 8:57 PMdeselected-fields
branch Umut and I were using and got working yesterday, so nothing should have changed between those points.
This new error could be related to the bug fix, but it doesn't look like it to me on the surface. Seeing the SCHEMA messages would help say that for sure 🙂
My hunch is that we're looking at something similar to https://meltano.slack.com/archives/CFG3C3C66/p1606866556000500?thread_ts=1605650543.370000&cid=CFG3C3C66, where the problem is with the age
column claiming possible types integer
, string
, and null
, which the database can't represent, which could lead to the target complaining about the mismatch between the stream schema and the existing database schema, as we're seeing.douwe_maan
12/10/2020, 9:02 PMSCHEMA
message for the offending stream, as well as the values for self.json_schema_to_sql_type(remote_column_schema)
and self.json_schema_to_sql_type(stream_buffer.schema['properties'][key_property])
at the mentioned code site, since their mismatch causes the error we're seeingofer_kulka
12/11/2020, 1:41 PMdouwe_maan
12/17/2020, 3:38 PMofer_kulka
12/17/2020, 3:41 PMofer_kulka
12/17/2020, 3:41 PMdouwe_maan
12/17/2020, 3:44 PMdouwe_maan
12/17/2020, 3:45 PMumut_yalcinkaya
12/17/2020, 5:48 PMdouwe_maan
12/17/2020, 5:49 PMdouwe_maan
12/17/2020, 6:00 PMdouwe_maan
12/17/2020, 6:27 PMdouwe_maan
12/17/2020, 6:28 PMpip_url: git+<https://gitlab.com/meltano/tap-facebook.git@age-property-type>
ofer_kulka
12/17/2020, 6:30 PMdouwe_maan
12/17/2020, 6:31 PM