Table history with Fivetran Transformations

Use Fivetran Transformations to take ongoing snapshots of your data so you can analyze trends over time.
October 15, 2019

With the release of Fivetran Transformations, Fivetran users are enjoying newfound utility in centralizing data to a relational warehouse. In addition to aggregation and clean up, Transformations can make your data more extendable in another way: table history.

History tables

Some data platforms, such as Salesforce, allow you to keep an incremental history of record states over time. With Fivetran Transformations, you can embed this same functionality into your warehouse when your data source doesn’t offer any visibility into record history.

The recipe

The table history transformation takes advantage of the _fivetran_synced column, which is written to every table that Fivetran creates in the warehouse. Each time Fivetran updates the table in the warehouse, the transformation script will append the changed version of the records to a _history-labeled version of the table.

The following sample will create and continue to update table history for the `LEAD` table in a schema titled `MARKETO`. Note that the table history will be written to the same base schema as the base table, but you may like to dedicate a schema for transformation-created tables. The script uses Snowflake dialect.

1. From your Fivetran Dashboard, click Transformations

2. Create a new transformation by clicking + Transformation

3. Name your transformation

4. Paste the following in the SQL script editor, making sure to use your own database, schema and table names:

CREATE TABLE IF NOT EXISTS "DATABASE_NAME"."MARKETO"."LEAD_HISTORY" ASSELECT *FROM "DATABASE_NAME"."MARKETO"."LEAD";INSERT INTO "DATABASE_NAME"."MARKETO"."LEAD_HISTORY"SELECT *FROM "DATABASE_NAME"."MARKETO"."LEAD"WHERE "DATABASE_NAME"."MARKETO"."LEAD"._fivetran_synced > ( SELECT Max(_fivetran_synced) FROM "DATABASE_NAME"."MARKETO"."LEAD_HISTORY");

5. For schedule type, select the New Data option. The trigger table should be the name of the table that will be used to generate the table history.

That’s it! Going forward, Fivetran will automatically add to this *_history table to reflect every record change relevant to this table. You can use this history table to view how your data looked at a point in time and analyze trends, while still using the base table for your daily analytics.

This is only one example of how you can extend your data capability with Transformations. Have you written a useful Transformation? We'd love to see it! Email me at stephen@fivetran.com.

Happy transforming!

Kostenlos starten

Schließen auch Sie sich den Tausenden von Unternehmen an, die ihre Daten mithilfe von Fivetran zentralisieren und transformieren.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Product
Product

Table history with Fivetran Transformations

Table history with Fivetran Transformations

October 15, 2019
October 15, 2019
Table history with Fivetran Transformations
Use Fivetran Transformations to take ongoing snapshots of your data so you can analyze trends over time.

With the release of Fivetran Transformations, Fivetran users are enjoying newfound utility in centralizing data to a relational warehouse. In addition to aggregation and clean up, Transformations can make your data more extendable in another way: table history.

History tables

Some data platforms, such as Salesforce, allow you to keep an incremental history of record states over time. With Fivetran Transformations, you can embed this same functionality into your warehouse when your data source doesn’t offer any visibility into record history.

The recipe

The table history transformation takes advantage of the _fivetran_synced column, which is written to every table that Fivetran creates in the warehouse. Each time Fivetran updates the table in the warehouse, the transformation script will append the changed version of the records to a _history-labeled version of the table.

The following sample will create and continue to update table history for the `LEAD` table in a schema titled `MARKETO`. Note that the table history will be written to the same base schema as the base table, but you may like to dedicate a schema for transformation-created tables. The script uses Snowflake dialect.

1. From your Fivetran Dashboard, click Transformations

2. Create a new transformation by clicking + Transformation

3. Name your transformation

4. Paste the following in the SQL script editor, making sure to use your own database, schema and table names:

CREATE TABLE IF NOT EXISTS "DATABASE_NAME"."MARKETO"."LEAD_HISTORY" ASSELECT *FROM "DATABASE_NAME"."MARKETO"."LEAD";INSERT INTO "DATABASE_NAME"."MARKETO"."LEAD_HISTORY"SELECT *FROM "DATABASE_NAME"."MARKETO"."LEAD"WHERE "DATABASE_NAME"."MARKETO"."LEAD"._fivetran_synced > ( SELECT Max(_fivetran_synced) FROM "DATABASE_NAME"."MARKETO"."LEAD_HISTORY");

5. For schedule type, select the New Data option. The trigger table should be the name of the table that will be used to generate the table history.

That’s it! Going forward, Fivetran will automatically add to this *_history table to reflect every record change relevant to this table. You can use this history table to view how your data looked at a point in time and analyze trends, while still using the base table for your daily analytics.

This is only one example of how you can extend your data capability with Transformations. Have you written a useful Transformation? We'd love to see it! Email me at stephen@fivetran.com.

Happy transforming!

Topics
No items found.
Share

Verwandte Beiträge

No items found.
No items found.
A deep dive into data lakes
Blog

A deep dive into data lakes

Beitrag lesen
Fivetran named 2024 Google Cloud Technology Partner of the Year
Blog

Fivetran named 2024 Google Cloud Technology Partner of the Year

Beitrag lesen
Everything you need to know about the Fivetran REST API
Blog

Everything you need to know about the Fivetran REST API

Beitrag lesen

Kostenlos starten

Schließen auch Sie sich den Tausenden von Unternehmen an, die ihre Daten mithilfe von Fivetran zentralisieren und transformieren.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.