<?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 Zsombor Földesi on Medium]]></title>
        <description><![CDATA[Stories by Zsombor Földesi on Medium]]></description>
        <link>https://medium.com/@zsombor-flds?source=rss-12ddaf2f0a31------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bFx_xpIF1rkTu98Ny_v2VQ.png</url>
            <title>Stories by Zsombor Földesi on Medium</title>
            <link>https://medium.com/@zsombor-flds?source=rss-12ddaf2f0a31------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 01:33:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zsombor-flds/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[Microbatch Incremental Models in dbt]]></title>
            <link>https://zsombor-flds.medium.com/microbatch-incremental-models-in-dbt-146a967871db?source=rss-12ddaf2f0a31------2</link>
            <guid isPermaLink="false">https://medium.com/p/146a967871db</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[dbt-labs]]></category>
            <category><![CDATA[snowflake]]></category>
            <dc:creator><![CDATA[Zsombor Földesi]]></dc:creator>
            <pubDate>Sun, 13 Oct 2024 11:37:14 GMT</pubDate>
            <atom:updated>2024-10-13T11:37:14.473Z</atom:updated>
            <content:encoded><![CDATA[<p>Working with large-scale time-series datasets often presents challenges in maintaining a balance between efficiency, resiliency, and simplicity within data pipelines. To address these challenges, dbt is introducing a new feature called: <strong>Microbatch Incremental Models</strong>.<br>This strategy is designed to enhance the way you handle incremental data loads, making your data pipelines more efficient and robust. In the upcoming paragraphs, I collected my thoughts on the benefits of using this strategy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*sIUxRvMq1efgKTvDvvWcDg.png" /></figure><h3>What is a Microbatch Incremental Model?</h3><p>In dbt, incremental models are a powerful materialization strategy that allows you to update your data warehouse tables by processing only the new or changed/modified data since the last run. Traditionally, this manifests into adding new rows or updating existing ones without reprocessing the entire dataset (defined by the selected <a href="https://docs.getdbt.com/docs/build/incremental-strategy">incremental strategy</a>)</p><p>Microbatch incremental models take this concept a step further. <br>Instead of processing all new data in one go, microbatching splits the data into smaller, more atomic batches based on a time-based partitioning scheme (e.g : daily). Each batch corresponds to a specific time window and is processed independently. <br>This approach offers several benefits:</p><ul><li><strong>Efficiency</strong>: By processing smaller chunks of data, you can optimize resource usage and reduce processing time.</li><li><strong>Resiliency</strong>: If a batch fails, you can retry it without reprocessing other batches.</li><li><strong>Concurrency</strong>: In future updates, batches can be processed concurrently, further speeding up data transformations.</li><li><strong>Idempotency</strong>: Since each batch is independent, reprocessing a batch should yield the same result.</li></ul><h3>Enabling Microbatch in dbt</h3><p>As of writing this post, the microbatch strategy is available in <a href="https://github.com/dbt-labs/dbt-core/discussions/10672"><strong>dbt Core v1.9</strong></a>. To enable it, set the environment variable:</p><pre>DBT_EXPERIMENTAL_MICROBATCH=True</pre><h3>How Microbatch Works</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*qbEiEhyQK41WvvYML8MxEQ.png" /></figure><p>When you run a microbatch model, dbt:</p><p>By default, the time window is set to <strong>daily</strong> batches, but you can configure this granularity based on your needs. With large events like clickstream, I saw performance benefits with hourly batches as well.</p><p>When writing your model query:</p><ul><li><strong>Process One Batch at a Time</strong>: Your query should handle data for a single batch only.</li><li><strong>No Need for </strong><strong>is_incremental() Conditions</strong>: Microbatching abstracts away the need for these conditions.</li><li><strong>Auto-Filtering of Upstream Models</strong>: dbt automatically filters upstream models based on the event_time config.</li><li><strong>Handle Late arriving record: </strong>you can configure a loopback window for events outside the daily interval.</li></ul><p>A sample Incremental with the Microbatch strategy:</p><pre>{{ config(<br>    materialized=&#39;incremental&#39;,<br>    incremental_strategy=&#39;microbatch&#39;,<br>    event_time=&#39;event_occurred_at&#39;,<br>    begin=&#39;2024-01-01&#39;,<br>    batch_size=&#39;day&#39;,<br>    lookback=3,<br>    full_refresh=False<br>) }}<br>/* This is automatically filtered by the<br>event_time(event_occurred_at), with the window defined by batch_size<br>*/<br>select * from {{ ref(&#39;stg_events&#39;) }} </pre><h3>Benefits compared to the legacy Incremental strategies</h3><p>Traditional incremental models in dbt require you to define what constitutes “new” data using a is_incremental() conditional block. You&#39;re responsible for crafting SQL that accurately filters new or updated records.</p><p>Microbatch incremental models simplify this by:</p><ul><li><strong>Eliminating the Need for Conditional Logic</strong>: No is_incremental() blocks are necessary.</li><li><strong>Automating Data Partitioning</strong>: dbt handles the batching based on your event_time and batch_size.</li><li><strong>Enhancing Efficiency and Resiliency</strong>: Independent batch processing allows for better error handling and potential concurrent execution.</li></ul><h4>Side note for Snowflake Users</h4><p>Although you can gain these benefits by leveraging microbatches in most adapters. If you are on Snowflake I would highly suggest testing the <a href="https://github.com/arnoN7/dbt-incremental-stream">dbt-incremental-stream</a> package first. The incr_stream package uses <a href="https://docs.snowflake.com/en/user-guide/streams-intro">Snowflake Stream And Task</a> which can significantly boost your dbt model loading window.</p><h3>Conclusion</h3><p>The microbatch incremental strategy in dbt is a significant advancement in handling time-series data transformations. By breaking down data processing into independent, idempotent batches, you can gain benefits in the names of efficiency, resiliency, and scalability in your dbt models. <br>Now we just need to finally resolve the issues with Snapshots — but that’s a whole different story for another day.<br>You can read more details about the dbt’s microbatch strategy in the official documentation <a href="https://docs.getdbt.com/docs/build/incremental-strategy">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=146a967871db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an IoT Data Pipeline for Energy Consumption Monitoring on the Edge with DuckDB and Malloy]]></title>
            <link>https://medium.com/hiflylabs/building-an-iot-data-pipeline-for-energy-consumption-monitoring-on-the-edge-with-duckdb-and-malloy-1c66ba266f2f?source=rss-12ddaf2f0a31------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c66ba266f2f</guid>
            <category><![CDATA[malloy]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[monitor]]></category>
            <category><![CDATA[duckdb]]></category>
            <category><![CDATA[data-pipeline]]></category>
            <dc:creator><![CDATA[Zsombor Földesi]]></dc:creator>
            <pubDate>Thu, 04 May 2023 06:46:37 GMT</pubDate>
            <atom:updated>2023-05-04T06:46:37.118Z</atom:updated>
            <content:encoded><![CDATA[<p>As many of you probably know, energy prices in the EU skyrocketed in 2022. My primary heating source is electric, so last winter, I wanted to understand my home electricity usage better.</p><p>That’s why I developed a data pipeline that allows me to monitor the electricity consumption of my home.</p><p>At work, I spend most of my Engineering related time interacting with Cloud Services, so to explore something different, I challenged myself to develop a data pipeline that only computes on the edge.</p><p>My first idea was to invest in smart plugs that enable the end user to pull the measured consumption data from the device, but at the time, I wasn’t lucky enough to find one that matched my preferences because most of them lacked a public API. In the past, I spent more time than I’d like to admit trying to reverse-engineer things like my <a href="https://www.nobo.hu/en/products/nobo-eco-hub">Nobo Hub</a>, but in this situation, it seemed too much of a hassle. And while I’m impressed by the flourishing smart home community, the direction of utilizing a home assistant such as<a href="https://www.home-assistant.io/"> home-assistant.io</a> didn’t appear worthwhile for me since I was only going for energy monitoring.</p><p>Fortunately, 2022 was the year I discovered DuckDB, and ever since, I have been looking for opportunities to get more out of it: whether it comes to building CLIs or bringing the “Cloud” to my laptop.</p><p>After a bit of tinkering, I came up with this simple architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i7OQZyPc0AmYqfoMx7B0-Q.png" /></figure><p>To sum it up, I set up an ESP8266 to read the measurement data from the Smart Meter via its serial port. The collected events were then parsed and sent to an API running on a Raspberry PI. Afterward, I persist the raw events as parquet files, and lastly, I utilize DuckDB with Malloy for transformation and analysis. In the next few paragraphs, I will walk you through each stage.</p><h3>Event Collection</h3><p>Fortunately, the Smart Meter provided by my electricity supplier is equipped with a <a href="https://en.wikipedia.org/wiki/Open_metering_system">DSMR</a> standard P1 port. DSMR stands for Dutch Smart Meter Requirements, a standard for smart meters created in the Netherlands. This standard enables end users to monitor their energy consumption/billing data.</p><p>I came across several projects that aimed to parse data from Smart Meters, such as <a href="https://github.com/dsmrreader/dsmr-reader">dsmr-reader</a>, but ultimately, none of them were compatible with the <a href="https://www.eon.hu/content/dam/eon/eon-hungary/documents/Muszaki-ugyek/Fogyasztasmerok-leirasa/sanxing-sx6x1/EON-leiras-az-ugyfelek-szamara-SX6X1-S12U16-S34U18-V010.pdf">particular Smart Meter</a> I have. However, with some troubleshooting and online research, I found a datasheet that helped me parse the messages received via the serial interface. The raw data gained from the Serial Connection looked like <a href="https://gist.github.com/zsombor-flds/665c34de506a52340a229e0b3659b246.">this</a>.</p><p>I programmed a NodeMCU to collect the events from the Smart Meter. The app retrieves data from the P1 serial connection, then parses the relevant information from the raw event, and finally transfers it as a JSON object to a simple Python API. Additionally, I added a DHT22 sensor to measure outdoor temperature and humidity.</p><p>Example output from the ESP:</p><pre>{<br> &quot;power_timestamp&quot;: &quot;230421091600S&quot;,<br> &quot;power_device_name&quot;: &quot;AUX103030299999&quot;,<br> &quot;power_breaker_status&quot;: &quot;000&quot;,<br> &quot;power_consumption&quot;: &quot;009994.902*kWh&quot;,<br> &quot;l1_phase_voltage&quot;: &quot;240.5*V&quot;,<br> &quot;l2_phase_voltage&quot;: &quot;239.8*V&quot;,<br> &quot;l3_phase_voltage&quot;: &quot;236.3*V&quot;,<br> &quot;l1_phase_current&quot;: &quot;000*A&quot;,<br> &quot;l2_phase_current&quot;: &quot;000*A&quot;,<br> &quot;l3_phase_current&quot;: &quot;000*A&quot;,<br> &quot;humidity&quot;: 40.4,<br> &quot;temperature&quot;: 7.6<br>}</pre><p>You can check out the PoC version of the event collection <a href="https://gist.github.com/zsombor-flds/1a91e3f953c9d6be04f0bca12e9d74c2)">here</a>.</p><h3>Persist Service</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*tQlg9qLnKpk8LZr0zhM20w.png" /><figcaption>Storage structe</figcaption></figure><p>To store data collected by the ESP8266, I created a simple Flask service with Python that persists the received data as partitioned parquet files. I chose this approach because it’s simple and maintainable.</p><pre>@app.route(&quot;/sensor&quot;, methods=[&quot;POST&quot;])<br>async def dummly_handle_request():<br>  raw_data = json.loads(request.data)   <br>  transformed = transform(data=raw_data)<br>  persist_to_parquet(data=transformed)<br><br>  return &quot;ok&quot;</pre><p>Since the update interval is between 1–10 seconds for the DSMR protocol, I didn’t worry about the throughput being too large. A simple HTTP service was enough to transform the serialized JSON objects into parquet. Moreover, since my plan was to deploy it on a Raspberry PI, I didn’t want to introduce more complexity and service costs with a regular streaming platform/ message broker like Red Panda. Realistically, a lightweight MQTT service would also have worked, and obviously, I would choose those options in a production environment.</p><pre>from deltalake.writer import write_deltalake<br>write_deltalake(&#39;/raw/&#39;,<br>  df,<br>  mode=&#39;append&#39;, <br>  partition_by=[&#39;year&#39;, &#39;month&#39;, &#39;day&#39;]<br>)</pre><h3>Transformation and exploration with DuckDB and Malloy</h3><p>Once the data is available in date partitioned parquet structure, I used <a href="http://duckdb.org/">DuckDB</a> to query and explore the dataset directly. DuckDB is optimized for analytical workloads — therefore, it boasts exceptional query performance thanks to its columnar storage and vectorized query execution engine. <br>I chose DuckDB because it’s lightweight and embeddable, which makes it an excellent fit for edge computing.</p><p>With DuckDB, reading from parquet files is as easy as:</p><pre>select<br>  measure_timestamp,<br>  power_consumption_khw,<br>  outside_temperature  <br>from read_parquet(&#39;~/raw/year=*/month=*/day=*/*.parquet&#39;)<br>limit 10;</pre><p>After applying some basic wrangling of the collected data, I wanted to explore and visualize it to uncover patterns and insights. I used <a href="https://www.malloydata.dev/">Malloy</a> to analyze and create charts to display energy consumption trends and check the correlation with outside temperature and humidity levels.</p><p>A little background info: Malloy is an innovative language designed to define data relationships and transformations. It serves as both a semantic modeling language and a structured querying language (pun intended), enabling users to run queries on relational databases. DuckDB is natively supported in Malloy, along with BigQuery, and Postgres. Therefore, it is a superb choice to create reusable explores against your data model.</p><p>I used the Visual Studio Code extension in a Remote Explorer to streamline the process of constructing queries and generating visualizations and dashboards well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3smjX9sIRfq01K7qfUZBLQ.png" /><figcaption>Monthly Power Consumption</figcaption></figure><p>I let this pipeline run in the past five months to ensure I have enough data to make my observations. Through these visualizations, I identified several energy consumption peaks throughout the day that could be addressed by adjusting my home’s heating schedule. Armed with this knowledge, I was able to take steps to optimize my home’s energy usage and reduce consumption, cut down my electricity bill, and reduce my impact on the environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i7xJV6oudPCDToNmphaEXA.png" /><figcaption>Hourly Power Consumption in a day</figcaption></figure><p>It was very instructive for me to build a data processing pipeline only using open-source technologies without touching cloud services or large on-prem infrastructures. Most of the prototype code is available <a href="https://github.com/zsombor-flds/dsmr-data-flow">here</a>. If you want to learn more about Malloy, check out this interactive <a href="https://github.dev/malloydata/try-malloy/airports.malloy">demo</a>.</p><p>In conclusion, I hope this blog post has provided you with valuable insights into the process of creating efficient IoT pipelines and demonstrated the impressive potential of DuckDB for enhancing local performance that rivals the Cloud.</p><p>Feel free to reach <a href="http://hello@hiflylabs.com/">out</a> if you’re interested in building a similar data pipeline or have any questions about my setup.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c66ba266f2f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hiflylabs/building-an-iot-data-pipeline-for-energy-consumption-monitoring-on-the-edge-with-duckdb-and-malloy-1c66ba266f2f">Building an IoT Data Pipeline for Energy Consumption Monitoring on the Edge with DuckDB and Malloy</a> was originally published in <a href="https://medium.com/hiflylabs">Hiflylabs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Level up your CI pipelines with Dagger.]]></title>
            <link>https://medium.com/hiflylabs/level-up-your-ci-pipelines-with-dagger-8425b9568935?source=rss-12ddaf2f0a31------2</link>
            <guid isPermaLink="false">https://medium.com/p/8425b9568935</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[dagger]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Zsombor Földesi]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 10:51:28 GMT</pubDate>
            <atom:updated>2023-04-13T09:06:52.466Z</atom:updated>
            <content:encoded><![CDATA[<h3>Level up your CI pipelines with Dagger</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zI2snQGcamZMusTntQD1dg.png" /></figure><p>A typical Analytics Engineer’s development workflow consists of many tools. <br>We use sqlfluff to lint the models, git hooks to raise issues automatically, Spectacles for testing Looker, and the Datafold CLI to compare datasets. This list varies based on the different business needs/environments.</p><p>Often you want to execute these processes:</p><ul><li>locally before a commit/PR</li><li>automatically as part of some CI automation</li></ul><p>Tools tend to use different interfaces for invocation. You can use some of them as git hooks and others with fancy CLIs, but managing/setup all this can be time-consuming and challenging for less tech-savvy Analytics Engineers.</p><p>Previously, I used to wrap most of these as GitHub Actions. If you’re lucky, you can find GitHub Actions provided by the vendor or the community that you can plug and play, but in many cases, you need to create your workflow. This setup works well, but not all CI tools have the same thrilling community as <a href="https://github.blog/2019-11-06-a-thousand-community-powered-workflows-using-github-actions/">GitH</a>ub.</p><p>Once the action was properly set up, I used a tool called<a href="https://github.com/nektos/act"> act</a> to execute the CI pipelines locally.</p><p>Although I liked this setup because it enabled us to evaluate changes faster, with this approach, it was still painful to reproduce these actions in different CI runners (e.g., from GitHub Actions to Gitlab-CI).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bgVJX8QUXvkPCyU7" /></figure><p>In the following paragraphs, I will show you how easy it is to solve these problems using <a href="https://github.com/dagger/dagger">Dagger</a>.</p><h3><strong>So, what on earth is Dagger, and why should you care?</strong></h3><p><a href="https://dagger.io/">Dagger</a> is an open-source programmable <a href="https://en.wikipedia.org/wiki/CI/CD">CI/CD</a> engine created by <a href="https://www.linkedin.com/in/solomonhykes/">Solomon Hykes</a>, the founder of <a href="https://www.docker.com/">Docker</a>. Dagger makes it easy to develop portable CI pipelines in your favorite programming language that executes entirely on standard OCI containers..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y0H2F5D0OngJSp84" /></figure><blockquote>‘<em>Dagger does not replace your CI: it improves it by adding a portable development layer on top of it.’</em><br>src: <a href="https://docs.dagger.io/1220/vs/">https://docs.dagger.io/1220/vs/</a></blockquote><h3>CI/CD as Code</h3><p>Unlike conventional CI/CD tools, Dagger lets you write a pipeline as code instead of writing proprietary YAML, you can write your CI/CD code in CUE, Go, Python, or NodeJS. This approach makes it easy to create dynamic pipelines and enables you to test your CI/CD just like any other project element.</p><h3>Run Anywhere</h3><p>You can test and debug instantly on your local machine. No need to push your changes to trigger the CI pipeline can run it anytime in your own isolated environment. This enables you to get instant feedback on the impact of your changes.</p><p>Dagger executes your pipelines entirely as <a href="https://opencontainers.org/">standard OCI containers</a>. Therefore, it is compatible with most CI/CD runtime environments, including:</p><ul><li>GitHub Actions</li><li>GitLab-CI</li><li>Travis-CI</li></ul><p>This approach has the benefit of enabling you to execute the same CI process everywhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*njBFj8JfMFbS9EvW" /></figure><h3>Performance</h3><p>Caching across pipeline runs is one of Dagger’s most potent but often overlooked power.</p><p>You can designate one or more directories as cache volumes in your pipeline, and its content will be persistent across runs. This makes it possible to reuse the cache’s contents at each pipeline run, which speeds up pipeline operations.</p><h3>Demo</h3><p>To demonstrate how easy it is to set up a CI process, let’s write our first pipeline with Dagger.</p><p>Our dummy pipeline will:</p><ul><li>initialize the Dagger client</li><li>mount the dummy projects dir to the container</li><li>install some Python dependencies</li><li>run the linter by executing the sqlfmt command</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*it3qp1sK6FLd25W1" /></figure><p>Simple as that, we were able to create a universal CI pipeline that can be executed on different CI runners.</p><p>You can execute the example locally:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xJxleOMYPrCxGVxY" /></figure><p>Or wrap the same pipeline as Github Actions just like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XOOULD8WtA-lfjtA" /></figure><p>This demonstrates how Dagger makes it easy to create custom pipelines that fit together like Lego pieces. Now, my CI setup is primarily built around Dagger for the build, testing, publish pipelines, and with this approach, I can run my CI anywhere I can run Docker containers.</p><p>In conclusion, Dagger is a powerful tool that enables Analytics Engineers to create portable CI pipelines in their favorite programming language and execute them in any Docker-compatible runtime environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8425b9568935" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hiflylabs/level-up-your-ci-pipelines-with-dagger-8425b9568935">Level up your CI pipelines with Dagger.</a> was originally published in <a href="https://medium.com/hiflylabs">Hiflylabs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Observability on Steroids]]></title>
            <link>https://medium.com/hiflylabs/data-observability-on-steroids-52dc3cfb0682?source=rss-12ddaf2f0a31------2</link>
            <guid isPermaLink="false">https://medium.com/p/52dc3cfb0682</guid>
            <category><![CDATA[data-observability]]></category>
            <category><![CDATA[data-monitoring]]></category>
            <category><![CDATA[dbt]]></category>
            <dc:creator><![CDATA[Zsombor Földesi]]></dc:creator>
            <pubDate>Tue, 05 Jul 2022 17:30:26 GMT</pubDate>
            <atom:updated>2022-07-08T06:00:06.341Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AAu8ZAnhJ0P01X-qFqLBGg.jpeg" /></figure><p>For a production data platform, we need transparent monitoring. <br>In the dbt Cloud interface, you can view the job statuses/logs, but custom alerts (email, SMS, slack notification) are not currently available or at least not as informative as they should be.</p><p>Ideally, we need a central tool where we can see the event/logs generated by the Ingestion tool, dbt, and other components of our data stack. <br>Of course, this requires relatively extensive interfaces between the components (APIs, RPCs, post hooks), and currently, there isn’t a silver bullet for this problem. We feel this part will still evolve a lot in the future and the community will figure out how to manage the collective orchestration in this fragmented ecosystem. What is certain is that this <a href="https://roundup.getdbt.com/p/ep-26-the-bundling-vs-unbundling?s=r">debate</a> is not over yet.</p><p>There are <a href="https://www.datafold.com/blog/different-ways-to-diff-data">plenty of ways</a> how you can look at data diffs ranging from databases to smaller pieces of your platform. Among those, unit testing has its limitations. You can use <a href="https://github.com/dbt-labs/dbt-utils">dbt_utils</a> and the portable elements from Great Expectations to test your data after a change, but it can be cumbersome to scale those tests when you add new columns to the table. <br>For instance, the testing logic has to be updated and expanded to keep the optimal coverage. On a large scale, the marginal benefit of writing those tests diminishes and alerting fatigue can become a serious issue. An automated data monitoring and diffing tool needs no manual maintenance on the user side and is able to catch any anomalies transparently. It should be able to gauge what counts as a breaking change and what is falling into the categories of normal behavior. That way, we are able to minimize false positives and keep human interaction as low as possible.</p><p>I think it’s almost half the success if we can get notifications about tests/schema drifting/data freshness errors <em>and</em> the logs are available in one central location, but fortunately, there are several companies now trying to cross this chasm and the area is being mentioned in the <a href="https://humansofdata.atlan.com/2022/01/the-future-of-the-modern-data-stack-in-2022/">most exciting trends for 2022</a>.</p><p>There are more of these tools than we can count on two hands, so we will only <strong>highlight a few </strong>that stood out to us with some of their qualities and fits the dbt-centric workflow. If you are interested in this field, you can find a more complete(ish) list <a href="https://www.metaplane.dev/state-of-data-quality-monitoring-2022">here</a>!</p><h3>re_data</h3><ul><li><strong>Strengths:</strong> Self-hostable, dbt native</li><li><strong>Use-cases:</strong> Catch data bugs before your CEO by just installing a package in dbt.</li></ul><p>r<a href="https://www.getre.io/">e_data</a> (mentioned among the<a href="https://dev.to/kuwala_io/what-are-the-hottest-dbt-repositories-you-should-star-on-github-2022-here-are-mine-2fj3"> hottest repositories</a>) is one of the few open-source alternatives for this problem, (<em>which handles the monitoring aspects and is also targeted for the MDS ecosystem</em>). It combines both data tests, gives you a monitoring dashboard, and it’s even capable of sending Slack notifications. It can be installed as a dbt package, so it integrates well with the ecosystem and leverages the manifest file of dbt to generate model lineages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TYkoH8vtBDMBbBeqQS1Nvg.png" /></figure><p>Imagine a dbt or Great Expectation testing suite which is made to be able to create time-based metrics and <a href="https://docs.getre.io/latest/docs/reference/anomaly_detection">track anomalies</a> using ML accordingly. In fact, they were one of the first who decided to bring monitoring and testing to the same platform.</p><p>However, you have to host a web app somewhere and manage the scheduling of the notification package for the time being. A cloud-hosted version is already on the roadmap to cover all sorts of enterprise users. We would consider this rather an advantage because not many of the other vendors allow you to host with its UI, and the setting can also keep your data secure in your own cloud from being distributed to third parties.</p><h3>Datafold</h3><ul><li><strong>Strengths:</strong> Data-diff, Profiling</li><li><strong>Use-cases:</strong> Avoid merging in breaking changes or changes that cause shifts in metrics that should be intact after the change (e.g. row counts).</li></ul><p>Sometimes a seemingly small change in your codebase can cause a lot of problems in downstream models and dashboards, invisible to the naked eye when submitting a PR.</p><p>“<a href="https://www.datafold.com/">Datafold</a> gives you confidence in your data quality through diffs, profiling, and anomaly detection.”</p><p>In terms of usability, it is as simple as any other similar tool. You need to supply the connection credentials as well as a temporary schema reserved for Datafold to materialize intermediate results. After that, you should be able to define metrics, observe the catalog of the database and run data diffs. An additional configuration is needed if you want to integrate Datafold with your GitHub workflow through the API.</p><p>I think the most interesting feature is that it’s capable of diffing datasets. Setting this up through GitHub Actions is pretty straightforward. All you need to do is first define the workflow YAML for dbt-core build and submit all the artifacts after compilation to Datafold through the API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rf6mzIO3qCLlBEtCaJnIPw.png" /><figcaption>Source: Datafold</figcaption></figure><p>You can write your own metrics in SQL, and Datafold makes sure to periodically monitor those metrics. Under the hood, it calculates a prediction interval for these metrics and triggers an alert (via mail, Slack or PagerDuty) when it falls outside the expected range.</p><p>The data-diff feature can be very handy to shift data within the source (web-based) or migrate from on-premise to cloud (CLI feature) without losing an event in the process.</p><p><strong>Scenario: </strong>Let’s say that you used the zero-copy-clone feature to migrate your tables to another schema or you decide to move to another warehouse vendor. Later on, you redact an order because it was wrongly recorded in the order lines table. Running the datadiff feature you realize that the three rows associated with that particular order were only deleted in the replicated table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ALxtEmbZVuuZmBd5" /></figure><p>Usually, it can be very painful and costly to scan through terabytes of data, but Datafold’s checksum algorithm makes sure that the diffing is still performant on a large scale. It simply hashes values to numbers, sums them up, and compares them across data sources. If there is a difference, the algorithm creates smaller and smaller segments in the data until it finds the rows responsible for the regression.</p><p>It allows you to create a per-row summary of missing and unmatching rows, which then you can use to spot-check errors and fix them without having to re-materialize your tables. Read more on checksums <a href="https://sirupsen.com/napkin/problem-14-using-checksums-to-verify">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*WkLjCgSdUhKmp3gOaVa1Sw.png" /></figure><p>Other notable features are column-level lineage, data profiling, and cataloging. Cataloging is a great extra feature to get a quick glance at the data equipped for search until a column level, sampling, and data ownership. I think such a feature falls outside the area of issues that Datafold wants to solve for its customers.</p><p>As far as BI tools are concerned, Datafold only supports Mode for now, but soon expects to bring the Looker integrations to users. This can be decisive for those who want to see the end-to-end lineage. What is also promising is that they are also planning to add Hightouch support, which would further expand your data visibility beyond classical ELT.</p><h3>Metaplane</h3><ul><li><strong>Strengths:</strong> Real-time monitoring, Actionable-alerting</li><li><strong>Use-cases:</strong> Be the first to know about data anomalies in the system and avoid client emails like “Hey, this dashboard seems funky”. “Numbers don’t seem to align here, can you fix it?</li></ul><p><a href="https://www.metaplane.dev/">Metaplane</a> (The Datadog of data) integrates across your data stack from source systems, through warehouses to BI dashboards, then identifies normal behavior and alerts the right people when things go awry.</p><p>While Datafold focuses on regressions introduced by codebase changes, Metaplane took the initiative to be a classical monitoring tool to identify silent data bugs even when it’s not flagged by the pipeline. An example here could be data source issues which significantly increase generated revenues displayed on the platform. This is not detectable by tools focused on tools kicked off by development work but occurs unexpectedly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gfgh8uX4ADOKI95X-fiuCQ.png" /><figcaption>Source: Metaplane</figcaption></figure><p>Unlike Datafold, Metaplane offers out-of-the-box tests even for statistical properties. It also checks for schema changes on the go. <br>Where Metaplane also has a slight advantage compared to others, is in terms of their Slack integration, which allows the end-user to interact with the anomaly and mark them either as an anomaly or normal behavior. This way, we can optimize for alert fatigue and false positives by altering the prediction interval.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/0*K9W9-_BgNkM7cWMe" /></figure><h3>Elementary</h3><ul><li><strong>Strengths:</strong> Artifacts uploader, dbt native</li><li><strong>Use-cases:</strong> I want to also see metrics about my recent dbt builds, but still don’t miss out on cool monitoring features by installing a package.</li></ul><p>Elementary is an open-source app that enables data teams to detect anomalies in their data before their users do.</p><p>It enables you to monitor the key data quality metrics, freshness, volume, and schema changes, including anomaly detection, configured and executed as dbt tests.</p><p>The included Data observability report enables you to examine the output of the dbt test:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sff1zibWkfe5huPhNcD1-A.png" /></figure><p>In our opinion, the most interesting feature of the <a href="https://github.com/elementary-data/dbt-data-reliability">dbt-data-reliability</a> package, is that it can be used to load the output of the <a href="https://docs.getdbt.com/reference/artifacts/run-results-json">run result</a> into the target database. This basic functionality is currently missing from the dbt core, and we are thankful to the fellows from Elementary for making this available to everyone. This makes us excited and it made many ideas feasible, but more on that later.</p><h3><strong>Closing Remarks</strong></h3><p>That being said, that is no ‘best tool’ on the market as of now, but we can see a pattern of similar companies trying to cover as many features as they can and “bundle” (pun intended) together with data cataloging, observability, and governance with a spice of ML. They are aggressively tackling this area to a point where they are inspired by each other (sometimes resulting in a <a href="https://news.ycombinator.com/item?id=30558137">conflict</a>). Each of the tools has its own stand-out features, so you have to make sure to choose the best one for your typical workflow. Hopefully, we are going to see more and more organizations interested in data durability and visibility, incentivizing the development of utilities we have been missing so much but weren’t worth yet implemented in the Modern Data Stack community.</p><p>We hope that one of the showcased tools has aroused your interest and that by introducing it to your project you will gain more confidence in your data platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52dc3cfb0682" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hiflylabs/data-observability-on-steroids-52dc3cfb0682">Data Observability on Steroids</a> was originally published in <a href="https://medium.com/hiflylabs">Hiflylabs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Robust deployment pipelines with dbt]]></title>
            <link>https://medium.com/hiflylabs/robust-deployment-pipeline-with-dbt-b3799559d978?source=rss-12ddaf2f0a31------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3799559d978</guid>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Zsombor Földesi]]></dc:creator>
            <pubDate>Wed, 08 Jun 2022 10:14:18 GMT</pubDate>
            <atom:updated>2022-06-20T13:37:00.724Z</atom:updated>
            <content:encoded><![CDATA[<p>I think a robust Release process is an unavoidable accessory for a stable Analytical warehouse. With a stable deployment cycle, we can increase the reliability of the platform. In the following next paragraphs, I will give an insight into the best practices we use in our dbt projects.</p><p>Luckily, we have the option of using the out-of-the-box solutions here, but we can extend the default option in several ways.</p><p>In my opinion, a Deployment process starts with a good Pull Request. You can read about PR best practices <a href="https://medium.com/@meshantha/guide-in-making-your-perfect-pull-request-d6f757f73276">here</a>, the PR template we use can be found <a href="https://docs.getdbt.com/blog/analytics-pull-request-template">here</a>.</p><h3><strong>Continuous integration with dbt Cloud</strong></h3><p>Continuous integration (CI) is a software engineering practice in which changes to the code base are tested immediately.</p><p>The standard solution provided by dbt allows each PR to create a temp schema in which to run a dbt run + test command, to verify that nothing has break during the development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*42URRRJdietzTkCc" /></figure><p>How to setup: <a href="https://docs.getdbt.com/docs/dbt-cloud/using-dbt-cloud/cloud-enabling-continuous-integration">link</a></p><p>With the <a href="https://discourse.getdbt.com/t/how-we-sped-up-our-ci-runs-by-10x-using-slim-ci/2603">slim CI</a> option, we have the ability to run only the modified models + their downstream models — reducing the CI job run time.</p><pre>dbt build --select state:modified+</pre><p>Note that while it’s quicker to set up a CI pipeline with dbt Cloud, there are several ways to implement this with dbt core as well.</p><h4>Zero Copy Clone CI on Snowflake</h4><p>Another great way to further optimize the CI pipelines is to leverage the<a href="https://docs.snowflake.com/en/sql-reference/sql/create-clone.html"> Zero Copy Clone</a> feature in Snowflake.</p><p>With this approach Instead of creating temp schema for every CI job you create a copy of the PROD database and run the test on the clone environment to ensure that cross-references is up to date in a deferred run. You can find an awesome detailed guide on how to setup a ZCC CI job <a href="https://medium.com/airtribe/test-sql-pipelines-against-production-clones-using-dbt-and-snowflake-2f8293722dd4">here</a>.</p><h3>Blue Green Deployment</h3><p>This deployment method is inherited from software development.</p><blockquote>By definition:<br>“Blue green deployment is an application release model that gradually transfers user traffic from a previous version of an app or microservice to a nearly identical new release — both of which are running in production.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*JVyrgoij3JnzdiHs" /></figure><p>With this deployment method, we have two identical environments(PROD, PREPROD). The production job always is running in the PREPROD environment then if the job is finished with a success (e.g all tests run successfully, every table has been updated) we swap the two environments. -&gt; this approach radically reduces downtime.</p><p>You can read about how to set this up here: <a href="https://discourse.getdbt.com/t/performing-a-blue-green-deploy-of-your-dbt-project-on-snowflake/1349">link</a></p><p>(Important Note: The community prefers the word combination STAGE and PROD in practice. However, I think this can cause misunderstandings, as the first layer of the database is also called a staging layer, not to mention that Snowflake’s external tables also have Stages. )</p><h3>More best practices</h3><p>My two favorite additions are <a href="https://github.com/sqlfluff/sqlfluff">sqlfluff</a> and <a href="https://pythonlang.dev/repo/offbi-pre-commit-dbt/">pre-commit-dbt</a> . Both tools can easily be used as a Github Action or as a git ho.</p><h4>sqlfuff</h4><p><a href="https://github.com/sqlfluff/sqlfluff">Sqlfluff</a> is the go-to linter for dbt projects, it enforces stylistic rules on your code. These rules only change the way the code is formatted, not the business logic behind it. This will ensure that the project developers follow the code style guide, no matter if they are <a href="https://mode.com/blog/should-sql-queries-use-trailing-or-leading-commas/">leading or trailing comma</a> persons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*_IZvE1EpsBqPGzA9W0GV6A.png" /></figure><h4>pre-commit-dbt</h4><p>With <a href="https://github.com/offbi/pre-commit-dbt">pre-commit-db</a>t, you can ensure that your project stays in order as the number of models increases.</p><p>For example, you can automatically test whether the columns in the models have a <a href="https://github.com/offbi/pre-commit-dbt/blob/main/HOOKS.md#check-model-columns-have-desc">description</a>. This speeds up Code Reviews since you can test a lot of formal requirements in an automated fashion.</p><h4><strong>Spectacles</strong> (for Looker users)</h4><p>The previous points are natively available with dbt (at most with a bit of hacking). Spectacles, however, takes advantage of the <a href="https://benn.substack.com/p/the-data-os?s=r">data OS</a> aspect of the ecosystem.</p><p>With this tool, we have the opportunity to do testing not only at the database level but also in the Looker dashboards sitting on the top of the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K-eGH6wykgDSUAK8" /></figure><p>Spectacles use the Looker API to test whether changes to the database have broken something on the frontend side, ensuring that your Looker Explores actually work.</p><p>More on Spectacles here: <a href="https://www.spectacles.dev/">link</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3799559d978" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hiflylabs/robust-deployment-pipeline-with-dbt-b3799559d978">Robust deployment pipelines with dbt</a> was originally published in <a href="https://medium.com/hiflylabs">Hiflylabs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BI as a Business-Critical Application]]></title>
            <link>https://medium.com/hiflylabs/bi-as-a-business-critical-application-c31e9297cb0d?source=rss-12ddaf2f0a31------2</link>
            <guid isPermaLink="false">https://medium.com/p/c31e9297cb0d</guid>
            <category><![CDATA[analytics-engineering]]></category>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-quality]]></category>
            <dc:creator><![CDATA[Zsombor Földesi]]></dc:creator>
            <pubDate>Fri, 29 Apr 2022 11:23:34 GMT</pubDate>
            <atom:updated>2022-06-20T13:06:40.900Z</atom:updated>
            <content:encoded><![CDATA[<p>As more companies begin to adapt their Analytics platform with dbt, one demand from enterprise users is becoming more apparent: Data Reliability.</p><p>Companies are investing more and more money to exploit the available data, and the exposure to data quality/availability is growing exponentially.</p><p>BI teams are no longer isolated within the organizations but contribute to the business continuity at the operational level. So we have to accept that modern BI platforms have become business-critical applications. Analytical DWHs are no longer used only by business analysts for reporting, but the data is circulated back to the core business systems.</p><p>Fully automated data-based applications amplify the competitiveness of companies, so bad data or faulty KPIs can have extremely detrimental consequences.</p><p>In the next few posts, I will try to summarize the building blocks that can make a data platform more robust.</p><p>We need to be aware that dealing with data quality issues has always been present in BI, but today we have more mainstream options to deal with these challenges than 5–10 years ago.</p><p>To put it simply, the motivation is still the same, we should be aware of the data errors before they hit production, and surely before the end-users recognize them. Better have an automated warning and a paused data load about a missing column than an email from the CEO telling us that the “X system” is down “again”.</p><p>(Note: I have consciously omitted a very important dimension from my thought process. <br>In the evolution, BI platforms have become complex and diverse.<br>Now we do not just have multiple variant input data sources with different characteristics, and large amounts of data volumes, but also have to deal with infinitely more data consumers of the Analytical Platforms e.g : dashboards, reports, other applications, etc . )</p><p>For fellows from the software development scene, robust CI processes, automated testing, and extensive monitoring are nothing new. <br>The last 15 years have brought them countless steps forward.</p><p>Solutions such as Jenkins or Gitlab CI for CI/CD, Datadog, ELK stack for aggregated logs and monitoring, Unit / Integration test frameworks automated testing is widely used. We need to build on this knowledge and we need to make up for our lag on the data front.</p><p>People smarter than me at Monte Carlo have done a pretty good job of defining the difference between Data Observability and Testing. You can read more about this <a href="https://www.montecarlodata.com/blog-what-is-data-observability/#Data-observability-vs.-testing">here</a>.</p><p>From a reliability perspective, my checklist for a robust Data Warehouse:</p><ul><li>Testing</li><li>Robust deployment/release process</li><li>Alerting / Monitoring</li></ul><h3><strong>Testing + and much more testing</strong></h3><p>The importance of data tests is unquestionable in data projects. As Analytics Engineers we must ensure that writing the tests is <strong>not</strong> stuck in the backlog purgatory.</p><p>Without schema/ integrity tests, eventually, you will run into data failures, which will lead to a loss of confidence in the Analytics Platform.</p><p>Fortunately, dbt out-of-the-box supports the ability to test your data from the beginning of development — to the daily scheduled jobs.</p><p>The testing starter pack consists of:</p><ul><li>Uniqueness: To ensure there are no duplicates in a column</li><li>Not null: To check that there are no NULL values present in a column</li><li>Relationship: To check the referential integrity between related fields in two model<br>Accepted values: To test that a column only contains a set of values e.g: “credit card”, “debit card”</li><li>Freshness test on staging tables: To check whether new records are inserted to the table</li></ul><figure><img alt="Exampletes" src="https://cdn-images-1.medium.com/max/1024/1*PeaqqMlhGDKk37lH0yqE7w.png" /></figure><p><strong>Custom test:</strong></p><p>In my opinion, Singular tests is one of the best ways to ensure that things don’t break in the development process. Basically you have to recalculate a KPI that you are sure is not going to change e.g last year’s sales amount. The test will compare a manually calculated hard-coded fix value with the current state and throw an error if something changed.</p><p>Example singular test:</p><pre>with total_revenue_test as (</pre><pre>   select sum(payment_amt) as payment_total_amt</pre><pre>   from {{ref(&#39;fct_payments&#39;)}}</pre><pre>   where payment_dt between &#39;2020-01-01&#39; and &#39;2020-12-31&#39;</pre><pre>),</pre><pre>compare_result as (<br>  select <br>      *<br>   from total_revenue_test<br>    where payment_total_amt &lt;&gt; 872342312 -- your hardcoded KPI<br>)</pre><pre>select * from compare_result</pre><p>In addition, we have to raise attention to potential schema drifting but I will write about it in the following post.</p><p>You can read more about the built-in tests <a href="https://docs.getdbt.com/docs/building-a-dbt-project/tests">here</a>, if you can’t find what you’re looking for you can still write a <a href="https://docs.getdbt.com/docs/guides/writing-custom-generic-tests">custom generic test</a>, but before you do that it’s worth looking around in the famous <a href="https://github.com/calogica/dbt-expectations">dbt-expectations</a> package.</p><p>If you are interested in the Unit testing options in dbt, one of my colleagues wrote a detailed how-to guide on this topic. You can find Sonny’s writing <a href="https://blog.hiflylabs.hu/en/2022/02/10/environment-dependent-unit-testing-in-dbt/">here</a>.</p><p>Stay tuned for the next episode, where I will write about the Deployment/CI aspect of a robust Data platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c31e9297cb0d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hiflylabs/bi-as-a-business-critical-application-c31e9297cb0d">BI as a Business-Critical Application</a> was originally published in <a href="https://medium.com/hiflylabs">Hiflylabs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Provision Snowflake infrastructure with Terraform]]></title>
            <link>https://medium.com/hiflylabs/provision-snowflake-infrastructure-with-terraform-56227a32e703?source=rss-12ddaf2f0a31------2</link>
            <guid isPermaLink="false">https://medium.com/p/56227a32e703</guid>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[modern-data-stack]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Zsombor Földesi]]></dc:creator>
            <pubDate>Wed, 05 Jan 2022 12:59:02 GMT</pubDate>
            <atom:updated>2022-01-06T07:30:05.218Z</atom:updated>
            <content:encoded><![CDATA[<p><em>The original article can be found on </em><a href="https://blog.hiflylabs.hu/en/2022/01/05/snowflake/"><em>Hiflylabs’ blog</em></a></p><p>In this post, I want to show you how we have automated the provisioning of Snowflake components with Terraform in our dbt projects.</p><p>Terraform is an open-source, <strong>I</strong>nfrastructure <strong>a</strong>s a <strong>C</strong>ode (IaC) tool that is used to manage the cloud services with a declarative, version controlled configuration format. It is cloud-agnostic so it works on AWS, GCP, Azure and many other cloud providers. Its benefits include that you can write maintainable, reusable, modular pieces of code. So it fits really well with the mindset that makes so many of us love using dbt.</p><p>In the upcoming paragraphs I will focus on the <a href="https://registry.terraform.io/providers/chanzuckerberg/snowflake/latest">Snowflake provider</a>.</p><p>First you need to install the Terraform CLI. To do this, follow the instructions here: <a href="https://learn.hashicorp.com/tutorials/terraform/install-cli">install-cli</a></p><p>Note that this varies from OS to OS, on MacOS, for example, I had to run these commands:</p><pre>$ brew tap hashicorp/tap<br>$ brew install hashicorp/tap/terraform</pre><p>After a successful installation, we need to initialize the Terraform project.<br>To do this we need a new directory, then create the main.tf file with the following content:</p><pre>terraform {<br>  required_providers {<br>    snowflake = {<br>      source  = &quot;chanzuckerberg/snowflake&quot;<br>      version = &quot;0.25.28&quot;<br>    }<br>  }<br>}</pre><p>From there run the following command:</p><pre>$ terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JRlYkuzOHbl8UNnXVIBUiQ.gif" /></figure><p>The project will consist of the following files:</p><ul><li>main.tf : call modules, locals and data-sources to create all resources</li><li>variable.tf : contains declarations of variables used in main.tf</li><li>secret.tfvars : sensitive variables, such as passwords</li></ul><p>Without the use of Terraform on projects, Snowflake dependencies need to be created manually. For example, in a new project, one thing that you definitely need in a Snowflake tenant is at least one warehouse:</p><p>It looks like this in pure SQL:</p><pre>CREATE WAREHOUSE TRANSFORMING WITH <br> WAREHOUSE_SIZE = ‘XSMALL’ <br> WAREHOUSE_TYPE = ‘STANDARD’ <br> AUTO_SUSPEND = 600 <br> AUTO_RESUME = TRUE;</pre><p>There is nothing fundamentally wrong with this approach, but there is no clear way to manage this kind of code in your dbt project. You can save it to a new repo or to one of the corners of your project, but there is no trivial solution to manage these external dependencies, and to make it parametrizable, reusable. Managing these external resources can cause technical debt.</p><p>The first step is to set up the required providers. This is necessary because the technical user on whose behalf we run the commands needs different roles for different operations.(This user must be at least SYS, SECURITY admin within Snowflake.)</p><p>Add the following to the contents of main.tf:</p><pre>provider &quot;snowflake&quot; {<br>username = &lt;snowflake-username&gt;<br>password = &lt;snowflake-password&gt;<br>account  = &lt;snowflake-account-name&gt;<br>region   = &lt;snowflake-region-name&gt;<br>alias    = &quot;sys_admin&quot;<br>role     = &quot;SYSADMIN&quot;<br>}</pre><p>(of course, sensitive information will not be stored in main.tf later)</p><p>To create a Snowflake warehouse in Terraform is as simple as this:</p><pre>resource snowflake_warehouse w {<br>  name           = &quot;test&quot;<br>  comment        = &quot;foo&quot;<br>  warehouse_size = &quot;small&quot;<br>}</pre><p>It’s looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NuzPtvzokE5VgdSsbW9NLg.gif" /></figure><p>We successfully provisioned a Snowflake warehouse from Terraform.</p><p>Now we are going to make the process more sophisticated. We will derive each value into a variable, for example, if you need more than one warehouse (which you probably do).</p><p>With the following DRY approach, it’s easy to automate the creation of warehouses in a configurable and reusable way. <br>You can simply add something this to your variable.tf:</p><pre>variable &quot;warehouses&quot; {<br>  type = map(object({<br>    name = string,<br>    size = string<br>  }))<br>  default = {<br>    &quot;test01&quot; = {<br>      name = &quot;TEST_WAREHOUSE&quot;,<br>      size = &quot;xsmall&quot;<br>    }<br>    &quot;test02&quot; = {<br>      name = &quot;TEST_WAREHOUSE_2&quot;,<br>      size = &quot;xsmall&quot;<br>    }<br>}</pre><p>main.tf</p><pre>resource &quot;snowflake_warehouse&quot; &quot;warehouses&quot; {<br>  for_each            = var.warehouses<br>  provider            = snowflake.sys_admin<br>  name                = upper(each.value.name)<br>  warehouse_size      = each.value.size<br>  auto_suspend        = 60<br>  initially_suspended = true<br>}</pre><p>So, as described above, with Terraform we can dynamically generate the necessary resources. I think this is a good way to demonstrate the power of Terraform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l1pazYOdd79FsMZ97lfzCg.gif" /></figure><p>Here is high level view of our final bootstrapping project: <br>This will create the following objects:</p><ul><li>create warehouses</li><li>create databases</li><li>create roles</li><li>create dbt user</li><li>create schemas</li><li>grant roles</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*vKorH7GLvGc4b7WhLSfw7g.png" /></figure><p>You can find the source code here: <a href="https://github.com/Hiflylabs/snowflake-terraform-boostrap">link</a></p><p>In this post, I tried to show you how to provision Snowflake infrastructure with Terraform. <br>Development of the dbt Cloud Terraform provider started 3 months ago (Oct 3, 2021), which will allow us to put dbt Cloud resources under version control in the future as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56227a32e703" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hiflylabs/provision-snowflake-infrastructure-with-terraform-56227a32e703">Provision Snowflake infrastructure with Terraform</a> was originally published in <a href="https://medium.com/hiflylabs">Hiflylabs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to run Spark 3 Glue jobs locally with docker?]]></title>
            <link>https://medium.com/hiflylabs/how-to-run-spark-3-glue-jobs-locally-with-docker-12cdbdf1b6bb?source=rss-12ddaf2f0a31------2</link>
            <guid isPermaLink="false">https://medium.com/p/12cdbdf1b6bb</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[zeppelin]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[pyspark]]></category>
            <dc:creator><![CDATA[Zsombor Földesi]]></dc:creator>
            <pubDate>Tue, 12 Oct 2021 16:13:53 GMT</pubDate>
            <atom:updated>2022-06-20T13:03:52.401Z</atom:updated>
            <content:encoded><![CDATA[<p><em>The original article can be found on </em><a href="https://blog.hiflylabs.hu/en/2021/10/12/spark3gluejobs/"><em>Hiflylabs’ blog</em></a></p><p>AWS Glue development requires that a developer endpoint should be running at all times. (In fact, technically it only has to run when the jobs are to be launched; however stopping the endpoint is not possible, and killing and re-creating it requires config changes which is a major hassle.)</p><p>For smaller teams, in small or hobby projects it makes a lot of sense to develop and run Glue jobs locally, independently of AWS. This is possible with dockerized Spark — but AWS provides only limited support.</p><p>Although Spark 3 came out early June 2020, unfortunately AWS currently (as of October 2021) only provides a docker image with Spark 2.4. Fortunately Spark 3.1 engine is available in the cloud via the AWS console.</p><p>It is beyond the scope of this post to contemplate on whether it’s worth switching from 2 to 3, I just want to show you how you can run Glue jobs locally with the Spark 3.1 engine.</p><p>Note that this solution is based on the <a href="https://github.com/alrouen/local-aws-glue-v3-zeppelin">alruen</a> attempt, but that didn’t quite work for our purpose. (However, I would like to give a thumbs up from here as well!)</p><p>Without further ado, you can try our pre-build image from<strong><em> </em></strong><a href="https://hub.docker.com/repository/docker/hiflylabs/local-aws-glue-v3-zeppelin"><strong><em>here</em></strong></a><strong><em> </em></strong>or<strong><em> </em></strong><a href="https://github.com/Hiflylabs/aws-glue-spark3-docker"><strong><em>here</em></strong></a> you will find everything you need to know for local build or customization.</p><p>Beyond docker, you need the AWS command line interface (<a href="https://aws.amazon.com/cli/">AWS cli</a>). After installing it you must authenticate with the aws-configure command.</p><p>You can then start the container with the following command:</p><pre>docker run -it --rm --name local-glue -p 8080:8080 -p 9001:9001 -v $PWD/logs:/logs -v $PWD/notebook:/notebook -e ZEPPELIN_LOG_DIR=’/logs’ -e ZEPPELIN_NOTEBOOK_DIR=’/notebook’ -v ~/.aws:/root/.aws:ro &lt;todo-hf-docker-image-name&gt;</pre><p>Note that the ~/.aws:/root/ path represents the default location of the aws configuration files (which were created by the aws-configure command).</p><p>Once the container has started, you can start coding in the Zeppelin notebook, which you can access at <a href="http://127.0.0.1:9001,">http://127.0.0.1:9001,</a> or you can attach the running container from VS code. Although it is not part of this tutorial, you can read more about this <a href="https://code.visualstudio.com/docs/remote/attach-container">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P256v5kNryDrZeeXHuBtCQ.png" /></figure><p>If all went well, you can now successfully develop AWS glue jobs locally on your own machine with Spark version 3; you don’t need either the AWS console nor a developer endpoint.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12cdbdf1b6bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hiflylabs/how-to-run-spark-3-glue-jobs-locally-with-docker-12cdbdf1b6bb">How to run Spark 3 Glue jobs locally with docker?</a> was originally published in <a href="https://medium.com/hiflylabs">Hiflylabs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>