Hello, I'm setting up a Snowflake destination for ...
# support
e
Hello, I'm setting up a Snowflake destination for my events and noticed that each event in the track call is being synced as it's own table with the properties being flattened out as their own separate columns. Instead of landing in separate tables, I want all the events to land into a single table (like tracks) with all the properties showing up as a JSON column (instead of them being flattened out). There are a few old threads on this topic but none are resolved, can someone shed some light here? Thanks https://rudderstack.slack.com/archives/C01E4PLB135/p1683647068820199 https://rudderstack.slack.com/archives/C01E4PLB135/p1668790380485979
m
Hey There! đź‘‹ Your message has been received by the RudderStack team. Our standard customer support hours are 9-6 PM EST, but we will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
s
Hi Nipun, There are 2 things here 1. Prevent properties from being flattened 2. Send all tracks data to a single table For 1 above, you can use the JSON columns option, see docs . Using this you can mention which columns within the properties object should not be flattened, so if you have this sample request
{
“anonymousId”: “8d872292709c6fbe”,
“context”: {...},
“event”: “Product Clicked”,
“messageId”: “1590431830915-73bed370-5889-436d-9a9e-0c0e0c809d06”,
“properties”: {
“currency”: “USD”,
“testArr”: [1,2,3],
“testmap”: {“nestedMap”: {“a”: 1, “b”: 2}},
“price”: “58.0”
},
“originalTimestamp”: “2020-05-25T183710.917Z”,
“type”: “track”,
“userId”: “sample_user_id”
}
Then you can mention
testArr, testap.nestedMap
and the array will not be flattened and the map will not be flattened beyond the nestedMap level.
For 2 you can use a user transformation to change the event property to a fixed value and move the event property value into the properties object. Original payload > { > “anonymousId”: “8d872292709c6fbe”, > “context”: {...}, > “event”: “Product Clicked”, > “messageId”: “1590431830915-73bed370-5889-436d-9a9e-0c0e0c809d06”, > “properties”: { > “currency”: “USD”, > “testArr”: [1,2,3], > “testmap”: {“nestedMap”: {“a”: 1, “b”: 2}}, > “price”: “58.0” > }, > “originalTimestamp”: “2020-05-25T183710.917Z”, > “type”: “track”, > “userId”: “sample_user_id” > } Your transformation should look like this
Copy code
export function transformEvent(event, metadata) {
    if (event.type !== "track") {
        return event;
    }
    const property = event.event; // Edit event name
    event.properties.event = property;
    event.event = "Track Event"
    return event;
}
Changed payload > { > “anonymousId”: “8d872292709c6fbe”, > “context”: {...}, > “event”: “Track Event”, > “messageId”: “1590431830915-73bed370-5889-436d-9a9e-0c0e0c809d06", > “properties”: { > “currency”: “USD”, > “event”: “Product Clicked” > “testArr”: [1,2,3], > “testmap”: {“nestedMap”: {“a”: 1, “b”: 2}}, > “price”: “58.0" > }, > “originalTimestamp”: “2020-05-25T183710.917Z”, > “type”: “track”, > “userId”: “sample_user_id” > }
âś… 1
m
Kindly test the sample user transformation before implementing it in your production environment
e
@shy-kite-21035 Re - Prevent properties from being flattened I want the complete properties json to show up as a json column in Snowflake. What should be the jsonPath that I should supply in this case? I tried passing
track.properties
via transformations and destination configuration both and couldn't make it work. Is there any issue with this jsonPath?
s
Since properties is the main object, you may have to do something like this
Copy code
export function transformEvent(event, metadata) {
  const allProperties = {...event.properties};
  const newProperties = {allProperties}; 
  event.properties = newProperties;
  return event;
}
You can then use the allProperties object as your JSON object. This should ideally work but you should test it out before deploying.
e
@shy-kite-21035 not clear what the above transformation does, event.properties seem to be unchanged. What jsonPath should I supply to keep my properties as a JSON object in the above case?
m
So what I was doing above is a hack. I am trying to add a property called all properties inside the event.properties . This object contains all the properties that are present inside the event.properties. Old properties Object properties: {prop1: value1, prop2: value2} New Properties Object properties: { allProperties: {prop1: value1, prop2: value2}}} The I was suggesting making allProperties as your JSON object. There may be some errors in the transformer code above, but essentially this is what I was trying to do.
e
Got it. I got confused because there is a typo in the function - should instead be
event.allProperties = newProperties;
Let me try this out and get back with any Qs! Thanks
@shy-kite-21035 the above 2 functions work well for the most part! Some minor hiccups though 1. Copying properties to another field and then passing it in jsonPath ensures it shows up as a JSON object in Snowflake âś… 2. Setting
event.event
to
Track Event
ensures that we have only a single table called
Track Event
on Snowflake âś… However in the
Track Event
table I'm seeing that while there is a json column for properties (with a different name), the original properties column is still being flattened. Because
Track Event
has all the events flowing into it, I can see thousands of columns being created as a result of properties being flattened. Can I prevent this? Or if I can stop
Track Event
from being created on Snowflake, that also works because I have all the info I need in the
Tracks
table, now that the new properties column is already being synced there.
m
I will check with the team and get back to you.
Hi Nipun can you share a sample request and the sample transformed payload to better elaborate the issue? There currently is an option to prevent data from going to the Tracks table but there does not seem to be a way to prevent sending data to track_event_name tables. You can check out the docs here https://www.rudderstack.com/docs/destinations/warehouse-destinations/warehouse-schema/#skip-sending-data-to-tracks-table