Transforming multiple rows to the Location Type

#1

Customer data has multiple rows with components of an address such as street address, postal code, city, country, etc.

id addtype text
AA1 postalCode 94107
AA1 streetAddresss xyz California street
AA1. state CA
AA1. country USA

My transform is a switch case on addtype that creates a Location object for each case as follows -
Location.make({id: id, address:{raw:text,components:[{name:text,abbr:’’,types:[{id:‘postal_code’}]})

I was expecting each transform to append to the address.components field, but it seems to be overwriting. As a result, the Location type is populated with the last transformed component, which is

{id: ‘AA1’, address: {raw:‘USA’, components:[{name:‘USA’, abbr:’’, types:[{id:‘country’}]}]}}

One way to fix this is to add the id to InlineAddress, transform each row to the GeoAddressComponent Type and foreign key on the id. Is this the best way to populate a location type from multiple rows?

0 Likes

#2

The components field of the InlineAddress Type is an array field (components: [ GeoAddressComponent ]).

I suspect that when the merge occurs, its overwriting the components field rather than appending an additional element to the array. You can verify this in Console by updating (merge API) a Location record with different components.

A solution is to implement a JS transform that fetches the existing Location record and then appends the address components individually.

0 Likes

#3

Is it possible for multiple threads/workers to process the transform for the same InlineAddress at the same time? If so, will it run into race condition when the transform function does fetch, append, and upsert?

0 Likes

#4

No. Each batch is processed by a single worker.

0 Likes