<?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 Matt Feeser on Medium]]></title>
        <description><![CDATA[Stories by Matt Feeser on Medium]]></description>
        <link>https://medium.com/@matt.feeser?source=rss-d2e0775100bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Q9q_38wgqNUNyKSbYfBiTg.jpeg</url>
            <title>Stories by Matt Feeser on Medium</title>
            <link>https://medium.com/@matt.feeser?source=rss-d2e0775100bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 21:01:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matt.feeser/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[Snowflake: Detecting and Alerting on Suspended Snowflake Tasks using Flow Operators]]></title>
            <link>https://medium.com/in-the-weeds/snowflake-detecting-and-alerting-on-suspended-snowflake-tasks-using-flow-operators-17df7642b748?source=rss-d2e0775100bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/17df7642b748</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[snowflake-tasks]]></category>
            <category><![CDATA[snowflake]]></category>
            <dc:creator><![CDATA[Matt Feeser]]></dc:creator>
            <pubDate>Mon, 03 Nov 2025 20:08:56 GMT</pubDate>
            <atom:updated>2025-11-03T20:08:56.825Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8KRczYiAaBCG4LAm4H_RVA.png" /></figure><h3>Background</h3><p>The team at Greenhouse has a few data pipelines that use Snowflake <a href="https://docs.snowflake.com/en/user-guide/tasks-intro#serverless-tasks">Serverless Tasks</a> for data ingestion. Now there are a number of reasons we chose this, but one is that serverless tasks can be cheaper to run than traditional tasks, which use customer-managed compute. From the <a href="https://docs.snowflake.com/en/sql-reference/sql/show-tasks">documentation</a>:</p><blockquote>[Serverless] tasks run on Snowflake-managed compute. Snowflake automatically resizes the resources as required for each workload. Snowflake determines the ideal size of compute resources for a given run based on a dynamic analysis of statistics for the most recent runs of the same task</blockquote><p>A Snowflake task, whether serverless or not, can be trigger by a cron schedule or by another (upstream) task. One very important note about using tasks is that “Snowflake creates all tasks in the SUSPENDED state”. This means that even though a task has been created, it will not run until it is “started”. A task can be started via the Snowflake UI or via SQL by issuing an ALTER TASK my_task_name RESUME;</p><p>With this “quirk” of defining Snowflake tasks, you may <em>think</em> that your task is running when it’s not. If you’re not monitoring it, how would you know for sure? A suspended task will never fail or produce an error message because it’s not running. For this reason, it is critical to monitor your production Snowflake platform for tasks in a suspended state.</p><h3>Attempting to Detect Suspended Tasks</h3><p>The only way I was able to find the state of a task was to use the <a href="https://docs.snowflake.com/en/sql-reference/sql/show-tasks">SHOW TASKS</a> command. I was not able to find a view or procedure in the INFORMATION_SCHEMA that provided equivalent results. If you know of one, please let me know in the comments.</p><p>Prior to the release of <a href="https://docs.snowflake.com/en/sql-reference/operators-flow">Flow Operators</a>, the only way to leverage the results of a SHOW command in SQL was to issue the command followed by a query using RESULT_SCAN() .</p><pre>SHOW TASKS;<br><br>SELECT *<br>FROM TABLE(RESULT_SCAN(LAST_QUERY_ID));</pre><p>This always felt really clunky to me.</p><p><strong>Flow Operators to the rescue</strong>. Now you can chain other SQL commands after the SHOW command using the flow operator -&gt;&gt; .</p><pre>SHOW TASKS<br>-&gt;&gt; SELECT * FROM $1;</pre><p><em>See my note about Flow Operators in the Lessons Learned section at the end so you don’t make the same bad assumptions I made on how the </em><em>$1 reference works.</em></p><h4>Attempt 1</h4><p>My initial thought to report on suspended tasks was to build the view equivalent to the results of the SHOW TASKS command. This is the view that I think Snowflake is missing in INFORMATION_SCHEMA.</p><p>Womp womp, unfortunately the <a href="https://docs.snowflake.com/en/sql-reference/sql/create-view">CREATE VIEW</a> command does not recognize the SHOW command. It only supports a SELECT statement to define the view.</p><pre>CREATE VIEW my_suspended_tasks AS <br>SHOW TASKS<br>-&gt;&gt; SELECT * FROM $1;<br><br>Syntax error: unexpected &#39;SHOW&#39;. (line 2)</pre><h4>Attempt 2</h4><p>I also experimented with building a stored procedure that returned a RESULTSET in the hopes that I could use SELECT * FROM TABLE(sp_name()) to define the view, but no such luck there either.</p><pre>CREATE PROCEDURE my_suspended_tasks() <br>RETURNS TABLE (task_name VARCHAR, task_state VARCHAR)<br>LANGUAGE SQL<br>AS<br>$$<br>DECLARE<br>  my_flow_operator_sql VARCHAR;<br>  my_resultset RESULTSET;<br>BEGIN<br>  my_flow_operator_sql := &#39;<br>    SHOW TASKS<br>      -&gt;&gt; SELECT<br>            &quot;name&quot; AS task_name,<br>            &quot;state&quot; AS task_state<br>          FROM $1<br>          WHERE &quot;state&quot; = &#39;&#39;suspended&#39;&#39;<br>  &#39;;<br><br>  my_resultset := (EXECUTE IMMEDIATE my_flow_operator_sql);<br><br>  RETURN TABLE(my_resultset);<br>  <br>END;<br>$$</pre><p>It works perfectly when executing the SELECT on its own…</p><pre>SELECT *<br>FROM TABLE(my_suspended_tasks());<br>-- returns expected results</pre><p>but gives an error when used in the view creation.</p><pre>CREATE VIEW suspended_tasks AS <br>SELECT *<br>FROM TABLE(my_suspended_tasks());<br><br>Procedures in FROM clauses can only be used in SELECT, INSERT, UPDATE, DELETE, COPY, MERGE, and CREATE TABLE AS ... SELECT statement types.</pre><p>I’ll spare you the details of my other failed attempts and get to what I finally implemented. Needless to say, I spent much more time on this than I feel should be required. All I’m after is a list of suspended tasks. That should be easy, right? I guess not for me.</p><h3><strong>Solution</strong></h3><p>I finally landed on creating a SQL stored procedure that would look for suspended tasks in a schema. If suspended tasks are found, it aggregates them and uses the internal <a href="https://docs.snowflake.com/en/sql-reference/stored-procedures/system_send_snowflake_notification">SYSTEM$SEND_SNOWFLAKE_NOTIFICATION</a> procedure to send a message to an existing <a href="https://docs.snowflake.com/en/sql-reference/sql/create-notification-integration">Notification Integration</a> that sends to an Amazon SNS topic and ultimately, a message to our team’s alert Slack channel. Fortunately the notification integration was already in place, so I did not need to create anything new there. I just had to reference the existing notification integration.</p><p>With the procedure in place, I then created a task to execute that stored procedure on a cron schedule.</p><h4>Stored Procedure</h4><pre>CREATE OR REPLACE PROCEDURE alert_on_suspended_tasks(<br>  DATABASE_NAME VARCHAR,<br>  SCHEMA_NAME VARCHAR<br>)<br>  RETURNS VARCHAR<br>  LANGUAGE SQL<br>  COMMENT = &#39;Checks for suspended ingestion tasks and sends an alert if any are found&#39;<br>AS<br>$$<br>DECLARE<br>  sql_to_run VARCHAR;<br>  suspended_task_count INTEGER;<br>  suspended_task_list VARCHAR;<br>  alert_message OBJECT;<br>  alert_message_txt VARCHAR;<br>  alert_message_suspended_task_list VARCHAR;<br>  max_task_list_chars_in_message INTEGER DEFAULT 500;<br>  query_resultset RESULTSET;<br>  return_value VARCHAR DEFAULT &#39;No suspended tasks found.&#39;;<br><br>BEGIN<br>  sql_to_run := &#39;<br>    SHOW TASKS IN SCHEMA &#39; || :DATABASE_NAME || &#39;.&#39; || :SCHEMA_NAME || &#39;<br>    -&gt;&gt;<br>    SELECT <br>      &quot;database_name&quot; AS database_name,<br>      &quot;schema_name&quot; AS schema_name,<br>      COUNT(&quot;name&quot;) AS suspended_task_count,<br>      LISTAGG(&quot;name&quot;, &#39;&#39;,&#39;&#39;)<br>        WITHIN GROUP (ORDER BY &quot;name&quot; ASC) AS suspended_task_list<br>    FROM $1<br>    WHERE &quot;state&quot; = &#39;&#39;suspended&#39;&#39;<br>    GROUP BY ALL<br>  &#39;;<br><br>  query_resultset := (EXECUTE IMMEDIATE sql_to_run);<br><br>  FOR record IN query_resultset LOOP<br>    IF (LENGTH(record.suspended_task_list) &gt; max_task_list_chars_in_message) THEN<br>      alert_message_suspended_task_list := SUBSTR(record.suspended_task_list, 1, max_task_list_chars_in_message) || &#39;...&#39;;<br><br>    ELSE<br>      alert_message_suspended_task_list := record.suspended_task_list;<br><br>    END IF;<br><br>    alert_message := OBJECT_CONSTRUCT(<br>      &#39;alert_impact&#39;, &#39;High&#39;,<br>      &#39;alert_message&#39;, &#39;Detected ingestion tasks in suspended state. This MUST be investigated.&#39;,<br>      &#39;alert_source&#39;, CURRENT_DATABASE() || &#39;.&#39; || CURRENT_SCHEMA() || &#39;.ALERT_ON_SUSPENDED_INGESTION_TASKS()&#39;,<br>      &#39;database_name&#39;, record.database_name,<br>      &#39;schema_name&#39;, record.schema_name,<br>      &#39;suspended_task_count&#39;, record.suspended_task_count,<br>      &#39;suspended_task_list&#39;, alert_message_suspended_task_list<br>    );<br><br>    CALL SYSTEM$SEND_SNOWFLAKE_NOTIFICATION(<br>      SNOWFLAKE.NOTIFICATION.APPLICATION_JSON(:alert_message::VARCHAR),<br>      SNOWFLAKE.NOTIFICATION.INTEGRATION(&#39;ALERT_NOTIFICATION&#39;)<br>    );<br><br>    return_value := alert_message::VARCHAR;<br>  END LOOP;<br><br>  RETURN return_value;<br>END;<br>;<br>$$<br>;</pre><h4>Serverless Task</h4><pre>CREATE TASK task_alert_on_suspended_ingestion_tasks<br>  SCHEDULE = &#39;USING CRON 0 3,15 * * * UTC&#39;<br>  USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE = &#39;XSMALL&#39;<br>  COMMENT = &#39;Checks for suspended ingestion tasks and alerts if found&#39;<br>  ERROR_INTEGRATION = ALERT_NOTIFICATION<br>AS<br>  CALL ALERT_ON_SUSPENDED_INGESTION_TASKS();</pre><h3>Lessons Learned</h3><ul><li>Flow Operators use a relative reference when using the $n convention, not a global reference.</li></ul><pre>SHOW TASKS<br>-&gt;&gt; SELECT * FROM $1  --This selects from the SHOW TASK statement (e.g. 1 statement prior to the current)<br>-&gt;&gt; SELECT * FROM $2; --This STILL selects from the SHOW TASK statement (e.g. 2 statements prior to the current)<br><br><br>SHOW TASKS<br>-&gt;&gt; SELECT * FROM $1  --This selects from the SHOW TASK statement (e.g. 1 statement prior to the current)<br>-&gt;&gt; SELECT * FROM $1; --This selects from the previous statement (e.g. 1 statement prior to the current)</pre><ul><li>There’s got to be a more direct way to detect suspended tasks. If you have better ways, please let me know.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17df7642b748" width="1" height="1" alt=""><hr><p><a href="https://medium.com/in-the-weeds/snowflake-detecting-and-alerting-on-suspended-snowflake-tasks-using-flow-operators-17df7642b748">Snowflake: Detecting and Alerting on Suspended Snowflake Tasks using Flow Operators</a> was originally published in <a href="https://medium.com/in-the-weeds">In the weeds</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Snowflake SQL: An array-based approach to searching HTML pages for keywords]]></title>
            <link>https://medium.com/in-the-weeds/snowflake-sql-an-array-based-approach-to-searching-html-pages-for-keywords-17dedf972439?source=rss-d2e0775100bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/17dedf972439</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[search]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Matt Feeser]]></dc:creator>
            <pubDate>Tue, 10 Jun 2025 16:10:46 GMT</pubDate>
            <atom:updated>2025-07-18T16:16:36.855Z</atom:updated>
            <content:encoded><![CDATA[<h3>Snowflake SQL: Using ARRAY_OVERLAPS(), ARRAY_INTERSECTION(), and BeautifulSoup for keyword searching HTML in database</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4SARThI7Yj4_i1M41V32hg.jpeg" /><figcaption>Image generated by Google Gemini</figcaption></figure><p>Have you ever wondered why you might want to use the <a href="https://docs.snowflake.com/en/sql-reference/functions/arrays_overlap">ARRAYS_OVERLAPS()</a> or <a href="https://docs.snowflake.com/en/sql-reference/functions/array_intersection">ARRAY_INTERSECTION() </a>functions in Snowflake SQL?</p><p>I found a pretty interesting use for these functions recently and thought I’d share.</p><p>I was tasked with optimizing a user-written query which was searching an HTML formatted TEXT column for an arbitrary number of search terms. If any one of the search terms was found in the HTML, then the record should be returned, as well as exactly which search terms were found. The SQL I was provided used multiple <a href="https://docs.snowflake.com/en/sql-reference/functions/ilike">ILIKE</a> operators, one for each search term, separated by an OR condition.</p><pre>SELECT html_body<br>FROM job_post<br>WHERE (<br>  html_body ILIKE &#39;%engineer%&#39;<br>  OR html_body ILIKE &#39;%architect%&#39;<br>  OR html_body ILIKE &#39;%ITIL%&#39;<br>  OR html_body ILIKE &#39;%ruby%&#39;<br>  OR html_body ILIKE &#39;%typescript%&#39;<br>  OR html_body ILIKE &#39;%react%&#39;<br>  OR html_body ILIKE &#39;%manager%&#39;<br>);</pre><p>A keen SQL eye may notice that using an <a href="https://docs.snowflake.com/en/sql-reference/functions/ilike_any">ILIKE ANY</a> operator would reduce the amount of code required to express the same functionality.</p><pre>SELECT html_body<br>FROM job_post<br>WHERE html_body ILIKE ANY (<br>  &#39;%engineer%&#39;,<br>  &#39;%architect%&#39;,<br>  &#39;%ITIL%&#39;,<br>  &#39;%ruby%&#39;,<br>  &#39;%typescript%&#39;,<br>  &#39;%react%&#39;,<br>  &#39;%manager%&#39;<br>);</pre><p>However, that doesn’t solve the problem of which search string caused the record to be returned. You may be tempted to build case statements in the SELECT clause as follows:</p><pre>SELECT <br>  html_body,<br>  CASE WHEN html_body ILIKE &#39;%engineer%&#39; THEN TRUE ELSE NULL END AS contains_engineer,<br>  CASE WHEN html_body ILIKE &#39;%architect%&#39; THEN TRUE ELSE NULL END AS contains_architect,<br>  CASE WHEN html_body ILIKE &#39;%ITIL%&#39; THEN TRUE ELSE NULL END AS contains_itil,<br>  CASE WHEN html_body ILIKE &#39;%ruby%&#39; THEN TRUE ELSE NULL END AS contains_ruby,<br>  CASE WHEN html_body ILIKE &#39;%typescript%&#39; THEN TRUE ELSE NULL END AS contains_typescript,<br>  CASE WHEN html_body ILIKE &#39;%react%&#39; THEN TRUE ELSE NULL END AS contains_react,<br>  CASE WHEN html_body ILIKE &#39;%manager%&#39; THEN TRUE ELSE NULL END AS contains_manager<br>FROM job_post<br>WHERE<br>  COALESCE(<br>    contains_engineer,<br>    contains_architect,<br>    contains_itil,<br>    contains_ruby,<br>    contains_typescript,<br>    contains_react,<br>    contains_manager,<br>    FALSE<br>  ) = TRUE;</pre><p>Though this may work, it does not scale as the number of search terms grows. This approach could also return false positives where the search term is found in the HTML tags or code and not in the actual text of page.</p><p>The ARRAY_OVERLAPS() and ARRAY_INTERSECTION() functions can help address the scaling of search terms. Let’s start by creating an array of all of our search terms. This can either be done explicitly using the <a href="https://docs.snowflake.com/en/sql-reference/functions/array_construct">ARRAY_CONSTRUCT()</a> function, or by storing groups of search terms in a table, one row per term, and constructing the ARRAY at query runtime using something like <a href="https://docs.snowflake.com/en/sql-reference/functions/array_agg">ARRAY_AGG()</a>. I prefer the later as it promotes reusability.</p><pre>CREATE OR REPLACE TEMPORARY TABLE search_term_groupings (<br>  search_term        TEXT,<br>  grouping_id        NUMBER<br>);<br><br>INSERT INTO search_term_groupings<br>VALUES (&#39;engineer&#39;, 1);<br><br>INSERT INTO search_term_groupings<br>VALUES (&#39;architect&#39;, 1);<br><br>INSERT INTO search_term_groupings<br>VALUES (&#39;ITIL&#39;, 1);<br><br>INSERT INTO search_term_groupings<br>VALUES (&#39;ruby&#39;, 1);<br><br>INSERT INTO search_term_groupings<br>VALUES (&#39;typescript&#39;, 1);<br><br>INSERT INTO search_term_groupings<br>VALUES (&#39;react&#39;, 1);<br><br>INSERT INTO search_term_groupings<br>VALUES (&#39;manager&#39;, 1);<br><br>INSERT INTO search_term_groupings<br>VALUES (&#39;snowflake&#39;, 2);<br><br>INSERT INTO search_term_groupings<br>VALUES (&#39;dbt&#39;, 2);<br><br>INSERT INTO search_term_groupings<br>VALUES (&#39;fivetran&#39;, 2);<br><br>-- build the array in SQL<br>SELECT<br>  grouping_id,<br>  ARRAY_AGG(<br>    DISTINCT UPPER(search_term)<br>  ) WITHIN GROUP (ORDER BY UPPER(search_term)) AS search_term_array<br>FROM search_term_groupings<br>GROUP BY<br>  grouping_id<br>ORDER BY<br>  grouping_id;</pre><p>I always like to ensure that the arrays I construct at runtime contain unique values and are sorted alphabetically for easier troubleshooting, hence the DISTINCT and the WITHIN GROUP (ORDER BY ..)). Having unique values in the array will also eliminate unnecessary matching attempts later in this process.</p><p>Now we have a search term array, but how can we use this array to search the HTML? We can’t use the ILIKE operator as we did before to compare the array to the HTML. However, we could turn the HTML into an array too, with one element for each word. Then we could then see if the two arrays (the html_array and the search_term_array) had any elements in common. An element in common would mean that the search term was matched.</p><p>So we have an approach, but how should we handle all of the extra characters in the HTML that do not represent text that is rendered on the page? For example, &lt;div class=&quot;page&quot; title = &quot;Page 2&quot;&gt;? This doesn’t need to be searched and could also present false positive matches.</p><p>To overcome this we can create a Python UDF by calling the get_text method from the python package <a href="https://beautiful-soup-4.readthedocs.io/en/latest/index.html">BeautifulSoup</a>. This method returns only the text from an HTML document, all of the tags get removed. The result is the text formatted as a single string using a separator.</p><pre>CREATE OR REPLACE FUNCTION STRIP_HTML(html STRING, parsing_separator STRING)<br>  RETURNS STRING<br>  LANGUAGE PYTHON<br>  RUNTIME_VERSION = 3.10<br>  HANDLER = &#39;get_text&#39;<br>  PACKAGES = (&#39;beautifulsoup4&#39;)<br>AS<br>$$<br>from bs4 import BeautifulSoup<br><br>def get_text(html, parsing_separator):<br>  soup = BeautifulSoup(html, &#39;html.parser&#39;)<br>  return soup.get_text(separator=parsing_separator)<br>$$;</pre><p>Now let’s see how we can call this function in the SQL.</p><pre>SELECT<br>  id,<br>  html_body,<br>  STRTOK_TO_ARRAY(<br>    STRIP_HTML(UPPER(html_body),&#39; &#39;),<br>    &#39; &#39;<br>  ) AS html_body_array<br>FROM job_post;</pre><p>If you haven’t played with the <a href="https://docs.snowflake.com/en/sql-reference/functions/strtok_to_array">STRTOK_TO_ARRAY()</a> function yet, all it does is take a string and split it into an array based on a delimiter. In the case above, I’m using the space character &#39; &#39;. So a b c as a string becomes the array [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]. You can even use multiple delimiters if there are special characters you’re seeing the html_body that need to be handled.</p><p>Now, let’s combine all of these together and use the overlap and intersection array functions to get the desired result.</p><h3>Array based approach</h3><pre>WITH job_post_parsed AS (<br>  SELECT<br>    id,<br>    html_body,<br>    ARRAY_DISTINCT(<br>      STRTOK_TO_ARRAY(<br>        STRIP_HTML(UPPER(html_body),&#39; &#39;),<br>        &#39; .,:()?!/&#39;<br>      )<br>    ) AS html_body_array<br>  FROM job_post<br>),<br><br>search_terms AS (<br>  SELECT<br>    grouping_id,<br>    ARRAY_AGG(<br>      DISTINCT UPPER(search_term)<br>    ) WITHIN GROUP (ORDER BY UPPER(search_term)) AS search_term_array<br>  FROM search_term_groupings<br>  GROUP BY<br>    grouping_id<br>)<br><br>SELECT<br>  job_post_parsed.id,<br>  job_post_parsed.html_body,<br>  search_terms.grouping_id,<br>  search_terms.search_term_array,<br>  ARRAY_INTERSECTION(<br>    job_post_parsed.html_body_array,<br>    search_terms.search_term_array<br>  ) AS search_terms_found<br>FROM job_post_parsed<br>  CROSS JOIN search_terms<br>WHERE<br>  ARRAYS_OVERLAP(<br>    job_post_parsed.html_body_array,<br>    search_terms.search_term_array<br>  );</pre><p>In the above SQL, the job_post_parsed common table expression (CTE) is simply building an array containing all of the distinct words in the text of the html body. The search_terms CTE constructs an array containing the unique search terms.</p><p>The ARRAYS_OVERLAP() function is used to check if any of the elements in the two arrays html_body_array and search_term_array are shared. If any common elements are found, then true is returned, otherwise false. In this way, we can filter the result set to only return records where at least one search term is matched.</p><p>The ARRAY_INTERSECTION() on the other hand returns an array of those elements that the two arrays share. This could be combined with the <a href="https://docs.snowflake.com/en/sql-reference/functions/array_size">ARRAY_SIZE()</a> function to count how many search terms are much. Furthermore, you may only want to return records where there are over a certain number of matches.</p><pre>...<br><br>SELECT<br>  job_post_parsed.id,<br>  job_post_parsed.html_body,<br>  search_terms.grouping_id,<br>  search_terms.search_term_array,<br>  ARRAY_INTERSECTION(<br>    job_post_parsed.html_body_array,<br>    search_terms.search_term_array<br>  ) AS search_terms_found,<br>  ARRAY_SIZE(search_terms_found) AS search_terms_found_count<br><br>...<br><br>WHERE<br>  ARRAYS_OVERLAP(<br>    job_post_parsed.html_body_array,<br>    search_terms.search_term_array<br>  )<br>  AND search_terms_found_count &gt; 3<br>;</pre><h3>Conclusion</h3><p>This, as with any solutions, has it’s own tradeoffs. In my case, the performance results using the array based approach were astounding. The original query was timing out after 3 hours on a Medium sized warehouse vs. the modified query completed in ~4 minutes on the same warehouse. I attribute this to the large data volume (source html_body records in the millions) and the number of unique groupings of search terms. With the original approach, the ILIKE operator performed full string comparisons on large bodies of text (including HTML tags), once for each search term. It was not reasonable to expect this approach to be performant on large dataset.</p><p>However, if you have a relatively small number of records and only a few search terms, multiple ILIKE statements will likely yield faster results.</p><p>In addition, this method does NOT consider multiword phrases, or partial words matching. Instead, this approach requires single word search terms and entire string matching. For example, a search term of engineer will not match engineering manager in the source html body. To overcome this, you could add both terms engineering and manager to the list of search terms and review the set of matched terms.</p><p>There’s also overhead to consider when calling BeautifulSoup via the UDF. The way that it’s usage is currently implemented, there is one python function call per row. If optimizing this overhead is something you’re interested in exploring, look into <a href="https://docs.snowflake.com/en/developer-guide/udf/python/udf-python-batch">Vectorized Python UDFs</a> which could be used to batch the python calls.</p><p>I hope you learned a little about the ARRAYS_OVERLAP() and the ARRAY_INTERSECTION() functions in Snowflake and at least one way that you can apply them. What other ways have you used these functions?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17dedf972439" width="1" height="1" alt=""><hr><p><a href="https://medium.com/in-the-weeds/snowflake-sql-an-array-based-approach-to-searching-html-pages-for-keywords-17dedf972439">Snowflake SQL: An array-based approach to searching HTML pages for keywords</a> was originally published in <a href="https://medium.com/in-the-weeds">In the weeds</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recursive CTEs in Snowflake with ARRAY_APPEND()]]></title>
            <link>https://medium.com/in-the-weeds/recursive-ctes-in-snowflake-with-array-append-940eb5826e24?source=rss-d2e0775100bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/940eb5826e24</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[recursion]]></category>
            <category><![CDATA[array-functions]]></category>
            <category><![CDATA[snowflake]]></category>
            <dc:creator><![CDATA[Matt Feeser]]></dc:creator>
            <pubDate>Mon, 05 May 2025 14:42:20 GMT</pubDate>
            <atom:updated>2025-05-05T14:42:20.855Z</atom:updated>
            <content:encoded><![CDATA[<p>I have seen a number of different methods for generating the “path” value in a Recursive CTE (common table expression). Most rely on some form of string-based concatenation which is later parsed to split a hierarchy into multiple, level specific columns. Yesterday I ran into an issue where the delimiter that I was using was embedded in the source data. Sure, I could analyze the source data and choose delimiter characters that are not present, but what if I could eliminate the need for delimiter characters altogether. Enter the <a href="https://docs.snowflake.com/en/sql-reference/functions/array_append">ARRAY_APPEND()</a> function in Snowflake. I’ve seen many articles about recursive CTEs, but I have yet to see one that leverages this function, so I thought I’d share what I found.</p><p>If you’re not familiar with Recursive CTEs or querying hierarchical data, the Snowflake documentation explains them <a href="https://docs.snowflake.com/en/user-guide/queries-cte#recursive-ctes-and-hierarchical-data">here</a> and <a href="https://docs.snowflake.com/en/user-guide/queries-hierarchical">here</a>.</p><h3>The shortcomings of string-based concatenation in Recursive CTEs</h3><p>Many examples of recursive CTEs traversing a hierarchy build a path through string concatenation and a delimiter.</p><p>Example:</p><pre>CREATE OR REPLACE TEMPORARY TABLE departments (<br>  department_id         NUMBER,<br>  department_name       TEXT,<br>  parent_department_id  NUMBER<br>);<br><br>INSERT INTO departments<br>VALUES <br>  (1, &#39;Organization&#39;, NULL),<br>  (2, &#39;Human Resources&#39;, 1),<br>  (3, &#39;Sales&#39;, 1),<br>  (4, &#39;Information Technology&#39;,1),<br>  (5, &#39;Finance/Accounting&#39;, 1),<br>  (6, &#39;Research &amp; Development&#39;, 1),<br>  (7, &#39;Payroll&#39;, 2),<br>  (8, &#39;Benefits&#39;, 2),<br>  (9, &#39;Recruiting&#39;, 2),<br>  (10, &#39;North America&#39;, 3),<br>  (11, &#39;EMEA&#39;, 3),<br>  (12, &#39;LATAM&#39;, 3),<br>  (13, &#39;APAC&#39;, 3),<br>  (14, &#39;Help Desk/Support&#39;, 4),<br>  (15, &#39;System Administration&#39;, 4),<br>  (16, &#39;Financial Planning&#39;, 5),<br>  (17, &#39;Accounting&#39;, 5),<br>  (18, &#39;Analytics&#39;, 5),<br>  (19, &#39;Engineering&#39;, 6),<br>  (20, &#39;Platform&#39;, 6),<br>  (21, &#39;Project Management&#39;, 6),<br>  (22, &#39;United States&#39;, 10),<br>  (23, &#39;Canada&#39;, 10),<br>  (24, &#39;Mexico&#39;, 10);</pre><pre>WITH RECURSIVE department_hierarchy (<br>    department_id,<br>    department_name,<br>    parent_department_id,<br>    department_id_path,<br>    department_name_path,<br>    depth<br>  )<br>  AS (<br>    SELECT<br>      department_id,<br>      department_name,<br>      parent_department_id,<br>      &#39;/&#39; || department_id::TEXT AS department_id_path,<br>      &#39;/&#39; || department_name::TEXT AS department_name_path,<br>      1::NUMBER AS depth<br>    FROM departments<br>    WHERE parent_department_id IS NULL<br>    UNION ALL<br>    SELECT<br>      d.department_id,<br>      d.department_name,<br>      d.parent_department_id,<br>      dh.department_id_path || &#39;/&#39; || d.department_id::TEXT AS department_id_path,<br>      dh.department_name_path || &#39;/&#39; || d.department_name::TEXT AS department_name_path,<br>      dh.depth + 1 AS depth<br>    FROM departments d<br>    JOIN department_hierarchy dh ON d.parent_department_id = dh.department_id<br>  )<br>SELECT<br>  department_id,<br>  department_name,<br>  parent_department_id,<br>  department_id_path,<br>  department_name_path,<br>  depth  <br>FROM department_hierarchy;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6eWe2o-iZI16IaIapRDeg.png" /><figcaption>Query Results</figcaption></figure><p>In the above example, I used the / delimiter to build the path. If you look closely at the original data, this delimiter is present in the name values of two of the records: Finance/Accounting and Help Desk/Support. This will cause an issue when we try to parse the different name levels into separate columns.</p><pre>WITH RECURSIVE department_hierarchy (<br>    department_id,<br>    department_name,<br>    parent_department_id,<br>    department_id_path,<br>    department_name_path,<br>    depth<br>)<br>  AS (<br>    SELECT<br>      department_id,<br>      department_name,<br>      parent_department_id,<br>      &#39;/&#39; || department_id::TEXT AS department_id_path,<br>      &#39;/&#39; || department_name::TEXT AS department_name_path,<br>      1::NUMBER AS depth<br>    FROM departments<br>    WHERE parent_department_id IS NULL<br>    UNION ALL<br>    SELECT<br>      d.department_id,<br>      d.department_name,<br>      d.parent_department_id,<br>      dh.department_id_path || &#39;/&#39; || d.department_id::TEXT AS department_id_path,<br>      dh.department_name_path || &#39;/&#39; || d.department_name::TEXT AS department_name_path,<br>      dh.depth + 1 AS depth<br>    FROM departments d<br>    JOIN department_hierarchy dh ON d.parent_department_id = dh.department_id<br>  ),<br>parsed_path AS (<br>  SELECT<br>    department_id,<br>    department_name,<br>    parent_department_id,<br>    department_id_path,<br>    department_name_path,<br>    depth,<br>    REGEXP_SUBSTR(department_id_path, &#39;[^/]+&#39;, 1, 1) AS department_level_1_id,<br>    REGEXP_SUBSTR(department_id_path, &#39;[^/]+&#39;, 1, 2) AS department_level_2_id,<br>    REGEXP_SUBSTR(department_id_path, &#39;[^/]+&#39;, 1, 3) AS department_level_3_id,<br>    REGEXP_SUBSTR(department_id_path, &#39;[^/]+&#39;, 1, 4) AS department_level_4_id,<br>    REGEXP_SUBSTR(department_name_path, &#39;[^/]+&#39;, 1, 1) AS department_level_1_name,<br>    REGEXP_SUBSTR(department_name_path, &#39;[^/]+&#39;, 1, 2) AS department_level_2_name,<br>    REGEXP_SUBSTR(department_name_path, &#39;[^/]+&#39;, 1, 3) AS department_level_3_name,<br>    REGEXP_SUBSTR(department_name_path, &#39;[^/]+&#39;, 1, 4) AS department_level_4_name<br>  FROM department_hierarchy<br>)<br>SELECT<br>  department_id,<br>  department_name,<br>  depth,<br>  department_id_path,<br>  department_name_path,<br>  department_level_1_name,<br>  department_level_2_name,<br>  department_level_3_name,<br>  department_level_4_name<br>FROM parsed_path<br>WHERE department_name_path ILIKE &#39;%finance/accounting%&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sx_KHViHKdi0icAglpSjZA.png" /><figcaption>Query Results: Parsing levels using string concatenation approach</figcaption></figure><p>The parsing above uses the <a href="https://docs.snowflake.com/en/sql-reference/functions/regexp_substr">REGEXP_SUBSTR()</a>function to split the department_name_path generated by the recursive CTE into their respective level columns. Since the source data contains the / delimiter that I’m using, the split columns are not working as expected. See the Query Results screenshot above. We would expect the DEPARTMENT_LEVEL_2_NAME to contain the value Finance/Accounting, instead this single name is being split into the DEPARTMENT_LEVEL_2_NAME and DEPARTMENT_LEVEL_3_NAME columns.</p><p>Now to solve this problem we <em>could</em> choose a different delimiter for the concatenation, but what should we choose? I’ve seen some examples that use -&gt; or others that enclose the source values in double quotes &quot; before concatenation. However, any string concatenation based approach relies on the those delimiters not appearing in the source values. Can you always predict what values may exist in the source data, especially when dealing with user entered data?</p><h4>Using the ARRAY_APPEND() function instead</h4><p>An alternative to concatenating strings together in the recursive CTEs is to use the <a href="https://docs.snowflake.com/en/sql-reference/functions/array_append">ARRAY_APPEND(</a>) function. I found this in the Snowflake documentation; however it appears this is available in other platforms as well, including Postgres and Databricks.</p><p>In the context of a recursive CTE, this function allows you to construct an array consisting of the path with each element of the array representing an level within the hierarchy. In this implementation, the position of the element in the array identifies the level of the hierarchy. This method of building the path is not susceptible to embedded delimiter characters in the source data.</p><pre>WITH RECURSIVE department_hierarchy (<br>    department_id,<br>    department_name,<br>    parent_department_id,<br>    department_id_path_array,<br>    department_name_path_array,<br>    depth<br>)<br>  AS (<br>    SELECT<br>      department_id,<br>      department_name,<br>      parent_department_id,<br>      COALESCE(department_id::TEXT, &#39;&#39;)::ARRAY AS department_id_path_array,<br>      COALESCE(department_name, &#39;&#39;)::ARRAY AS department_name_path_array,<br>      1::NUMBER AS depth<br>    FROM departments<br>    WHERE parent_department_id IS NULL<br>    UNION ALL<br>    SELECT<br>      d.department_id,<br>      d.department_name,<br>      d.parent_department_id,<br>      ARRAY_APPEND(dh.department_id_path_array, COALESCE(d.department_id::TEXT,&#39;&#39;)) AS department_id_path_array,<br>      ARRAY_APPEND(dh.department_name_path_array, COALESCE(d.department_name::TEXT,&#39;&#39;)) AS department_name_path_array,<br>      dh.depth + 1 AS depth<br>    FROM departments d<br>    JOIN department_hierarchy dh ON d.parent_department_id = dh.department_id<br>  ),<br>parsed_path AS (<br>  SELECT<br>    department_id,<br>    department_name,<br>    parent_department_id,<br>    department_id_path_array,<br>    department_name_path_array,<br>    depth,<br>    NULLIF(department_id_path_array[0], &#39;&#39;)::NUMBER AS department_level_1_id,<br>    NULLIF(department_id_path_array[1], &#39;&#39;)::NUMBER AS department_level_2_id,<br>    NULLIF(department_id_path_array[2], &#39;&#39;)::NUMBER AS department_level_3_id,<br>    NULLIF(department_id_path_array[3], &#39;&#39;)::NUMBER AS department_level_4_id,<br>    NULLIF(department_name_path_array[0], &#39;&#39;)::TEXT AS department_level_1_name,<br>    NULLIF(department_name_path_array[1], &#39;&#39;)::TEXT AS department_level_2_name,<br>    NULLIF(department_name_path_array[2], &#39;&#39;)::TEXT AS department_level_3_name,<br>    NULLIF(department_name_path_array[3], &#39;&#39;)::TEXT AS department_level_4_name<br>  FROM department_hierarchy<br>)<br>SELECT<br>  department_id,<br>  department_name,<br>  depth,<br>  department_id_path_array,<br>  department_name_path_array,<br>  department_level_1_name,<br>  department_level_2_name,<br>  department_level_3_name,<br>  department_level_4_name<br>FROM parsed_path<br>WHERE ARRAY_CONTAINS(<br>  &#39;Finance/Accounting&#39;::VARIANT,<br>  department_name_path_array::VARIANT<br>);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ApymKJdKN01Z7X5FSwJXSA.png" /><figcaption>Query Results: Parsing levels using ARRAY_APPEND() approach</figcaption></figure><p>With this approach, each iteration of the recursion is appended to the previous iteration of the recursion.</p><p>A couple of notes on this approach:</p><ul><li>This handles null values in the hierarchy using the COALESCE() function when appending values into the array. This is important as it preserves the structure of the hierarchy.</li><li>When parsing the array to get the individual levels, it handles empty string elements of the array using the NULLIF() function.</li></ul><h3>Conclusion</h3><p>If you’re querying a hierarchy using a recursive CTE, using the ARRAY_APPEND() function adds resilience to your query with minimal additional implementation effort. I highly recommend this over a string-based concatenation method. I’ll be using this array-based approach from here on out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=940eb5826e24" width="1" height="1" alt=""><hr><p><a href="https://medium.com/in-the-weeds/recursive-ctes-in-snowflake-with-array-append-940eb5826e24">Recursive CTEs in Snowflake with ARRAY_APPEND()</a> was originally published in <a href="https://medium.com/in-the-weeds">In the weeds</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using MATCH_RECOGNIZE in Snowflake]]></title>
            <link>https://medium.com/in-the-weeds/using-match-recognize-in-snowflake-bdfba80e546e?source=rss-d2e0775100bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdfba80e546e</guid>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[data-warehouse]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Matt Feeser]]></dc:creator>
            <pubDate>Wed, 08 May 2024 21:19:06 GMT</pubDate>
            <atom:updated>2024-05-09T15:42:09.107Z</atom:updated>
            <content:encoded><![CDATA[<p>A clever way to collapse daily snapshot data into relative start/end date ranges.</p><p>I’ve been using SQL for over 15 years on various platforms (Oracle, SQL Server, Teradata, Postgres, and Snowflake) and today I came across MATCH_RECOGNIZE. I was blown away by what this thing can do.</p><p>This optional subclause to the FROM clause is supported by many database platforms. I’m using Snowflake these days, so here’s a link to their documentation for <a href="https://docs.snowflake.com/en/sql-reference/constructs/match_recognize">MATCH_RECOGNIZE</a>.</p><p>MATCH_RECOGNIZE is much more powerful than what is shown here, but I was so excited by what I was able to accomplish in a relatively small amount of SQL that I had to share.</p><p>Ok, so here’s what I was working on…</p><h4>The backstory</h4><p>My team wanted to start detecting schema changes in our upstream app databases. I know that there are other solutions for schema change detection, but I wanted to see what I could build on my own, cheaply.</p><p>So I built a simple python script that pulls data from the information_schema.tablesand information_schema.columns views in each app database and uploads the results to s3. In addition, to just pulling the raw data, I also added an MD5 hash column based on all columns in the view, and built a primary key column (a period-separated concatenation of the table_catalog, table_schema, table_name and column_name columns) for each row.</p><pre>-- generated MD5 record hash for information_schema.tables<br>  MD5(<br>    COALESCE(table_catalog::text,&#39;$null$&#39;)<br>    || COALESCE(table_schema::text,&#39;$null$&#39;)<br>    || COALESCE(table_name::text,&#39;$null$&#39;)<br>    || COALESCE(table_type::text,&#39;$null$&#39;)<br>    || COALESCE(self_referencing_column_name::text,&#39;$null$&#39;)<br>    || COALESCE(reference_generation::text,&#39;$null$&#39;)<br>    || COALESCE(user_defined_type_catalog::text,&#39;$null$&#39;)<br>    || COALESCE(user_defined_type_schema::text,&#39;$null$&#39;)<br>    || COALESCE(user_defined_type_name::text,&#39;$null$&#39;)<br>    || COALESCE(is_insertable_into::text,&#39;$null$&#39;)<br>    || COALESCE(is_typed::text,&#39;$null$&#39;)<br>    || COALESCE(commit_action::text,&#39;$null$&#39;)<br>  ) AS md5_record_hash,</pre><pre>-- generated primary key column for information_schema.tables<br>COALESCE(table_catalog::text,&#39;$null$&#39;) <br>    || &#39;.&#39; || COALESCE(table_schema::text,&#39;$null$&#39;)<br>    || &#39;.&#39; || COALESCE(table_name::text,&#39;$null$&#39;) AS pk,</pre><p>The s3 files are then ingested from s3 via <a href="https://docs.snowflake.com/en/user-guide/data-load-snowpipe-intro">Snowpipe</a>.</p><p>Let’s focus on the data from the information_schema.columns view. It has a grain of one row per database/schema/table/column in the source db. Pulling in the daily snapshots, we end up with one row per day, per app db of that basic grain. That data contains a lot of noise as it contains rows whether or not definition of the column changed. It would be nice to eliminate the noise (days where there are no changes), and instead only see when the definition of a column <strong><em>actually</em></strong><em> </em>changes. This is where the MD5 hash column, primary key, and MATCH_RECOGNIZE come to the rescue.</p><p>Here’s a simplified example of the ingested data.</p><pre>-- Create temporary table to hold test data<br>CREATE OR REPLACE TEMPORARY TABLE column_data (<br>  pk VARCHAR,<br>  md5_ecord_hash VARCHAR,<br>  run_date DATE<br>);</pre><pre>-- Insert test data<br>INSERT INTO column_data VALUES (&#39;app_db.public.users.id&#39;,&#39;1d89ed6a7992c77ca6b354dc740c4863&#39;,&#39;2024-01-01&#39;);<br>INSERT INTO column_data VALUES (&#39;app_db.public.users.id&#39;,&#39;1d89ed6a7992c77ca6b354dc740c4863&#39;,&#39;2024-01-02&#39;);<br>INSERT INTO column_data VALUES (&#39;app_db.public.users.id&#39;,&#39;1d89ed6a7992c77ca6b354dc740c4863&#39;,&#39;2024-01-03&#39;);<br>INSERT INTO column_data VALUES (&#39;app_db.public.users.id&#39;,&#39;64423ab2626a19efd4c3b58ff3a81ac9&#39;,&#39;2024-01-04&#39;);<br>INSERT INTO column_data VALUES (&#39;app_db.public.users.id&#39;,&#39;64423ab2626a19efd4c3b58ff3a81ac9&#39;,&#39;2024-01-05&#39;);<br>INSERT INTO column_data VALUES (&#39;app_db.public.users.id&#39;,&#39;df8e14b4da70837b1e89095790988380&#39;,&#39;2024-01-06&#39;);<br>INSERT INTO column_data VALUES (&#39;app_db.public.users.username&#39;,&#39;c05a71f3b6efd66f773e63ba6ce9fc3e&#39;,&#39;2024-01-05&#39;);<br>INSERT INTO column_data VALUES (&#39;app_db.public.users.username&#39;,&#39;c05a71f3b6efd66f773e63ba6ce9fc3e&#39;,&#39;2024-01-05&#39;);   -- Intentional duplicate<br>INSERT INTO column_data VALUES (&#39;app_db.public.users.username&#39;,&#39;c05a71f3b6efd66f773e63ba6ce9fc3e&#39;,&#39;2024-01-06&#39;);<br>INSERT INTO column_data VALUES (&#39;app_db.public.users.username&#39;,&#39;271f05dc35cc5b5a33a8da89e42c02dd&#39;,&#39;2024-01-07&#39;);  <br>INSERT INTO column_data VALUES (&#39;app_db.public.users.username&#39;,&#39;271f05dc35cc5b5a33a8da89e42c02dd&#39;,&#39;2024-01-15&#39;);   -- Intentional gap<br>INSERT INTO column_data VALUES (&#39;app_db.public.users.username&#39;,&#39;99210cdd38519cf6ea90b7eb25e27c05&#39;,&#39;2024-01-16&#39;);</pre><pre>-- Show inserted data<br>SELECT *<br>FROM column_data<br>ORDER BY pk, run_date;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YkTu9L_E1yjCFVhoyKj-4A.png" /><figcaption>Preview data</figcaption></figure><p>Notice that for PK valueapp_db.public.users.id , I have daily snapshots from 2024–01–01 thru 2024–01–06 . Some of those daily snapshots have the same hash value while others are different. The change in md5_record_hash value indicates that something about the source database’s column has changed.</p><p>MATCH_RECOGNIZE can collapse these common records and return the start/end dates that the column had a specific md5_record_hash value. This eliminates the noise when the daily snapshot stayed the same.</p><h4>The Solution</h4><pre>-- Collapse time frames to only show when the record changed.<br>SELECT *<br>FROM column_data<br>  MATCH_RECOGNIZE (<br>    PARTITION BY pk<br>    ORDER BY run_date<br>    MEASURES<br>      FIRST(md5_record_hash) AS md5_record_hash,<br>      FIRST(run_date) AS start_date,<br>      LAST(run_date) AS end_date        <br>    ONE ROW PER MATCH<br>    PATTERN (initial_row_or_change{1} row_no_change* )<br>    DEFINE<br>      initial_row_or_change AS<br>        LAG(md5_record_hash) IS NULL<br>        OR md5_record_hash &lt;&gt; NVL(LAG(md5_record_hash), md5_record_hash),<br>      row_no_change AS<br>        md5_record_hash = NVL(LAG(md5_record_hash), md5_record_hash)<br>    )<br>ORDER BY<br>  pk,<br>  start_date;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p9rDMB3onnaKfo0mi9QZ-w.png" /><figcaption>MATCH_RECOGNIZE output</figcaption></figure><p>This yields exactly the output that I wanted!</p><p>I’ll explain the pieces of MATCH_RECOGNIZE to make it clearer what’s going on in the SQL.</p><h4>Breaking down the components</h4><p>First you have the PARTITION BY and ORDER BY portions. These define the scope within which you want to perform the matching and the order in which the records are placed before searching for the pattern.</p><p>The MEASURES portion defines what aggregates you want returned when the pattern is matched. In my case I wanted to return FIRST md5_record_hash, theFIRST run_date, and the LAST run date within the pattern. I aliased the dates to the desired output of START_DATE and END_DATE respectively.</p><p>Here’s where it starts to get more complex. In my case I only wanted to return one row with each matched pattern, so I chose the ONE ROW PER MATCH option. This collapses all of the “no-change” records into a single record. You can also choose ALL ROWS PER MATCH which will not collapse the records.</p><p>Let’s skip over the PATTERN for now and move on to the DEFINE.</p><p>DEFINE allows you to assign a named classifier to records that meet certain criterion. Recall that I wanted to detect changes in the md5_record_hash column, so I used the <a href="https://docs.snowflake.com/en/sql-reference/functions/lag">LAG()</a> window function to check if this value changed from that of the previous record. In addition, I know from experience that the first record in a window/partition will always have a NULL value for LAG() and I wanted to account for that.</p><p>So for the classifier that I defined initial_row_or_change, records that evaluate to TRUE for my custom expression of</p><pre>-- First record in a window/partition<br>LAG(md5_record_hash) IS NULL<br>-- The hash value on this record is different than the last record<br>OR md5_record_hash &lt;&gt; NVL(LAG(md5_record_hash), md5_record_hash)</pre><p>will be given assigned this classifier.</p><p>The next line defines another classifier:</p><pre>row_no_change AS<br>  md5_record_hash = NVL(LAG(md5_record_hash), md5_record_hash)</pre><p>Similar to the previous classifier, any records where the expression evaluates to TRUE will be assigned the classifier of row_no_change.</p><p>Now that we’ve defined the classifiers, let’s return to the PATTERN. This describes the pattern of classifiers that you’re trying to match within the partition.</p><p>In my case, I want to find exactly one initial_row_or_change followed by zero or many row_no_change records.</p><pre>   PATTERN (initial_row_or_change{1} row_no_change* )</pre><p>The symbols to the right of the defined classifier mimic regular expression syntax for the number of desired occurrences. The classifiers are space separated and must be contained in parentheses.</p><h4>An alternate solution</h4><p>Here’s another version of the query that defines three classifiers instead of two. It uses an OR condition implemented as a | character in the PATTERN section. This returns the same result as the original query, but separates the initial row and the change row into two separate classifiers.</p><pre>SELECT *<br>FROM column_data<br>  MATCH_RECOGNIZE (<br>    PARTITION BY pk<br>    ORDER BY run_date<br>    MEASURES<br>      FIRST(md5_record_hash) AS md5_record_hash,<br>      FIRST(run_date) AS start_date,<br>      LAST(run_date) AS end_date        <br>    ONE ROW PER MATCH<br>    PATTERN ((initial_row_or_change{1} | change_row{1}) no_change_row* )<br>    DEFINE<br>      initial_row AS<br>        LAG(md5_record_hash) IS NULL,<br>      change_row AS<br>        md5_record_hash &lt;&gt; NVL(LAG(md5_record_hash), md5_record_hash),<br>      no_change_row AS<br>        md5_record_hash = NVL(LAG(md5_record_hash), md5_record_hash)<br>    )<br>ORDER BY<br>  pk,<br>  start_date;</pre><p>Which one do you like better?</p><h4>Conclusions</h4><p>I’ve done this type of collapsing daily change records into start/end dates before, and it has taken multiple analytic functions and complicated CTEs. The MATCH_RECOGNIZE implementation, though complex at initial glance, really simplifies things.</p><p>Have you solved this same problem in a different way? How does it compare to the MATCH_RECOGNIZE solution? Leave me a comment, I’d love to hear your experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdfba80e546e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/in-the-weeds/using-match-recognize-in-snowflake-bdfba80e546e">Using MATCH_RECOGNIZE in Snowflake</a> was originally published in <a href="https://medium.com/in-the-weeds">In the weeds</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated Ingestion into Snowflake via DMS/s3]]></title>
            <link>https://medium.com/in-the-weeds/automated-ingestion-into-snowflake-via-dms-s3-e64359f062ea?source=rss-d2e0775100bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/e64359f062ea</guid>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[dms]]></category>
            <category><![CDATA[data-ingestion]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Matt Feeser]]></dc:creator>
            <pubDate>Fri, 04 Aug 2023 16:02:27 GMT</pubDate>
            <atom:updated>2024-08-09T15:46:10.590Z</atom:updated>
            <content:encoded><![CDATA[<p>Ingestion of large amounts of change data capture (CDC) data from s3 into Snowflake can be a challenge. How would you manage that ingestion for nearly 300 tables from 8 different <a href="https://aws.amazon.com/rds/">AWS RDS</a> instances populated to s3 via <a href="https://aws.amazon.com/dms/">AWS Database Migration Services (DMS)</a>? It seems like a daunting task, but with some good planning and design, it can be easy to implement and support. Here’s how we did it at Greenhouse.</p><p>If you’re not familiar with AWS DMS, it’s a tool that can be used to read from a source system, typically a database, and propagate the data from that system into a target system. In our case we use AWS DMS to read from the Write-Ahead-Log (WAL) in PostgreSQL RDS instances and populate <a href="https://parquet.apache.org/">parquet</a> files in s3. The specifics of the DMS implementation are for another post. In this post we’ll focus on the ingestion of the s3 parquet files into Snowflake.</p><h3>Frequency of Ingestion</h3><p>The first decision point we made on ingestion was whether to load in near real-time or via batch.</p><p>Initially we looked into near real-time using <a href="https://docs.snowflake.com/en/user-guide/data-load-snowpipe-intro">Snowpipe</a> which can be triggered by s3 bucket notifications. Using Snowpipe the ingestion can be initiated as soon as the source file arrives in s3. However, we found a limitation that AWS only supports up to <a href="https://docs.aws.amazon.com/general/latest/gr/s3.html#limits_s3">100 event notifications per bucket</a>. With our 8 different RDS instances and ~300 tables all writing to the same s3 bucket, we would need 2,400 bucket event notifications. There are workarounds we considered: 1) such as using a single bucket event notification to call a lambda function to identify the specific file and route it to the correct SNS topic or SQS, 2) splitting the DMS target across multiple buckets, but we ultimately we chose to pursue Snowflake Tasks and process daily batches of data from s3. The complete daily ingestion using Tasks averages just over 20 minutes. This is performant enough for us to increase the frequency of ingestion should such a business case arise.</p><p>The use of Snowflake Tasks proved to be a good decision for cost containment as well. Since tasks utilize a virtual warehouse, we can closely control our credit consumption. This could be more difficult to control with an out of the box Snowpipe implementation that scales up based on data volume.</p><p>Here’s our final ingestion pipeline design using Snowflake Tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aIFxeOPV7pnb67l6Be4z7g.png" /><figcaption>Ingestion Pipeline</figcaption></figure><h3>Task Design</h3><p><a href="https://docs.snowflake.com/en/user-guide/tasks-intro">Snowflake Tasks</a> are SQL based units of work that can execute either based on a schedule or based on the completion of a predecessor task (when building a <a href="https://en.wikipedia.org/wiki/Directed_acyclic_graph">DAG</a>). We chose to use User-Managed tasks where we could fully utilize a specified warehouse and run all tasks concurrently.</p><p>Each task is responsible for loading a single table in our Datalake database, which pulls in data from the same logical table across all RDS instances. For example, the user table exists in all 8 RDS instances. A single task is responsible for ingesting the user table from each of the 8 instances. This is achieved by using a consistent file prefix for all of the DMS tasks so that the RDS instance and table name can easily be identified.</p><h3>Stored Procedures</h3><p>We built a series of stored procedures which are called by the tasks. The primary ingestion procedure performs the following steps for a single logical table:</p><ol><li>Dynamically generate a “COPY INTO” statement with a file pattern targeting the table within each RDS instance</li><li>Execute the “COPY INTO” statement</li></ol><p>A single call to the stored procedure results in N number of “COPY INTO” statements executing, 1 per source RDS instance.</p><p>The first stored procedure acts like a wrapper or interface between the task and the stored procedure that performs the ingestion. When called in “incremental” mode, this wrapper procedure determines the s3 file prefix date partition to run for and passes that to the second stored procedure. When called in “initial” mode, the wrapper procedure simply calls the second stored procedure. There are a few benefits to this approach:</p><ol><li>By determining the s3 prefix date partition, we are able to minimize our cloud services layer credit usage in Snowflake by narrowly focusing the file pattern. When loading files with too general of a file pattern in s3, you will see higher cloud service layer credit usage. This is due to the long list times on buckets with a large number of files.</li><li>The stored procedure that performs the ingestion can be called directly during maintenance or support rotations. If a file did not get ingested, the correct date partition can be passed to it and the file will be loaded.</li></ol><p>When <a href="https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.S3.html">using s3 as the target endpoint for DMS</a>, the default file naming convention produces different filenames for the full load and CDC files. Full files are stored within the root table prefix and begin with the word LOAD. CDC files on the other hand, use timestamps for the file name based on when the records were written to the file. In addition, we configured DMS to create the CDC files in <a href="https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.S3.html#CHAP_Target.S3.DatePartitioning">date-based folders</a> using the DatePartitionEnabled, DatePartitionSequence, and DatePartitionDelimeter endpoint configuration parameters. So the CDC files contain the date they were created in their file prefix. Finally, we also included the source RDS instance as a prefix to the file name. For example, the full file and CDC file can be found the s3 bucket with the following prefix and file name.</p><h4>Full File:</h4><pre>dms-s3-bucket-name/rds_instance_1/public/users/LOAD000000001.parquet</pre><h4>CDC (aka incremental file):</h4><pre>dms-s3-bucket-name/rds_instance_1/public/users/2023/06/01/20230601-004208649.parquet</pre><h4><strong>Example: Initial Load Dynamically Generated Copy Into Statement (no date partition)</strong></h4><pre>COPY INTO DATALAKE.APP.USERS (<br>  RECORD,<br>  PK,<br>  _OPERATION,<br>  _COMMIT_TIMESTAMP,<br>  _LOAD_TIMESTAMP,<br>  _FILE_NAME,<br>  _FILE_ROW_NUMBER<br>)<br>FROM (<br>  SELECT<br>    $1::variant as RECORD,<br>    $1:id::varchar as PK,<br>    $1:Op::varchar as _OPERATION,<br>    $1:_commit_timestamp::TIMESTAMP_TZ as _COMMIT_TIMESTAMP,<br>    current_timestamp::TIMESTAMP_TZ as _LOAD_TIMESTAMP,<br>    metadata$filename as _FILE_NAME,<br>    metadata$file_row_number as _FILE_ROW_NUMBER<br>  FROM @DATALAKE.APP.STAGE_DMS_S3_DATALAKE/rds_instance_1/public/users/LOAD<br>)<br>FILE_FORMAT = DATALAKE.APP.PARQUET_FORMAT<br>ON_ERROR = skip_file;</pre><h4>Example: Incremental Dynamically Generated Copy Into Statement</h4><pre>COPY INTO DATALAKE.APP.USERS (<br>  RECORD,<br>  PK,<br>  _OPERATION,<br>  _COMMIT_TIMESTAMP,<br>  _LOAD_TIMESTAMP,<br>  _FILE_NAME,<br>  _FILE_ROW_NUMBER<br>)<br>FROM (<br>  SELECT<br>    $1::variant as RECORD,<br>    $1:id::varchar as PK,<br>    $1:Op::varchar as _OPERATION,<br>    $1:_commit_timestamp::TIMESTAMP_TZ as _COMMIT_TIMESTAMP,<br>    current_timestamp::TIMESTAMP_TZ as _LOAD_TIMESTAMP,<br>    metadata$filename as _FILE_NAME,<br>    metadata$file_row_number as _FILE_ROW_NUMBER<br>  FROM @DATALAKE.APP.STAGE_DMS_S3_DATALAKE/rds_instance_1/public/users/2023/06/05/<br>)<br>FILE_FORMAT = DATALAKE.APP.PARQUET_FORMAT<br>ON_ERROR = skip_file;</pre><p>For the “COPY INTO” statements to execute successfully, they need access to s3. We accomplished this by configuring an External Stage, Storage Integration, File Format, and the necessary IAM roles/privileges via Terraform.</p><h3>Triggering the Tasks</h3><p>Snowflake tasks can be triggered by a cron schedule, or by the successful execution of a predecessor task. In our case, all of the tasks are independent, so we used a cron schedule. All tasks trigger at the same time.</p><h3>Monitoring/Alerting</h3><p>By default, Snowflake tasks timeout after 60 minutes. On days with increased data volume from the source system, we occasionally run into this default duration and the task times out or gets canceled.</p><p>We decided not to increase the default timeout for the tasks, as this could lead to runaway ingestion tasks that consume excessive credits. Instead, the team decided that an alert sent to our data-alerts slack channel would be sufficient for notifying the support person of the issue. The tasks could then be investigated and manually restarted and monitored as needed.</p><p>This was implemented via an <a href="https://docs.snowflake.com/en/user-guide/tasks-errors-aws">error notification integration in Snowflake to an AWS SNS topic</a> which invoked a lambda function to send the alert to the Slack webhook.</p><h3>Provisioning the Resources</h3><p>We used Terraform to provision all of the resources to support the ingestion process. This included:</p><p>Snowflake</p><ul><li>Databases</li><li>Schemas</li><li>Tables</li><li>Stored Procedures</li><li>Tasks</li><li>Storage Integrations</li><li>External Stages</li><li>File Formats</li></ul><p>AWS</p><ul><li>IAM roles/permissions</li></ul><p>A module was created to provision all of the resources needed for the ingestion of a single logical table across the RDS instances. With this design, we were able to use a single list variable in Terraform, to store all of the source table names to be ingested and call the module in a for_each loop. If a new table needs to be added to the ingestion in the future, all that needs to happen is to add the table name to the list variable. The task and target table in Snowflake to handle the ingestion will be created on the next Terraform apply command.</p><pre>locals {<br>  tables = [<br>    &quot;table_1&quot;,<br>    &quot;table_2&quot;,<br>    &quot;table_3&quot;,<br>    &quot;table_4&quot;,<br>  ]<br>}</pre><pre>module &quot;snowflake_s3_ingestion&quot; {<br>  source = &quot;../../../../snowflake_s3_ingestion&quot;<br><br>  for_each                                = toset(local.tables)<br>  region                                  = &quot;use1&quot;<br>  bucket_arn                              = &quot;arn:aws:s3:::your-s3-bucket-name&quot;<br>  database                                = &quot;DATALAKE&quot;<br>  schema                                  = &quot;APP&quot;<br>  stage_name                              = &quot;STAGE_DMS_S3_DATALAKE&quot;<br>  table_name                              = upper(each.key)<br>  file_format                             = &quot;PARQUET_FORMAT&quot;<br>  storage_integration                     = &quot;PROD_S3_STORAGE_INTEGRATION&quot;<br>  storage_aws_iam_user_arn                = &quot;arn:aws:iam::123456789:role/use1-prod-snowflake-storage-integration&quot;<br>  automation_type                         = &quot;task&quot;<br>  automation_enabled                      = true<br>  sql_statement                           = format(&quot;CALL %s.%s.%s(&#39;%s&#39;,&#39;%s&#39;,&#39;incremental&#39;)&quot;, &quot;DATALAKE&quot;, &quot;APP&quot;, &quot;INGEST_APP_TABLE_PROC&quot;, upper(each.key), &quot;id&quot;)<br>  task_warehouse                          = &quot;DMS_S3_INGEST_APP&quot;<br>  task_schedule                           = &quot;USING CRON 30 0 * * * UTC&quot;<br>  snowflake_notification_integration_name = &quot;PROD_NOTIFICATION_INGTEGRATION&quot;<br>}</pre><h3>Snowflake Tasks Lessons Learned</h3><ol><li>By default, all Snowflake Tasks are deployed in a suspended state. This means that they will not execute on their specific schedule until they are manually enabled.</li><li>Due to the task’s state change being made outside of Terraform, we implemented a lifecycle policy to ignore changes on the enabled attribute of the task. This reduced the noise in subsequent Terraform plans and did not overwrite our intended state in future deployments.</li><li>Terraform and Snowflake don’t agree on column data types. What you provision in Terraform may show slightly different in Snowflake. For example, specifying VARCHAR(100) will end up being VARCHAR with no length constraint in Snowflake. This will cause constant drift in a Terraform plan. To remedy this, we also put in a lifecycle policy to ignore changes to column data types. Likely this will be fixed in a newer version of the Terraform provider for Snowflake.</li></ol><h3>Right-Sizing the Ingestion Warehouse</h3><p>In order to attribute cost and to ensure we could independently scale the ingestion workload, we created a separate warehouse for the sole purpose of ingestion. We ran a number of tests to determine the right-size for the warehouse.</p><p>Before embarking on this effort we set a goal that we wanted to complete the entire ingestion in under 30 minutes and minimize amount of credits used. In addition, we took the time to review the actual workload. This is important because in some cases increasing the number clusters or adjusting the scaling policy may not have not have the expected impact on overall runtime.</p><p><strong>The Workload</strong></p><ul><li>All 300 tasks execute daily on the same cron schedule</li><li>Each task executes 8 “COPY INTO”statements (one for each RDS instance)</li></ul><p>The workload is constant, with the same number of statements being run daily. Though the data volume may change in s3, the number of tasks/statements to complete with each ingestion does not fluctuate between runs.</p><p>This led us to believe that we would get the best results with a <a href="https://docs.snowflake.com/en/user-guide/warehouses-multicluster#increasing-or-decreasing-clusters-for-a-multi-cluster-warehouse">multi-cluster warehouse</a> running in Maximized mode, so that all clusters are available as soon as the warehouse is started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oKOnA6fgEAkiFccORNI4wQ.png" /><figcaption>Warehouse Configurations Tested</figcaption></figure><p>For configuration 1, we saw high volume of query queueing and runtimes that exceeded the 60 minute task default timeout.</p><p>With configuration 2 we still observed high queueing and runtimes that exceeded the 60 minute task default timeout. This supported our earlier notion that auto-scaling the clusters would not significantly improve performance.</p><p>Using configuration 3, there was still some queuing, but it was minimal. Tasks completed at a reasonable rate with the entire ingestion taking about 20 minutes.</p><p>At the time of writing this, we are averaging only 4.8 credits used daily for this ingestion warehouse.</p><h3>Structure of the Datalake tables</h3><p>One of the challenges in loading CDC changes into a database is schema change over time. If a new column gets added to a table in the source system, that new column also needs to be added to the target table during the ingestion. Fortunately AWS DMS configured with a s3 target can automatically add these new columns to the output CDC files. So the added column is present in the file in s3, now we just need to make our load process incorporate the new column.</p><p>To ensure no data loss, and that all columns were present in our raw tables in Snowflake, we use a VARIANT column to store the entire content of the record from the source system. In addition to the VARIANT column, we keep some metadata about the load process and source s3 file. Finally, we parse out some important fields from the variant column and store them as individual columns on the table. This is done to simplify the process of sequencing the CDC changes to identify the current image of a record. Those columns include the primary key column from the source table, the timestamp of when the record was committed in the source system, and the DML operation (Insert, Update, or Delete). This results in all of the tables in our Snowflake Datalake databases having a common structure of:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wb3xBIQt8AheEdyIW2z-jA.png" /><figcaption>Datalake Table Structure</figcaption></figure><p>We configured the DMS tasks to propagate source table DDL changes to the s3 target endpoint, so the parquet files in s3 include any new columns that get added to the sources. Because the COPY INTO statement in the Snowflake Task maps the entire source record to the RECORD VARIANT column, all new columns show up automatically. There is no need for code changes to the ingestion process for new columns to appear in the Snowflake Datalake.</p><h3>Key Takeaways</h3><p>Some of my favorite features from this implementation were:</p><ul><li><strong>Ease of adding a new table</strong>. Simply add the table name to the Terraform list variable.</li><li><strong>Ease of adding a new RDS instance. </strong>Simply add the RDS instance name to a list variable in Terraform that is used by the Snowflake Stored Procedure.</li><li><strong>Source schema change resilience</strong>. Any newly added columns to the source tables automagically show up in Snowflake.</li><li><strong>Low Snowflake credit usage. </strong>I am still amazed that we can ingest so much data from our source application for less than 5 credits per day.</li></ul><h3>Conclusion</h3><p>This was a very fun project. It took about 8 weeks from the design and initial POC to implementation. I learned a ton about Terraform, Snowflake, s3, and DMS along the way. I hope this helps you in your development of ingestion patterns into Snowflake.</p><h4>Update July 15, 2024:</h4><p>I was asked in the comments to provide a sample of the module code that was used in this example. For context, this version of the module code contains support for serverless tasks, which we found to work better when a large number of tasks execute simultaneously on the same warehouse. Additionally, this version removes support for snowpipe, as the tasks method of ingestion is working fine. This module does nothing more than provision the target table for ingestion and the task based on the details provided in the module call.</p><pre>locals {<br>  task_schedule                            = var.task_schedule<br>  task_name                                = &quot;TASK_${upper(var.table_name)}&quot;<br>  snowflake_notification_integration_name  = var.snowflake_notification_integration_name<br>  user_task_managed_initial_warehouse_size = &quot;XSMALL&quot;<br>}<br><br>resource &quot;snowflake_table&quot; &quot;this&quot; {<br>  database        = var.database<br>  schema          = var.schema<br>  name            = var.table_name<br>  comment         = &quot;Raw ingest table for ${var.table_name}&quot;<br>  change_tracking = false<br><br>  data_retention_time_in_days = var.data_retention_time_in_days<br><br>  column {<br>    name = &quot;PK&quot;<br>    type = &quot;VARCHAR&quot;<br>  }<br><br>  column {<br>    name = &quot;RECORD&quot;<br>    type = &quot;VARIANT&quot;<br>  }<br><br>  column {<br>    name = &quot;_OPERATION&quot;<br>    type = &quot;VARCHAR&quot;<br>  }<br><br>  column {<br>    name = &quot;_COMMIT_TIMESTAMP&quot;<br>    type = &quot;TIMESTAMP_TZ(9)&quot;<br>  }<br><br>  column {<br>    name     = &quot;_FILE_NAME&quot;<br>    type     = &quot;VARCHAR&quot;<br>    nullable = false<br>  }<br><br>  column {<br>    name     = &quot;_FILE_ROW_NUMBER&quot;<br>    type     = &quot;NUMBER(38,0)&quot;<br>    nullable = false<br>  }<br><br>  column {<br>    name = &quot;_LOAD_TIMESTAMP&quot;<br>    type = &quot;TIMESTAMP_TZ(9)&quot;<br>  }<br>}<br><br>resource &quot;snowflake_task&quot; &quot;this&quot; {<br>  database  = var.database<br>  schema    = var.schema<br>  warehouse = var.task_warehouse != &quot;&quot; ? var.task_warehouse : null<br><br>  name              = local.task_name<br>  sql_statement     = var.sql_statement<br>  schedule          = var.task_schedule<br>  enabled           = var.automation_enabled<br>  error_integration = var.snowflake_notification_integration_name<br><br>  user_task_managed_initial_warehouse_size = var.task_warehouse != &quot;&quot; ? null : local.user_task_managed_initial_warehouse_size<br><br>  lifecycle {<br>    ignore_changes = [<br>      enabled<br>    ]<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e64359f062ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/in-the-weeds/automated-ingestion-into-snowflake-via-dms-s3-e64359f062ea">Automated Ingestion into Snowflake via DMS/s3</a> was originally published in <a href="https://medium.com/in-the-weeds">In the weeds</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>