<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Suela Isaj on Medium]]></title>
        <description><![CDATA[Stories by Suela Isaj on Medium]]></description>
        <link>https://medium.com/@suela.isaj?source=rss-6aa4db597456------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aC8mztLAVmIQ1miI1whf0Q.jpeg</url>
            <title>Stories by Suela Isaj on Medium</title>
            <link>https://medium.com/@suela.isaj?source=rss-6aa4db597456------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 21:04:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@suela.isaj/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The power of dbt incremental models for Big Data]]></title>
            <link>https://medium.com/data-science/the-power-of-dbt-incremental-models-for-big-data-c8ba821eb078?source=rss-6aa4db597456------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8ba821eb078</guid>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[google-big-query]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[incremental]]></category>
            <dc:creator><![CDATA[Suela Isaj]]></dc:creator>
            <pubDate>Thu, 09 Feb 2023 08:30:26 GMT</pubDate>
            <atom:updated>2023-07-05T09:50:52.001Z</atom:updated>
            <content:encoded><![CDATA[<h4>An experiment on BigQuery</h4><p>If you are processing a couple of MB or GB with your dbt model, this is not a post for you; you are doing just fine! This post is for those poor souls that need to scan terabytes of data in BigQuery to calculate some counts, sums, or rolling totals over huge event data on a daily or even at a higher frequency basis. In this post, I will go over a technique for enabling a cheap data injestion and cheap data consumption for “big data”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uBaoihaL_3e_LAG-" /><figcaption>Photo by <a href="https://unsplash.com/@sortino?utm_source=medium&amp;utm_medium=referral">Joshua Sortino</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let’s imagine we have raw data in the granularity of timestamps and we need to calculate the totals per customer. Additionally, we would like to have analysis on the day and mothly basis because we need aggregated sums on different granularity. I will take the example of Twitter likes, where user_id is a Twitter user, post_id is a Twitter post, and timestamp is the timestamp when user_id liked post_id . The raw data is stored as a partioned table on day granularity. If your raw data is not partitioned, that is already your first improvement, so consider migrating the raw data to a partitioned table, following <a href="https://www.revisitclass.com/gcp/how-to-add-partition-to-existing-table-in-bigquery/">this</a> example. Make sure to make the partition filter as required <a href="https://cloud.google.com/bigquery/docs/managing-partitioned-tables#require-filter">https://cloud.google.com/bigquery/docs/managing-partitioned-tables#require-filter</a> to avoid accidents where all raw data is being scanned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kIerCnexchQDf4Mr4tV8lg.png" /><figcaption>Raw log of Twitter post likes</figcaption></figure><p>And this data is actually around 869.91 GB! So if I want the number of likes that each user has performed, my [costly] naive query would be:</p><pre>SELECT <br>  user_id,<br>  COUNT(*) as nr_likes<br>FROM twitter_likes</pre><p>However, the likes on Twitter are <em>immutable</em> events, with no chance to be modified. This allows me to load this data incrementally. I will go over the raw data to load the day, go over the daily aggregated data to load the month, and finally through the daily data to update the counts for the user that have changed.</p><p>For both incremental models, I will use the static partitioning technique, which is proven to be the most performant <a href="https://discourse.getdbt.com/t/benchmarking-incremental-strategies-on-bigquery/981">https://discourse.getdbt.com/t/benchmarking-incremental-strategies-on-bigquery/981</a>. This means that I will operate on the partitions and not scan data, so I will pick the two last-day partitions (just in case I have late arriving events), aggregate them, and add them to my dbt model twitter_likes_daily</p><pre>{% set partitions_to_replace = [<br>    &#39;current_date&#39;,<br>    &#39;date_sub(current_date, interval 1 day)&#39;<br>] %}<br><br>{{<br>    config(<br>        materialized=&#39;incremental&#39;,<br>        partition_by = { &#39;field&#39;: &#39;date&#39;, &#39;data_type&#39;: &#39;date&#39; },<br>        cluster_by = [&quot;user_id&quot;],<br>        incremental_strategy = &#39;insert_overwrite&#39;<br>        partitions = partitions_to_replace<br>    )<br>}}<br><br>SELECT <br>    user_id,<br>    DATE(timestamp) as date, <br>    COUNT(*) as nr_likes <br>FROM {{ source (&#39;twitter&#39;, &#39;twitter_likes&#39;)}}<br>-- I have a fake condition here because <br>-- my raw table does not let me query without a partition filter<br>WHERE DATE(timestamp) &gt;= &quot;1990-01-01&quot;<br><br>{% if is_incremental() %}<br>  -- this filter will only be applied on an incremental run<br>   AND DATE(timestamp) in ({{ partitions_to_replace | join(&#39;,&#39;) }})<br>{% endif %}<br>GROUP BY 1, 2</pre><p>twitter_likes_daily is only 55.52 GB and the daily load scans 536.6 MB! Let’s create the monthly aggregates, and for that, we can directly work on twitter_likes_daily instead of the raw twitter_likes</p><pre>{% set partitions_to_replace = [<br>    &#39;date_trunc(current_date, month)&#39;,<br>    &#39;date_trunc(date_sub(current_date, interval 1 month), month)&#39;<br>] %}<br><br>{{<br>    config(<br>        materialized=&#39;incremental&#39;,<br>        partition_by = { &#39;field&#39;: &#39;month_year&#39;, &#39;data_type&#39;: &#39;date&#39;, &quot;granularity&quot;: &quot;month&quot; },<br>        cluster_by = [&quot;user_id&quot;],<br>        incremental_strategy = &#39;insert_overwrite&#39;<br>        partitions = partitions_to_replace<br>    )<br>}}<br><br>SELECT <br>    user_id,<br>    DATE_TRUNC(date, MONTH) as month_year, <br>    SUM(nr_likes) as nr_likes <br>FROM {{ref(&#39;twitter_likes_daily&#39;)}}<br><br>{% if is_incremental() %}<br>  -- this filter will only be applied on an incremental run<br>   AND DATE_TRUNC(date, MONTH) in ({{ partitions_to_replace | join(&#39;,&#39;) }})<br>{% endif %}<br>GROUP BY 1, 2</pre><p>The twitter_likes_monthly is 14.32 GB and 1 load scans only 2.5 GB!</p><p>Now let’s go for the totals. For this case, we can decide to run a merge operation to update the totals of only those users that have new likes in the last 2 days. The rest of the users have no updates. So for that case, I can pick the users with likes from today from twitter_likes_daily, calculate their totals intwitter_likes_monthly, and finally merge them in the table with the totals twitter_likes_total . Note that the table is clustered using the user_id because a merge with a cluster on the id is more performant that a regular merge <a href="https://discourse.getdbt.com/t/benchmarking-incremental-strategies-on-bigquery/981">https://discourse.getdbt.com/t/benchmarking-incremental-strategies-on-bigquery/981</a></p><pre>{{<br>    config(<br>        materialized=&#39;incremental&#39;,<br>        unique_key = &#39;user_id&#39;,<br>        cluster_by = [&quot;user_id&quot;],<br>        incremental_strategy = &#39;merge&#39;<br>    )<br>}}<br><br>{% if is_incremental() %}<br>WITH users_changed as (<br>    SELECT DISTINCT user_id<br>    FROM {{ref(&#39;twitter_likes_daily&#39;)}}<br>    WHERE date = current_date()<br>)<br><br>{% endif %}<br>SELECT <br>    user_id,<br>    sum(nr_likes) as total_likes<br>FROM {{ref(&#39;twitter_likes_monthly&#39;)}}<br><br>{% if is_incremental() %}<br>  AND user_id in (select user_id from users_changed)<br>{% endif %}<br>group by  1<br></pre><p>twitter_likes_total is 1.6 GB and scans 16 GB! So from 869.91 GB we ended up scanning only 16 GB and producing a bunch of light and cheap analytical tables.</p><p>However, the approach of twitter_likes_total could also have been a table configuration on dbt that only scans the twitter_likes_monthly . That would be like below:</p><pre>{{<br>    config(<br>        materialized=&#39;table&#39;,<br>        cluster_by = [&quot;user_id&quot;]<br>    )<br>}}<br><br>SELECT <br>    user_id,<br>    sum(nr_likes) as total_likes<br>FROM {{ref(&#39;twitter_likes_monthly&#39;)}}<br></pre><p>The above script will scan 14.5 GB so actually lighter than the merge procedure! What just happened here? It is important to understand that a merge can be less effective than a full table recreation. Given that the table that we are scanning twitter_likes_monthly is not that large and 14.5 GB, a full table recreation is more performant than a merge. So when the data ends up not being that large, a merge would be really over-engineering.</p><p><strong>Let’s wrap up</strong></p><p>The scans of raw immutable events can be efficiently treated by using incremental models on dbt, and specifically, using a static insert+overwrite strategy. The improvement can be huge, from TB to a couple of GB daily for the dbt load, but most importantly, enabling data analysts to run queries on what would have been a costly scan of raw tables to some light, pre-aggregated tables. Finally, while appending data to a table might look theoretically cheaper than re-creating the table, depending on the use case, sometimes using a merge can be less performant than a full table recreation, when the source data is a couple of GB.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8ba821eb078" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/the-power-of-dbt-incremental-models-for-big-data-c8ba821eb078">The power of dbt incremental models for Big Data</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two (completely different) types of dbt incremental models in BigQuery]]></title>
            <link>https://medium.com/data-science/two-completely-different-types-of-dbt-incremental-models-in-bigquery-db794cbe022c?source=rss-6aa4db597456------2</link>
            <guid isPermaLink="false">https://medium.com/p/db794cbe022c</guid>
            <category><![CDATA[data-management]]></category>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-warehouse]]></category>
            <dc:creator><![CDATA[Suela Isaj]]></dc:creator>
            <pubDate>Thu, 28 Jul 2022 14:02:06 GMT</pubDate>
            <atom:updated>2023-08-17T12:39:07.575Z</atom:updated>
            <content:encoded><![CDATA[<h4>Partition-based loading or tracking the history of your downstream model with incremental loads</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Nm3N3egV4BqUeW6V" /><figcaption>Photo by <a href="https://unsplash.com/@killerfvith?utm_source=medium&amp;utm_medium=referral">Alex wong</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Incremental models in <a href="https://docs.getdbt.com/">dbt</a> are not a new invention, they are the traditional way of appending data into a table. In old-school datawarehouses, this would be the way to bring the daily data to your data storage environment. In order for things not to get out of control, you would put a key and decide to update the row if it exists, or append it otherwise (with a MERGEoperation).</p><p>dbt has already great documentation on incremental models <a href="https://docs.getdbt.com/docs/building-a-dbt-project/building-models/configuring-incremental-models">https://docs.getdbt.com/docs/building-a-dbt-project/building-models/configuring-incremental-models</a>. The typical use case that is mentioned in almost all the examples is switching to an incremental model to reduce your costs, so you wouldn’t drop your table every day and re-built it from scratch but instead, add the rows incrementally. If you are using BigQuery, you should already look at costs for scanning hundreds of GB or TB of data every day (or maybe several times per day, depending on how you have scheduled your dbt). Below, I will go over 2 types of use cases and how to design an efficient incremental model in dbt.</p><h4><strong>Type 1 incremental model use case</strong></h4><ul><li>Your data is already in your data lake, completely, all of it, so you could re-create your table every day.</li><li>You have event data that is immutable and has a timestamp. Examples can be clicks, views, impressions, email open, etc.</li><li>Creating the model on the table materialization is costly.</li></ul><h4><strong>Example of type 1 incremental model</strong></h4><p>Let’s say I have data about customer clicks that have the user_id and the clicked_at timestamp</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*Dvom8rEcAfKe0Wn537j8tQ.png" /><figcaption>Example of raw customer click data</figcaption></figure><p>and you want to create a model with the number of clicks per customer per day:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*3-oX9T7TDhsZqUNiI1j5YA.png" /><figcaption>Example of type 1 incremental model output on click data</figcaption></figure><p>The query for this is pretty simple:</p><pre>select <br>     user_id, <br>     date(clicked_at) as day, <br>     count(clicked_at) as nr_clicks<br>from raw_data<br>group by user_id, date(clicked_at)</pre><p>Imagine you have Terabytes of this data, why recalculate all the click history every time from scratch when you can only calculate the last day?</p><h4><strong>Solution for type 1 incremental model</strong></h4><p>First of all this type of data is born to be partitioned, please do it. In this <a href="https://discourse.getdbt.com/t/benchmarking-incremental-strategies-on-bigquery/981">link</a> you can see a very neat comparison of different strategies on BigQuery and the performance of each. It is very obvious that the <em>insert+overwrite static</em> strategy has the best performance, almost linear with the growth of data <strong>🥳</strong>. So let’s implement that!</p><pre>-- Let&#39;s define the partitions and decide the replace the last 2 <br>-- days, just in case some clicks did not arrive yet.<br>{% set partitions_to_replace = [<br>      &#39;current_date&#39;,<br>      &#39;date_sub(current_date, interval 1 day)&#39;<br>] %}<br>-- Here we define the incremental model, the data will be<br>-- partitioned by the date and I am also clustering by user_id<br>-- to improve performance. I am choosing the insert_overwrite<br>-- strategy explicitly<br>{{ <br>   config(<br>          materialized=&#39;incremental&#39;,<br>          partition_by = { &#39;field&#39;: &#39;day&#39;, &#39;data_type&#39;: &#39;date&#39; },<br>          cluster_by = &quot;user_id&quot;,<br>          incremental_strategy = &#39;insert_overwrite&#39;,<br>          partitions = partitions_to_replace         <br>        )<br>}}<br>select <br>     {{ dbt_utils.surrogate_key([&#39;user_id&#39;,    dbt_utils.date_trunc(&#39;day&#39;,&#39;clicked_at&#39;)]) }} as user_day_pk,<br>     user_id, <br>     date(clicked_at) as day, <br>     count(clicked_at) as nr_clicks<br>from raw_data<br>-- This is to replace the last 2 day partitions<br>{% if is_incremental() %}<br>where date(clicked_at) in ({{ partitions_to_replace | join(&#39;,&#39;) }})<br>{% endif %}<br>group by user_id, date(clicked_at)</pre><p>I am not even showing the example of merge strategies for this use case, even though they would function because this is really a neat way to implement this model and achieve the best performance. Note that <strong>you do not need a key</strong> for the insert_overwrite strategy. More importantly, even if you add a line in your config for a unique key, that line won’t even run! So do not do this, you will create false expectations for yourself:</p><pre>{{ <br>   config(<br>          materialized=&#39;incremental&#39;,<br>-- do not do this line below, it won&#39;t run anyways<br>          unique_key = &#39;user_day_pk&#39;<br>          partition_by = { &#39;field&#39;: &#39;day&#39;, &#39;data_type&#39;: &#39;date&#39; },<br>          cluster_by = &quot;user_id&quot;,<br>          incremental_strategy = &#39;insert_overwrite&#39; <br>          partitions = partitions_to_replace       <br>        )<br>}}</pre><p>So how come the key won’t be needed? Well, the code above works blindly, drops your last 2 day partitions from your dbt model, picks the last 2 days from raw_data and re-appends them. So no keys are needed for the operation, but you are welcome to keep a key on the table if you would like.</p><h4><strong>Type 2 incremental model use case</strong></h4><ul><li>Your data source does not keep history but you would like to start building the history and stop losing data.</li><li>Your dbt model has several transformations downstream and you would like to track the history of your downstream model.</li></ul><p>This is a completely different use case than the previous case because this resembles keeping snapshots. <a href="https://docs.getdbt.com/blog/change-data-capture?utm_content=215567626&amp;utm_medium=social&amp;utm_source=linkedin&amp;hss_channel=lcp-10893210">Here</a> is a very nice blog from dbt labs about this use case, where they clearly state not to snapshot your downstream model. The solution I will show not only helps you track history and prevent data loss, but it is also way less costly than maintaining several snapshots.</p><h4><strong>Example of type 2 incremental model</strong></h4><p>Let’s suppose you have 6 tables in your data source that keep different attributes of the Twitter profile, like Twitter profile URL, Twitter username, Twitter description, Twitter photo URL, and Twitter location. These are engineering tables that keep each of these attributes, together with the created and modified timestamp.</p><p>t_profile — t_profile_id , t_modified_at , t_deleted_at</p><p>t_username — t_profile_id , t_username , t_created_at , t_modified_at</p><p>t_url — t_profile_id , t_url , t_created_at , t_modified_at</p><p>t_description — t_profile_id , t_description , t_created_at , t_modified_at</p><p>t_photo_url — t_profile_id , t_photo_url , t_created_at , t_modified_at</p><p>t_location — t_profile_id , t_longitude , t_latitude , t_created_at , t_modified_at</p><p>t_profile_id is a key for each of these tables. The username and the profile URL are mandatory attributes but the rest can be missing from a profile. The query for joining this data is simple, but it only gives you the current version of the Twitter profile. Actually, unless you start tracking the history, you cannot find the versions of each of the attributes, only the current ones.</p><pre>select<br>      t_profile.t_profile_id,<br>      t_username,<br>      t_url,<br>      t_description,<br>      t_photo_url,<br>      t_longitude,<br>      t_latitude,<br>      t_profile.t_created_at as t_profile_created_at,<br>      t_profile.t_deleted_at as t_profile_deleted_at<br>from t_profile<br>inner join t_username<br>      on t_profile.t_profile_id = t_username.t_profile_id<br>left join t_url<br>      on t_profile.t_profile_id = t_url.t_profile_id<br>left join t_description<br>      on t_profile.t_profile_id = t_description.t_profile_id<br>left join t_photo_url<br>      on t_profile.t_profile_id = t_photo_url.t_profile_id<br>left join t_location<br>      on t_profile.t_profile_id = t_location.t_profile_id</pre><p>Now you would like to create a table t_profile_history based on the previous query but also keep track of each of the attributes in the engineering data.</p><h4><strong>Solution for type 2 incremental model</strong></h4><p>We cannot use partitions for the data load strategy anymore, because we do not want to drop any partitions and recalculate from the data source, given that the data source does not keep history. Let’s simply the case as keeping a modification per day.</p><pre>-- Here we set the config as incremental and the unique key of each -- profile per day<br>-- I am pratitioning by date for query performance after the model <br>-- is live, but it won&#39;t affect the merge<br>-- Add the strategy as merge<br>-- Do not forget full_refresh = false so there are no accidents<br>{{ config(<br>          materialized=&#39;incremental&#39;,<br>          unique_key = &#39;t_profile_history_pk&#39;,<br>          partition_by = { &#39;field&#39;: &#39;t_profile_modified_at&#39;,     &#39;data_type&#39;: &#39;timestamp&#39;, &quot;granularity&quot;: &quot;day&quot; }, <br>          cluster_by = &quot;t_profile_id&quot;,<br>          incremental_strategy = &#39;merge&#39;,<br>          full_refresh = false<br>         )<br>}}<br>with twitter_profile_versions as (<br>select<br>      t_profile.t_profile_id,<br>      t_username,<br>      t_url,<br>      t_description,<br>      t_photo_url,<br>      t_longitude,<br>      t_latitude,<br>      t_profile.t_created_at as t_profile_created_at,<br>      t_profile.t_deleted_at as t_profile_deleted_at,<br>      GREATEST(<br>               COALESCE(<br>                        t_profile.t_created_at,<br>                        t_username.t_modified_at,<br>                        t_url.t_modified_at,<br>                        t_description.t_modified_at,<br>                        t_photo_url.t_modified_at,<br>                        t_location.t_modified_at<br>                       ),<br>               COALESCE(<br>                        t_username.t_modified_at,<br>                        t_url.t_modified_at,<br>                        t_description.t_modified_at,<br>                        t_photo_url.t_modified_at,<br>                        t_location.t_modified_at,<br>                        t_profile.t_created_at<br>                       ),<br>               COALESCE(<br>                        t_url.t_modified_at,<br>                        t_description.t_modified_at,<br>                        t_photo_url.t_modified_at,<br>                        t_location.t_modified_at,<br>                        t_profile.t_created_at<br>                        t_username.t_modified_at<br>                       ),<br>               COALESCE(<br>                        t_description.t_modified_at,<br>                        t_photo_url.t_modified_at,<br>                        t_location.t_modified_at,<br>                        t_profile.t_created_at<br>                        t_username.t_modified_at<br>                        t_url.t_modified_at<br>                       ),<br>               COALESCE(<br>                        t_photo_url.t_modified_at,<br>                        t_location.t_modified_at,<br>                        t_profile.t_created_at<br>                        t_username.t_modified_at<br>                        t_url.t_modified_at,<br>                        t_description.t_modified_at<br>                       ),<br>               COALESCE(<br>                        t_location.t_modified_at,<br>                        t_profile.t_created_at<br>                        t_username.t_modified_at<br>                        t_url.t_modified_at,<br>                        t_description.t_modified_at<br>                        t_photo_url.t_modified_at<br>                       ),<br>               ) as t_profile_modified_at<br>from t_profile<br>left join t_username<br>      on t_profile.t_profile_id = t_username.t_profile_id<br>left join t_url<br>      on t_profile.t_profile_id = t_url.t_profile_id<br>left join t_description<br>      on t_profile.t_profile_id = t_description.t_profile_id<br>left join t_photo_url<br>      on t_profile.t_profile_id = t_photo_url.t_profile_id<br>left join t_location<br>      on t_profile.t_profile_id = t_location.t_profile_id<br>)<br>select <br>     {{ dbt_utils.surrogate_key([&#39;t_profile_id&#39;,      dbt_utils.date_trunc(&#39;day&#39;,&#39;t_profile_modified_at&#39;)}} as t_profile_history_pk,<br>     twitter_profile_versions.*<br>from twitter_profile_versions<br>{% if is_incremental() %}<br>where date_diff(current_date(), date(t_profile_modified_at), DAY) &lt;= 2<br>{% endif %}</pre><p>The above piece of code designs the load process for our t_profile_history which keeps a version of the profile for each day, in case there are any changes. I left join with the tables with the attributes to pick any modified attributes in the last two days. Be careful because an inner join would require that all the attributes have changed, but this might not be the case.</p><p>I am using GREATEST() to pick the last modified timestamp and this is to simplify the query and try to find intermediate versions between the modified timestamps of each table. In this case, we are simplifying our use case to build the history with the snapshot that we get when we run our dbt. Note that I am using COALESCE() and rotating all the modified timestamps, including t_created_at in the profile. I am doing this because GREATEST() will return NULL if any of the elements is null <a href="https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators">https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators</a> and we might have nulls given that we have 5 left joins. I am rotating each modified timestamp, so all have the chance to be the output of COALESCE() if they are not null.</p><p>Remember to use full_refresh=FALSE . This will prevent accidents when someone runs dbt run --full --refresh and your model is gone, together with the history you tracked so far.</p><p>A note on the side:</p><p>An alternative solution to the type 2 use case can also be resolved with snapshots. In that case, you would snapshot all 6 tables every day and have your transformations as usual (table or incremental materialization) downstream. The pros of the snapshot solution are that you still have a type of ELT process in place, where you track the history of source data and decide on the transformations later. This is a great advantage when you are not sure what to track and you expect schema changes. The cons of the snapshot solution are that it is way costly compared to the incremental model, both in terms of processing (the incremental model solution only scans data for the last 2 days) and storage (we only store 1 model in the incremental solution instead of 7 in the snapshot solution).</p><h4><strong>Let’s wrap up!</strong></h4><p>dbt incremental models are an amazing tool to improve performance and optimize your costs. When your tables are huge and the events are immutable, consider using insert_overwrite strategy. A less traditional example is tracking the history from your downstream model. This resembles more of an ETL process, where you extract, do the transformations, and then load incrementally, and can be achieved with merge strategy, keeping a unique key, and making sure you do not allow full refresh.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db794cbe022c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/two-completely-different-types-of-dbt-incremental-models-in-bigquery-db794cbe022c">Two (completely different) types of dbt incremental models in BigQuery</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tracking user activity with dbt]]></title>
            <link>https://medium.com/data-science/incremental-models-to-track-activity-with-dbt-7f6565b893f3?source=rss-6aa4db597456------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f6565b893f3</guid>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[data-build-tool]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[data-warehouse]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Suela Isaj]]></dc:creator>
            <pubDate>Sun, 12 Dec 2021 20:26:52 GMT</pubDate>
            <atom:updated>2023-07-05T09:55:53.612Z</atom:updated>
            <content:encoded><![CDATA[<h4>Generating historical activity table (time-partioned) in Bigquery with dbt incremental models</h4><p>In this post, I will show how to create a historical table and track user activity using <em>incremental models</em> and <strong>dbt </strong>in<strong> BigQuery</strong>. If <strong>dbt</strong> does not ring a bell, then check this <a href="https://blog.getdbt.com/what-exactly-is-dbt/">article</a>. You can also get started with incremental models following <a href="https://docs.getdbt.com/docs/building-a-dbt-project/building-models/configuring-incremental-models">this</a>.</p><p>Ok, back to our example! Let me make it simple: we have the last activity timestamp of each user and now we want to know the frequency that the user has been to our platform in a daily granularity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*ngaByP4P4Q9lcz8MDTxNNw.png" /><figcaption>Image by author</figcaption></figure><p>Let’s say we have a table that keeps the last activity for each user. We need to build a table that tracks if a user was on our platform each day. We cannot do that with our current <strong>Last Activity Table </strong>because that keeps only the latest activity timestamp for each user.</p><p>A naive solution would be to keep daily copies of the <strong>Last Activity Table</strong>. That of course will work, but we will have repeated rows of users, especially when they have not come to our platform for some time.</p><p>Let’s list our requirements and considerations:</p><ol><li>We need an operation like Merge that keeps only unique rows of users and their daily activity.</li><li>We can run the pipeline at least once per day to get daily tracking.</li><li>The historical table will grow with time so let’s store it as a time-unit <em>partitioned</em> table, so we can reduce costs drastically. If you do not know what partitioned tables are, check this <a href="https://cloud.google.com/bigquery/docs/partitioned-tables">link</a>.</li></ol><p>Our pipeline should run daily, pick the <strong>Last Activity Table</strong>, and insert it into our partitioned <strong>Historical Activity Table</strong> with respecting the uniqueness of user_id+activity_date. I will show you how to do this with <strong>dbt </strong>step by step.</p><ul><li>Create a file, I am naming it inc_user_activity.sql</li><li>Let’s decide on the SQL query. We need to select everything from <strong>Last Activity Table</strong> but on a daily granularity. Let’s suppose we reference our table as last_activity_table. If you haven’t referenced your table, then instead of {{ref(&#39;last_activity_table&#39;)}} put the name of your table. However, I highly recommend using references in <strong>dbt</strong> and check this <a href="https://docs.getdbt.com/reference/dbt-jinja-functions/ref">link</a> if you don’t know how to do that. So instead of</li></ul><pre>select user_id, last_activity from {{ ref(&#39;last_activity_table&#39;}}</pre><p>we need</p><pre>select <br>    {{ dbt_utils.surrogate_key([&#39;user_id&#39;,     <br>    dbt_utils.date_trunc(&#39;day&#39;,&#39;last_activity&#39;)]) }} as user_activity_id,<br>    user_id, <br>    date(last_activity) as activity_date <br>from {{ ref(&#39;last_activity_table&#39;}}</pre><p>because we only need daily granularity. If we leave the last_activity as timestamp as it is, then we will have several rows in the new table for the same day if the user came more than once. That is why we need to use dbt_utils.date_trunc(&#39;day&#39;, &#39;last_activity&#39;), so that we truncate last_activityto day granularity. Additionally, we need a key for our table, which will keep the relationship between the user_id and the date of the activity. We create the key by dbt_utils.surrogate_key([&#39;user_id&#39;, dbt_utils.date_truc(&#39;day&#39;, last_activity)]) .</p><ul><li>Let’s write our config ! We need to define the uniqueness of user_id and activity_date and we also need to create a date partitioned table, so voilá:</li></ul><pre>{{ config<br>      (<br>        materialized=&#39;incremental&#39;,<br>        unique_key = &#39;user_activity_id&#39;,<br>        partition_by = { &#39;field&#39;: &#39;activity_date&#39;, &#39;data_type&#39;: &#39;date&#39; },<br>        incremental_strategy = &#39;merge&#39;<br>      ) <br>}}</pre><p>Let’s take a moment here to understand what we did here: we are telling <strong>dbt</strong> to create an incremental model materialize = &#39;incremental&#39; , then we want to key to use user_activity_id as the unique_key , which, as we saw above, is the combination of user_id and activity_date . We also need to tell <strong>dbt</strong> to create a partitioned table, so partition_by = {&#39;field&#39;:&#39;activity_date&#39;, &#39;data_type&#39; = &#39;date&#39;} . Finally, we need the merge strategy, so if a combination of user_id and activity_date is already there, then to overwrite it so we respect our uniqueness constraint, but also, to insert the combinations that are not present.</p><ul><li>Now let’s tell <strong>dbt</strong> how to run the query for the incremental model, so we will need to re-define our SQL to only pick data of yesterday and today from <strong>Last Activity Table</strong> and add them to your <strong>Historical Activity Table</strong>. I am doing this so the queries are lighter and we only deal with yesterday and today’s data. The {%if is_icremental() %} ... {% endif %} block only runs for incremental models, so the query will be modified to add the where condition to filter only the data of today and yesterday.</li></ul><pre>select <br>    {{ dbt_utils.surrogate_key([&#39;user_id&#39;,     <br>    dbt_utils.date_trunc(&#39;day&#39;,&#39;last_activity&#39;)]) }} as user_activity_id, <br>    user_id, <br>    date(last_activity) as activity_date <br>from {{ ref(&#39;last_activity_table&#39;}}<br>{% if is_incremental() %}<br>where date_diff(current_date(), date(last_activity), DAY) &lt;= 2<br>{% endif %}</pre><p>Ok, here I will put the whole procedure I described above, all together, so you can simply copy-paste it in your <strong>dbt</strong> file and make the proper adjustments!</p><pre>{{ config(<br>      materialized=&#39;incremental&#39;,<br>      unique_key = &#39;user_activity_id&#39;,<br>      partition_by = { &#39;field&#39;: &#39;activity_date&#39;, &#39;data_type&#39;: &#39;date&#39; },<br>      incremental_strategy = &#39;merge&#39;) <br>}}<br>select <br>      {{ dbt_utils.surrogate_key([&#39;user_id&#39;,<br>       dbt_utils.date_trunc(&#39;day&#39;,&#39;last_activity&#39;)]) }} as user_activity_id, <br>       user_id, <br>      date(last_activity) as activity_date <br>from {{ ref(&#39;last_activity_table&#39;}}<br>{% if is_incremental() %}<br>where date_diff(current_date(), date(last_activity), DAY) &lt;= 2<br>{% endif %}</pre><p>In conclusion, <em>dbt can be used not only for transforming data to create analytical models but also for generating historical data!</em> Tables that originate from OLTP sources might not always keep historical data, so instead of keeping full snapshots every day, you can use the power of <strong>dbt</strong> to build incremental models and tune them correctly to start tracking the history. Moreover, think about how your table will scale, so time partitions, especially for event data, will save your life in the long run.</p><p>That is all from me folks! If you want to read something more about partitions, have a look at this great post <a href="https://discourse.getdbt.com/t/bigquery-dbt-incremental-changes/982">https://discourse.getdbt.com/t/bigquery-dbt-incremental-changes/982</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f6565b893f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/incremental-models-to-track-activity-with-dbt-7f6565b893f3">Tracking user activity with dbt</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grouping by and applying functions on Pandas]]></title>
            <link>https://medium.com/@suela.isaj/grouping-by-and-applying-functions-on-pandas-16c3e8802f31?source=rss-6aa4db597456------2</link>
            <guid isPermaLink="false">https://medium.com/p/16c3e8802f31</guid>
            <category><![CDATA[python-lambda]]></category>
            <category><![CDATA[pandas-groupby]]></category>
            <category><![CDATA[pandas-lambda]]></category>
            <category><![CDATA[pandas-dataframe]]></category>
            <category><![CDATA[pandas]]></category>
            <dc:creator><![CDATA[Suela Isaj]]></dc:creator>
            <pubDate>Sat, 13 Nov 2021 08:52:34 GMT</pubDate>
            <atom:updated>2021-11-13T08:52:34.192Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*LwLVXWE5lEXbJgTRSE6yBg.png" /></figure><p>If you are new to pandas, have a look here at this <a href="https://medium.com/swlh/the-mastery-of-pandas-i-50156db42125">article</a>. I will take a simple example here of some data. If you want to try it with me, use this code:</p><pre>import pandas as pd<br>data=pd.DataFrame({&#39;Customers&#39;:[&#39;Jane&#39;, &#39;Maria&#39;, &#39;Maria&#39;, &#39;Joch&#39;, &#39;Daniel&#39;, &#39;Daniel&#39;, &#39;Daniel&#39;],<br>        &#39;Product&#39;:[&#39;Wine&#39;, &#39;Milk&#39;, &#39;Cookies&#39;, &#39;Bread&#39;, &#39;Gnocchi&#39;, &#39;Tomatos&#39;, &#39;Parmesian&#39;],<br>        &#39;Price&#39;:[30.6, 1.5, 2.6, 0.7, 1.5, 0.9, 3.5]})</pre><p>and we will have this simple example of some customers buying products:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*GrrKoP2v1ub3t0-JUtuPlQ.png" /></figure><p>So, what we will do is to group this data by customer, apply a function for each group, and finally, put them back together.</p><p>If you try to group by Customers, the output is an object. What is actually happening, is that the dataframe data is split into the groups, so all the rows are indexed according to their group. So the object contains the group and the rows they belong to the group, arranged in a mini dataframes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3EcZGgQVxGWNSbYU0XGeQ.png" /></figure><p>You can even try to see what is inside the object:</p><pre>for group, mini_df in data.groupby(&#39;Customers&#39;):<br>    print(&#39;group:&#39;, group)<br>    print(&#39;df:\n&#39;, mini_df)<br>    print(&#39;\n&#39;)</pre><p>You will see the groups and the mini dataframes that belong to each group:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*LobgPoZVkFsGijxPrGWaOQ.png" /></figure><p>So, now, let’s suppose we want to see how much each customer spent. We would need to sum the prices of the products they bought. There are in-built functions in pandas for these typical aggregations, such as the sum, average, min, max, etc. In our case, we will group by customer and sum the price, so after grouping by customer, we can select the price and then sum on that column, like this:</p><pre>data.groupby(&#39;Customers&#39;).Price.sum()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*VZGqAdZYv9C1a-xH_jxAJw.png" /></figure><p>If you try to sum on all the columns without filtering the Price, you will still get the correct result, because we have only 1 column that is float to apply mathematical function. But as good practice, filter your columns before :)</p><p>Now, let’s suppose that we cannot apply an in-built function but we need to see the all the products, ordered by the price in a descending order, for each customer. I will write a simple function to do that:</p><pre>def order_products (df):<br>    return df.sort_values(&#39;Price&#39;, ascending=False)</pre><p>And I need to apply this for each of my groups. Now we can use .apply() to apply a function after grouping by. What is happening is that each of the mini_df that were created by grouping by are input for order_products . order_products will sort each of the mini_df and put them back together in a dataframe.</p><pre>data.groupby(&#39;Customers&#39;).apply(order_products)</pre><p>and we get our desired ouput, each group, ordered by descending price.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*bFpXNQvTbeWebIIC9iJnxg.png" /></figure><p>Instead of defining the function order_products , we can use a lambda function, which is an anonimous function that you define directly inside the .apply() Check <a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.apply.html">this</a> for more documention. You would use lambda when you have ONLY one output. lambda functions cannot return more than 1 output differently from functions in python.</p><p>Lambda functions start with the keyword lambda and their input, a colon : and then the output, which means, what is the function returning. Looking at order_products , our input is df and the return is df.sort_values(&#39;Price&#39;, ascending=False) .</p><p>So instead of defining order_products , we can solve our problem in only 1 line:</p><pre>data.groupby(&#39;Customers&#39;).apply(lambda df: df.sort_values(&#39;Price&#39;, ascending=False))</pre><p>And the output is the same as before!</p><p>I will visualize these so everything is crystal clear:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*CLIvP4lNw76h4i26dYHY_w.png" /></figure><p>Good, now go enjoy some panda time 🐼</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16c3e8802f31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Categorical values into Boolean columns in BigQuery using PIVOT]]></title>
            <link>https://medium.com/@suela.isaj/categorical-values-into-boolean-columns-in-bigquery-using-pivot-a77a0868771a?source=rss-6aa4db597456------2</link>
            <guid isPermaLink="false">https://medium.com/p/a77a0868771a</guid>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[pivot]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Suela Isaj]]></dc:creator>
            <pubDate>Thu, 16 Sep 2021 14:33:37 GMT</pubDate>
            <atom:updated>2021-09-16T14:34:09.982Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Ie1xfpPGkGKn8W3im8lr7g.png" /></figure><p>A common problem is having a column of categorical values that you need to expand into several columns populated with true/false. While this issue is easily solved in Python, in BigQuery using SQL is a bit different. I will show here a solution using <a href="https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#pivot_operator">PIVOT</a>.</p><p>Let’s suppose we have a table of customer ids and the product they bought, named selections as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*szDTPxtrLVwvs6P0te6DKw.png" /></figure><p>I would like to have this result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*2z6ckxqmKhsivccaZxWfEA.png" /></figure><p>I can achieve this by using PIVOT. So what you have to do, is select * from selectionsfollowed by PIVOT ( aggregation(<em>column you want to aggregate</em>) FOR <em>column with the categorical values</em> IN (<em>categorical values</em>). In our case, we do not want any aggregation, so we can simply get the count. The count will return 1 if the customer_idis connected to that product, or 0 otherwise. After FOR we will select the column product , since that is the column with the categorical values, and finally after IN we will list the categorical values in the column product</p><pre>select * from selections PIVOT(count(product) FOR product in (&#39;apples&#39;, &#39;oranges&#39;, &#39;butter&#39;, &#39;cream&#39;, &#39;chocolate&#39;, &#39;wine&#39;, &#39;cheese&#39;))</pre><p>The result of the query is this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*2z6ckxqmKhsivccaZxWfEA.png" /></figure><p>If you do not want to specify all the products, you can use this piece of code, first declare your list products as a list where you do STRING_AGG on the distinct products, and then use EXECUTE IMMEDIATE to run your query:</p><pre>DECLARE products STRING;</pre><pre>SET products = (SELECT CONCAT(&#39;(&quot;&#39;, STRING_AGG(DISTINCT product, &#39;&quot;, &quot;&#39;), &#39;&quot;)&#39;), FROM selections);<br>EXECUTE IMMEDIATE format(&quot;&quot;&quot; <br>select * from selections PIVOT(count(product) FOR product in %s)<br>&quot;&quot;&quot;, products);</pre><p>Hope this helps!</p><p>Credits to: <a href="https://towardsdatascience.com/pivot-in-bigquery-4eefde28b3be">https://towardsdatascience.com/pivot-in-bigquery-4eefde28b3be</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a77a0868771a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deleting Apex Classes and Triggers on Salesforce]]></title>
            <link>https://medium.com/@suela.isaj/deleting-apex-classes-and-triggers-on-salesforce-b0f22d1783e3?source=rss-6aa4db597456------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0f22d1783e3</guid>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[xml]]></category>
            <category><![CDATA[objects]]></category>
            <category><![CDATA[apex]]></category>
            <dc:creator><![CDATA[Suela Isaj]]></dc:creator>
            <pubDate>Fri, 10 Sep 2021 08:22:43 GMT</pubDate>
            <atom:updated>2021-09-10T08:33:09.628Z</atom:updated>
            <content:encoded><![CDATA[<p>If you wonder how to delete an <em>Apex class</em> in Salesforce and you are trying to do that through the Salesforce UI, bad news…there is no way!</p><p>You might need to delete Apex classes or triggers when you need to get rid of a Salesforce object but you cannot due to its dependencies. Some dependencies like Matching rules, Duplicate Rules, tec, can be solved within Salesforce with no difficulties. While dependencies like Apex Classes will give you are a hard time.</p><p><a href="https://help.salesforce.com/s/articleView?id=000328218&amp;type=1">The Salesforce help site</a> points you to <a href="https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/forcemigrationtool_container_install.htm">Ant Migration Tool</a> and personally, I found it a real headache to configure and learn how to use. Thus, I will show here the solution using Workbench. Spoiler alert: <em>You do not need to install anything and it is easy peasy.</em></p><p>Steps to follow:</p><ol><li>Go to <a href="https://workbench.developerforce.com/login.php">https://workbench.developerforce.com/login.php</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n1Wax1YRydUAHnBMYTGRog.png" /></figure><p>2. Click on <em>Login with Salesforce</em> and put your salesforce credentials (username + password)</p><p>3. Choose Migration -&gt; Deploy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6qAZLl1LC0uPhMMzNR_Lw.png" /></figure><p>4. In the next page, we will need to upload a zip file as mentioned in this <a href="https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/daas_destructive_changes.htm">link</a>. So, first, create a new folder.</p><p>5. Inside your folder, create a text file named destructiveChanges.xml<em>. </em>It is important to name it <strong>exactly</strong> like this! Open the file with a text editor and paste the code below</p><pre>&lt;?xml version=”1.0&quot; encoding=”UTF-8&quot;?&gt; <br>&lt;Package xmlns=”http://soap.sforce.com/2006/04/metadata&quot;&gt; <br>    &lt;types&gt; <br>    &lt;members&gt;CustomersData&lt;/members&gt; <br>    &lt;name&gt;ApexClass&lt;/name&gt; <br>    &lt;/types&gt; <br>&lt;/Package&gt;</pre><p>6. If you are deleting an Apex class, write ApexClass between the tags &lt;name&gt;&lt;/name&gt;. If you are deleting an Apex trigger, then type ApexTrigger between the tags &lt;name&gt;&lt;/name&gt;. Additionally, write the name of the class/trigger in between the memebers tags &lt;members&gt;&lt;/members&gt; . In my case, I am deleting the ApexClass named CustomerData</p><p>PS: If you want to delete classes and triggers in one go, you can simply add more members and names. For example, if I need to delete 2 classes (CustomerDataand SalesData ) and 1 trigger ( TriggerOnCustomers ), this would be the code</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;Package xmlns=&quot;<a href="http://soap.sforce.com/2006/04/metadata">http://soap.sforce.com/2006/04/metadata</a>&quot;&gt;<br>    &lt;types&gt;<br>        &lt;members&gt;CustomerData&lt;/members&gt;<br>        &lt;name&gt;ApexClass&lt;/name&gt;<br>    &lt;/types&gt;<br>    &lt;types&gt;<br>        &lt;members&gt;TriggerOnCustomers&lt;/members&gt;<br>        &lt;name&gt;ApexTrigger&lt;/name&gt;<br>    &lt;/types&gt;<br>    &lt;types&gt;<br>        &lt;members&gt;SalesData&lt;/members&gt;<br>        &lt;name&gt;ApexClass&lt;/name&gt;<br>    &lt;/types&gt;<br>&lt;/Package&gt;</pre><p>7. Create another text file name package.xml . It is important to name it <strong>exactly</strong> like this! Open the file with a text editor and paste the code below. Make sure the version matches with the version on workbench (see the Figure in Step 1).</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; <br>&lt;Package xmlns=&quot;http://soap.sforce.com/2006/04/metadata&quot;&gt;<br>    &lt;version&gt;<br>       52.0<br>    &lt;/version&gt; <br>&lt;/Package&gt;</pre><p>8. Zip together both destructiveChanges.xml and package.xml in a zip folder named package and upload it in Choose file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dC5laPey3ZrjGZp-9w5Nyw.png" /></figure><p>9. Select Rollback On Error , Single Package , and choose RunLocalTests in Test Level as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lH0rxk0RsL4CmyMnrogYZA.png" /></figure><p>10. Click on Deploy and that’s it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5VCcfhoik7DgCZPrScnP7Q.png" /></figure><p>You can go on Setupon Salesforce and search for Deploment. Click on Deploment status and you can see how everything went!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*ejMiAfIjdAQ2XzEDp1Swog.png" /></figure><p>If you see something like this, then everything went well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LRN4ZnG7Gb2mpuHYoy6zIg.png" /></figure><p>If you see something like this, then nothing was deployed, so check if you have misspelled the files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*vZ3F8ALTbVUsMqeFMSnn1w.png" /></figure><p>So folks, I hope this helps so go head and delete some old Apex code that is only lying around and hurting your processes!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0f22d1783e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>