Infinite Dynamic Properties in Source Stream Cont...
# replication-troubleshooting
d
Infinite Dynamic Properties in Source Stream Context • I am working on a PR to support the Profiles API for Klaviyo • The endpoint returns an array of profiles which has an object that can have infinite dynamic properties. Ex:
Copy code
{
  "properties": {
    "CUSTOM_KEY_1": INT|STR|ARRAY,
    "CUSTOM_KEY_2": ...,
    ...
  }
}
Problem • There is no way to detect this property list besides listing every item from the endpoint (a full refresh) • A full refresh will take over an hour for users with >= 500,000 leads in Klaviyo ◦ 60 requests per second, 100 max page size => (500000)/(6000) = 83 minutes Investigation • I have looked through the codebase trying to find an example of supporting an object with a dynamic number of properties. I cannot find such a use case. • Codebase Examples ◦ The Airtable integration has top-level "Base" or "Table" concepts which would have very few entities. It extracts the properties from there ◦ The Mixpanel integration seems to be doing a full refresh of every Profile in Mixpanel to do this Options • (Love) A better solution from someone in this chat • (Like) Find a way to store a JSONB column with this dynamic list of properties and allow Airbyte customers to handle extractions themselves • (Dislike) Behave like the Mixpanel integration and do a full refresh to determine properties.
✅ 1
s
@Dustin Pearson I would think the second option (putting them in a container object) would be the way to go here. It would at least write it as JSON to the destination and allow querying it etc.
d
@Sherif Nada Could you help me find an example for handling it this way? I'm struggling to find such a case. I tried to have the following
profiles.json
file, but when I actually used this as a custom connector, the
properties
key still displayed as null:
Copy code
{
  "type": "object",
  "properties": {
    "type": { "type": "string" },
    "id": { "type": "string" },
    "updated": { "type": "string", "format": "date-time" },
    "properties": { "type": "object" },
  }
}
Is there some other customization that I need to do in the code or schema to ensure we can push to the properties column even though it has no additional definition beyond the type?
s
where is it displayed as null? in the output of the source connector in the CLI/terminal?
d
@Sherif Nada I configured a custom connector with the following: Creation of Custom Connector https://github.com/airbytehq/airbyte/pull/23968 • Exactly the same as this PR, except I modified
profiles.json
to have the configuration above instead of what is in the PR • I created pushed a private docker container and used it as a custom connector Data • Inside of the database
_klaviyo_test
schema: ◦ We have a
_airtable_raw_profiles
table which contains the full expected response, including the full properties for each profile. • We have a
profiles
table at which contains just a null value for each row in this column
s
To help narrow down on the problem can you confirm the connector outputs those fields when you run it from the command line?
d
@Sherif Nada I am not sure of how to run it from the command line. Which output do we mean exactly?
m
@Dustin Pearson there is a README file in the connector folder with instructions
d
If "run the connector" just means run
python main.py read --config secrets/config.json --catalog integration_tests/configured_catalog.json
, then yes, it includes those fields Here is one of the profiles that are output from running that command:
Copy code
{
  "type": "RECORD",
  "record": {
    "stream": "profiles",
    "data": {
      "type": "profile",
      "id": "OBFUSCATE_ID",
      "attributes": {
        "email": "test@nutrisense.io",
        "phone_number": null,
        "external_id": null,
        "anonymous_id": null,
        "first_name": "FAKE_FIRST",
        "last_name": "FAKE_LAST",
        "organization": null,
        "title": null,
        "image": null,
        "created": "2023-01-27T14:06:06+00:00",
        "updated": "2023-02-27T15:14:06+00:00",
        "last_event_date": "2023-01-27T14:06:09+00:00",
        "location": {
          "address1": null,
          "address2": null,
          "city": null,
          "country": null,
          "latitude": null,
          "longitude": null,
          "region": null,
          "zip": null,
          "timezone": null
        },
        "properties": {
          "Full Name": "FIRSTNAME LASTNAME",
          "Subscribed To": [
            "Marketing",
            "Account",
            "Newsletter",
            "Promotions"
          ],
          "Newsletter - Subscription - Source": "checkout",
          "Registration - Date Created": "2023-01-27T14:06:03Z",
          "Eng Identify User Origin": null
        },
        "subscriptions": {
          "email": {
            "marketing": {
              "consent": "NEVER_SUBSCRIBED",
              "timestamp": null,
              "method": null,
              "method_detail": null,
              "custom_method_detail": null,
              "double_optin": null,
              "suppressions": [],
              "list_suppressions": []
            }
          },
          "sms": {
            "marketing": null
          }
        }
      },
      "links": {
        "self": "https://a.klaviyo.com/api/profiles/OBFUSCATE_ID/"
      },
      "relationships": {
        "lists": {
          "links": {
            "self": "https://a.klaviyo.com/api/profiles/OBFUSCATE_ID/relationships/lists/",
            "related": "https://a.klaviyo.com/api/profiles/OBFUSCATE_ID/lists/"
          }
        },
        "segments": {
          "links": {
            "self": "https://a.klaviyo.com/api/profiles/OBFUSCATE_ID/relationships/segments/",
            "related": "https://a.klaviyo.com/api/profiles/OBFUSCATE_ID/segments/"
          }
        }
      },
      "updated": "2023-02-27T15:14:06+00:00"
    },
    "emitted_at": 1679077848765
  }
}
Since the data being discussed is fully present in the table
_airbyte_raw_profiles
, the issue is definitely related to the data normalization, right? I cannot find clear instructions on how to test that
s
Ah I see my apologies I misread your previous message. Yes this feels like a normalization issue. Could you expand the profiles stream row so I can see what airbyte identifies as the schema of each column?
d
@Sherif Nada I think this bug could be entirely my fault. The following happened: • I created a custom connector with version v0.2.1 which had properties as a null object using the
["object", null"]
notation • I created v0.2.2 of the connector with just
"object"
for properties • I failed to refresh the source schema I've just went through the process of refreshing the source schema and see that the Data type switched from
nullobject
->
object
Weirdly, when we have a nullobject, the UI still displays the Data Type as "Object" so it isn't immediately clear
I'll rerun a full sync with the updated schema and update on whether it solves this
@Sherif Nada Unfortunately, even with the resync, no data is appearing in the properties column of our
_klaviyo_test
.
profiles
table. Here is a screenshot of the schema. There aren't any nested properties
s
Yeah this feels like a normalization problem
d
For now, I'll leave my PR as-is since anyone using the integration that cares can just pull directly from
airbyte_raw_profiles
In that case, I guess I'll just wait for a member of the airbyte team to review the PR.
Thanks for the help @Sherif Nada!
s
<!subteam^S046RT7CEM6> is this a known issue in normalization? stream
profiles
has field
properties: {type: object, additionalProperties: true}
. The value of this field is propagated to _`profiles_raw` in postgres but the normalized table
profiles
only has nulls in that column.
r
This sounds like a known issue when the usage of
type: [some_data_type_here, object]
is set and also the case with nested objects. Github issue: Normalization handles
type: [X, object]
schemas
As for support for
jsonb
that is actually something we're actively looking to prioritize, @Edward Gao (Airbyte) is leading the charge for that feature and will let him speak more about that Regarding your normalized table still showing
null
values, is the entire
profiles.properties
column
null
or are the most recent syncs including
objects
in that column? Suspect the issue is because normalization is executing on the most recent records synced not all the existing data in
_airbyte_raw_profiles
.
d
@Ryan Fu (Airbyte) With a schema of:
"properties": { "type": "object" }
I did: • Refresh source schema and reset data • Multiple syncs of thousands of updated records Result: • Still the
properties
column in the
profiles
table is null.
r
Are you running this sync on a local
:dev
instance of
source-klaviyo
? In the PR you linked I still see
"properties": { "type": ["null", "object"] }
. In the past, I've seen instances where rebuilding a
dev
version of a connector and running syncs locally the
dev
connector doesn't actually pick up the changes. It may not be the case here, however,
"properties": { "type": "object" }
has been successful for other connections so this would either be some regression in normalization or the
schema
is being passed in with the
[null, object]
still Could you connect to the airbyte-db and see within your
connection
table what the catalog looks like? it should include the schema being passed into
normalization
, if your catalog is indeed showing
"properties": { "type": "object" }
then more investigation needs to be done
d
Hi @Ryan Fu (Airbyte). I never updated the PR, but I am certain that I did the following: • Changed the schema to match
"properties": { "type": "object" }
• Built and published a new docker image with a new version to ECR • SSH into my airbyte container on GCP and pull the tagged docker image • Visit airbyte console and switch to new version of docker image • Visit airbyte console and click "Refresh source schema" ◦ See screenshot below of when that happened • Check yes to reload full schema ◦ This triggered deletion of all rows and resynced everything
Just in case, I queried the
connections
table in the airbyte postgres database we have on google cloud. It gave this output:
Copy code
{
  "streams": [
    {
      "stream": {
        "name": "profiles",
        "json_schema": {
          "type": "object",
          "properties": {
            "id": {"type": "string"},
            "type": {"type": "string"},
            "links": {"type": ["null", "object"]},
            "updated": {"type": "string", "format": "date-time"},
            "segments": {"type": ["null", "object"]},
            "attributes": {
              "type": "object",
              "properties": {
                "email": {"type": "string"},
                "title": {"type": "string"},
                "created": {"type": "string", "format": "date-time"},
                "updated": {"type": "string", "format": "date-time"},
                "last_name": {"type": "string"},
                "first_name": {"type": "string"},
                "organization": {"type": "string"},
                "phone_number": {"type": "string"},
                "last_event_date": {"type": "string", "format": "date-time"}
              }
            },
            "properties": {"type": "object"},
            "relationships": {"type": ["null", "object"]},
            "subscriptions": {"type": ["null", "object"]}
          }
        },
        "default_cursor_field": ["updated"],
        "supported_sync_modes": ["full_refresh", "incremental"],
        "source_defined_cursor": true, "source_defined_primary_key": [["id"]]
      },
      "sync_mode": "incremental",
      "primary_key": [["id"]],
      "cursor_field": ["updated"],
      "destination_sync_mode": "append_dedup"
    }
  ]
},
{"units": 1, "timeUnit": "hours"},
f,null,2023-03-17 01:36:13.057445+00,2023-03-17 20:21:54.517078+00,d4af1271-007c-4de5-9531-67fbf44b76a1,basic_schedule,
{
  "basicSchedule": {
    "units": 1,
    "timeUnit": "hours"
  }
}",
AUTO,t,ignore,f,f,
{
  "null/flows": false,
  "null/lists": false,
  "null/events": false,
  "null/metrics": false,
  "null/profiles": false,
  "null/campaigns": false,
  "null/global_exclusions": false
}
If it will help debug, I can do the following: • Push a branch of the exact code I am using • Create a new public docker image of this code that your team can access • Create a new connector relying upon this image • Setup the new connector in our airbyte instance and validate that we are still having the same problem
r
@Dustin Pearson can you push up all the changes for your branch? Based on your catalog you linked there doesn't appear to be any glaring issues so would like to test this locally for myself and see if I can replicate your issue with a running copy of your branch
d
Hi @Ryan Fu (Airbyte) @Marcos Marx (Airbyte), A data engineer with our team discovered that this is likely due to the keyname properties being used. When the data appears inside of
airbyte_raw_profiles
, it actually just nests a new properties key under attributes. I am guessing this is due to some bug in the way the schemas work.
Example API Response:
Copy code
{
 "attributes": {
    "email": "jpires11@icloud.com",
  },
  "properties": {
    "PROPERTY1": "test",
  }
}
Example of how this is being stored:
Copy code
{
   "attributes": {
      "email": "jpires11@icloud.com",
      "properties": {
        "PROPERTY1": "test",
      }
    },
}
We will need to think of a solution to this problem. A simple solution could be to load the properties data into a new field with a different name at the top-level, but maybe someone has a better idea?
Nevermind. Please ignore all of this. I just failed to read JSON appropriately. I was reading the properties field as being adjacent to the attributes field this whole time, even though it was nested inside of it
✅ 2