haleemur_ali
04/23/2023, 9:47 PM{
"className": "entityName",
"keyName": "primaryKeyName",
"keyValue": "primaryKeyValue",
"fieldRows": [
{
"fieldName": "fieldName1",
"fieldValue": "fieldValue1"
},
{
"fieldName": "customFieldName2",
"fieldValue": "customFieldValue2"
}
]
}
The number of fields in "fieldRows" is unknown and can evolve.
I'd like to reshape the data as follows before sending it to the target, and have the target schema evolve when new fields are added.
{
"primaryKeyName": "primaryKeyValue",
"fieldName1": "fieldValue1",
"fieldName2": "fieldValue2"
}
Essentially, the transformation logic would be something like below for each record returned by this endpoint.
def flatten(row):
flat = {row["keyName"]: row["keyValue"]}
for item in row["fieldRows"]:
flat[item["fieldName"]] = item["fieldValue"]
return flat
this is the schema of what the endpoint returns
{
"$schema": "<http://json-schema.org/schema#>",
"type": "object",
"key_properties": [
"className",
"keyName",
"keyValue"
],
"bookmark_properties": [],
"properties": {
"fieldRows": {
"type": "array",
"items": {
"type": "object",
"properties": {
"fieldName": {
"type": "string"
},
"fieldValue": {
"type": "string"
}
}
}
},
"className": {
"type": "string"
},
"keyName": {
"type": "string"
},
"keyValue": {
"type": "string"
}
}
}pat_nadolny
04/25/2023, 2:27 PM--discover call to the tap to generate a json schema (in your case it would probably be dynamic schema based on a recent sample of the fieldRows data) thats then passed to the target before starting the sync. In most implementations the target will assert that the records all match that schema before writing to the destination. If you started the sync expecting only fieldName1 to exist then fieldName2 showed up then you'd get an error.pat_nadolny
04/25/2023, 2:34 PMfieldRows into one nested object field like
{
"primaryKeyName": "primaryKeyValue",
"fieldRows": {
"fieldName1": "fieldValue1",
"fieldName2": "fieldValue2"
}
}
then use the target record flattening setting to unnest those for you to create a table structure like:
primaryKeyName, fieldRows.fieldName1, fieldName1.fieldName2
primaryKeyValue, fieldValue1, fieldValue2
then if that object grows the target will append a new column based on the key that was added. This would bypass the issue with the schema changing because all records would pass validation since the schema is static and contains the fieldRows as an object with key value pairs.pat_nadolny
04/25/2023, 2:40 PMhaleemur_ali
05/03/2023, 11:11 PM