{"id":102447,"date":"2024-05-24T08:30:00","date_gmt":"2024-05-24T08:30:00","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=102447"},"modified":"2024-09-03T20:04:45","modified_gmt":"2024-09-03T20:04:45","slug":"the-evolution-of-time-travel-in-fabric-data-warehouse","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/the-evolution-of-time-travel-in-fabric-data-warehouse\/","title":{"rendered":"The Evolution of Time Travel in Fabric Data Warehouse"},"content":{"rendered":"<p>The May Microsoft Fabric updates bring new about Time Travel in a Data Warehouse. This is good but surprising because this feature is available for a while. Let\u2019s discover what\u2019s new in Data Warehouse time travel.<\/p>\n<p>Time travel is a feature of Delta Tables which allow us to retrieve the data as it was in a specific moment in time.<\/p>\n<p>There is a lot of considerations in the market if we should rely on a technical feature to hold data history for us or if we should ignore the feature and use a Slowly Changing Dimension type 2 (SCD type 2). If we use the SCD type 2, the history responsibility would be on us, independent of any feature.<\/p>\n<p>Most professionals I talked to prefer to take the responsibility for the history into modelling, a SCD type 2. However, the time travel can still be useful in exceptional scenarios.<\/p>\n<h2>How does it work in Microsoft Fabric<\/h2>\n<p>I wrote before about <a href=\"https:\/\/www.red-gate.com\/simple-talk\/blogs\/microsoft-fabric-and-the-delta-tables-secrets\/\">lakehouse delta tables maintenance<\/a> and this is directly related to the Time Travel feature.<\/p>\n<p>In a lakehouse, the maintenance depends on us. We decide for how long we would like to keep the data for time travel. If we are using a good modelling for history, a SCD type 2, we don\u2019t need this history at all.<\/p>\n<p>In a Data Warehouse, the maintenance is made for us. A Data Warehouse keeps the data for 7 days before cleaning the history. In this way, at any moment a time travel can be made for historical data in the last 7 days.<\/p>\n<h2>The Clone Feature<\/h2>\n<p>The first time-travel feature in Data Warehouse was the Clone statement feature. I published a video about it: <a href=\"https:\/\/www.youtube.com\/watch?v=ZVgizgPQRS8&amp;list=PLNbt9tnNIlQ5TB-itSbSdYd55-2F1iuMK&amp;index=11\">Fabric Monday 27: Clone and Time Travel in Fabric Data Warehouse<\/a><\/p>\n<p>The method is simple: We can clone a table to a specific point in time back up to 7 days. This can be done using the Clone statement or using the UI.<\/p>\n<p>Using the UI, we right-click the table, choose the Clone option:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"325\" height=\"265\" class=\"wp-image-102448\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/05\/a-screenshot-of-a-computer-description-automatica-12.png\" alt=\"A screenshot of a computer\n\nDescription automatically generated\" \/><\/p>\n<p>On the following window we specify the time travel we would like to make:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"886\" class=\"wp-image-102449\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/05\/a-screenshot-of-a-computer-description-automatica-13.png\" alt=\"A screenshot of a computer\n\nDescription automatically generated\" \/><\/p>\n<h2>Clone Statement Example<\/h2>\n<p>An interesting example is to make an update on a table and clone it to before the update time and compare the values.<\/p>\n<ol>\n<li>Check the 10 first records<\/li>\n<\/ol>\n<div><span style=\"font-family: Courier New;font-size: 10pt\"> <span style=\"color: blue\">SELECT<\/span>\u00a0<span style=\"color: blue\">TOP<\/span>\u00a0<span style=\"color: black\">10<\/span>\u00a0<span style=\"color: maroon\">salekey<\/span><span style=\"color: silver\">,<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">customerkey<\/span><span style=\"color: silver\">,<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">totalincludingtax<\/span> <br \/>\n<span style=\"color: blue\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon\">fact_sale<\/span> <br \/>\n<span style=\"color: blue\">ORDER<\/span>\u00a0\u00a0<span style=\"color: blue\">BY<\/span>\u00a0<span style=\"color: maroon\">salekey<\/span>\u00a0 <\/span><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"405\" height=\"284\" class=\"wp-image-102450\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/05\/a-screenshot-of-a-data-description-automatically.png\" alt=\"A screenshot of a data\n\nDescription automatically generated\" \/><\/p>\n<ol>\n<li value=\"2\">Update the records<\/li>\n<\/ol>\n<div><span style=\"font-family: Courier New;font-size: 10pt\"> <span style=\"color: blue\">UPDATE<\/span>\u00a0<span style=\"color: maroon\">fact_sale<\/span> <br \/>\n<span style=\"color: blue\">SET<\/span>\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">totalincludingtax<\/span>\u00a0<span style=\"color: silver\">=<\/span>\u00a0<span style=\"color: maroon\">totalincludingtax<\/span>\u00a0<span style=\"color: silver\">*<\/span>\u00a0<span style=\"color: black\">2<\/span>\u00a0 <\/span><\/div>\n<ol>\n<li value=\"3\">Clone the table with time travel<\/li>\n<\/ol>\n<div><span style=\"font-family: Courier New;font-size: 10pt\"> <span style=\"color: blue\">CREATE<\/span>\u00a0<span style=\"color: blue\">TABLE<\/span>\u00a0<span style=\"color: maroon\">dbo<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">fact_sale_past<\/span>\u00a0<span style=\"color: blue\">AS<\/span>\u00a0<span style=\"color: maroon\">clone<\/span>\u00a0<span style=\"color: blue\">OF<\/span>\u00a0<span style=\"color: maroon\">dbo<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">fact_sale<\/span>\u00a0<span style=\"color: maroon\">at<\/span>\u00a0<span style=\"color: red\">&#8216;2024-05-22T00:00:00.000&#8217;<\/span><span style=\"color: silver\">;<\/span> <\/span><\/div>\n<ol>\n<li value=\"4\">Compare the cloned table with the original one<\/li>\n<\/ol>\n<div><span style=\"font-family: Courier New;font-size: 10pt\"> <span style=\"color: blue\">SELECT<\/span>\u00a0<span style=\"color: blue\">TOP<\/span>\u00a0<span style=\"color: black\">10<\/span>\u00a0<span style=\"color: maroon\">fs<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">salekey<\/span><span style=\"color: silver\">,<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">fs<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">customerkey<\/span><span style=\"color: silver\">,<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">fs<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">totalincludingtax<\/span><span style=\"color: silver\">,<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">fsp<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">totalincludingtax<\/span><span style=\"color: silver\">,<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">fs<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">totalincludingtax<\/span>\u00a0<span style=\"color: silver\">&#8211;<\/span>\u00a0<span style=\"color: maroon\">fsp<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">totalincludingtax<\/span>\u00a0<span style=\"color: blue\">AS<\/span>\u00a0<span style=\"color: maroon\">Difference<\/span> <br \/>\n<span style=\"color: blue\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon\">fact_sale<\/span>\u00a0<span style=\"color: maroon\">fs<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: blue\">INNER<\/span>\u00a0<span style=\"color: blue\">JOIN<\/span>\u00a0<span style=\"color: maroon\">fact_sale_past<\/span>\u00a0<span style=\"color: maroon\">fsp<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: blue\">ON<\/span>\u00a0<span style=\"color: maroon\">fs<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">salekey<\/span>\u00a0<span style=\"color: silver\">=<\/span>\u00a0<span style=\"color: maroon\">fsp<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">salekey<\/span> <br \/>\n<span style=\"color: blue\">ORDER<\/span>\u00a0\u00a0<span style=\"color: blue\">BY<\/span>\u00a0<span style=\"color: maroon\">salekey<\/span>\u00a0 <\/span><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"279\" class=\"wp-image-102451\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/05\/a-screenshot-of-a-calculator-description-automati.png\" alt=\"A screenshot of a calculator\n\nDescription automatically generated\" \/><\/p>\n<h2>The new Time Travel feature<\/h2>\n<p>The new Time Travel feature released in May is the possibility to make time travel in a select statement, like the example below:<\/p>\n<div><span style=\"font-family: Courier New;font-size: 10pt\"> <span style=\"color: blue\">SELECT<\/span>\u00a0<span style=\"color: blue\">TOP<\/span>\u00a0<span style=\"color: black\">10<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">salekey<\/span><span style=\"color: silver\">,<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">customerkey<\/span><span style=\"color: silver\">,<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">totalincludingtax<\/span> <br \/>\n<span style=\"color: blue\">FROM<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">fact_sale<\/span> <br \/>\n<span style=\"color: blue\">ORDER<\/span>\u00a0<span style=\"color: blue\">BY<\/span>\u00a0<span style=\"color: maroon\">salekey<\/span>\u00a0<span style=\"color: blue\">OPTION<\/span>\u00a0<span style=\"color: maroon\">(<\/span><span style=\"color: maroon\">for<\/span>\u00a0<span style=\"color: maroon\">timestamp<\/span>\u00a0<span style=\"color: blue\">AS<\/span>\u00a0<span style=\"color: blue\">OF<\/span>\u00a0<span style=\"color: red\">&#8216;2024-05-22T00:00:00.000&#8217;<\/span><span style=\"color: maroon\">)<\/span> <\/span><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"405\" height=\"284\" class=\"wp-image-102452\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/05\/a-screenshot-of-a-data-description-automatically-1.png\" alt=\"A screenshot of a data\n\nDescription automatically generated\" \/><\/p>\n<p>The Clone statement creates a different table and allows us to compare the values, while the SELECT only allows us to recover information from a past point in time.<\/p>\n<h2>Summary<\/h2>\n<p>In my opinion, modelling is the best way to keep history. But in some exceptional situations, the time-travel can be very useful. I already needed it myself to solve some specific problems.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The May Microsoft Fabric updates bring new about Time Travel in a Data Warehouse. This is good but surprising because this feature is available for a while. Let\u2019s discover what\u2019s new in Data Warehouse time travel. Time travel is a feature of Delta Tables which allow us to retrieve the data as it was in&#8230;&hellip;<\/p>\n","protected":false},"author":50808,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,159164],"tags":[123645,159106,158997,159105],"coauthors":[6810],"class_list":["post-102447","post","type-post","status-publish","format-standard","hentry","category-blogs","category-microsoft-fabric","tag-data-warehouse","tag-delta-table","tag-microsoft-fabric","tag-time-travel"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/102447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/50808"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=102447"}],"version-history":[{"count":1,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/102447\/revisions"}],"predecessor-version":[{"id":102453,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/102447\/revisions\/102453"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=102447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=102447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=102447"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=102447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}