<?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 Abhilashp on Medium]]></title>
        <description><![CDATA[Stories by Abhilashp on Medium]]></description>
        <link>https://medium.com/@abhilashp296?source=rss-fbaf9b601d4f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*UISXazjAWEqG1PGx</url>
            <title>Stories by Abhilashp on Medium</title>
            <link>https://medium.com/@abhilashp296?source=rss-fbaf9b601d4f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 08:54:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhilashp296/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[Ingest API data natively in Snowflake]]></title>
            <link>https://medium.com/@abhilashp296/ingest-api-data-natively-in-snowflake-9eeee13c5ebb?source=rss-fbaf9b601d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9eeee13c5ebb</guid>
            <dc:creator><![CDATA[Abhilashp]]></dc:creator>
            <pubDate>Mon, 02 Sep 2024 09:38:40 GMT</pubDate>
            <atom:updated>2024-09-02T09:38:40.781Z</atom:updated>
            <content:encoded><![CDATA[<p>Data warehousing involves integrating data from multiple sources, often including API-based sources such as web services or third-party applications. Traditionally, data ingestion for platforms like Snowflake relies on cloud-based integration tools to streamline this process. However, in this article, we will explore an alternative approach that leverages Snowflake’s native features to build end-to-end data pipelines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*vQjNnddrR3mpebGvuwFOCA.png" /><figcaption>High level flow diagram</figcaption></figure><p>Accessing the external networks from Snowflake involves three additional components other than the typical components like procedures, tasks, tables etc.</p><p>· <strong>Network Rule</strong> whitelists the URL of the external API to enable access.</p><p>· <strong>Secret</strong> stores credentials required for authentication.</p><p>· <strong>External access integration</strong> encapsulates the above for easier access from procedures and functions.</p><p>In this article, I have used data from one of the sample modules from Creatio CRM tool as a data source. The first step involves creation of network rule to enable access to the Creatio URLs.</p><pre>CREATE OR REPLACE NETWORK RULE creatio_apis_network_rule<br>  MODE = EGRESS<br>  TYPE = HOST_PORT<br>  VALUE_LIST = (&#39;000-crm-bundle-is.creatio.com&#39;,&#39;000-crm-bundle.creatio.com&#39;);</pre><p>Next we create a secret to store the client id and client secret required for API authentication. This step is crucial to ensure that credentials are protected and properly managed.</p><pre> CREATE OR REPLACE SECRET creatio_api_secret<br>  TYPE = GENERIC_STRING<br>  SECRET_STRING = &#39;{&quot;client_id&quot;:&quot;123456&quot;,<br>      &quot;client_secret&quot;:&quot;abcdef&quot;,<br>      &quot;grant_type&quot;:&quot;client_credentials&quot;}&#39;;</pre><p>The external access integration links the network rule and secrets, which will be used within a Python function.</p><pre> CREATE OR REPLACE EXTERNAL ACCESS INTEGRATION creatio_api_access_integration<br>  ALLOWED_NETWORK_RULES = (creatio_apis_network_rule)<br>  ALLOWED_AUTHENTICATION_SECRETS = (creatio_api_secret)<br>  ENABLED = true;</pre><p>The Python function interacts with the web API and retrieves data. First, the function obtains an access token by passing the credentials to the API. Once the access token is acquired, it is used to make subsequent data requests to retrieve the actual data in JSON format. The function supports incremental data loading by including an optional date parameter, which helps to fetch only the new or updated data since the specified date.</p><pre>CREATE OR REPLACE FUNCTION ingest_creatio_data(modulename string,datefield string,datevalue string)<br>RETURNS STRING<br>LANGUAGE PYTHON<br>RUNTIME_VERSION = 3.8<br>HANDLER = &#39;get_creatiodata&#39;<br>EXTERNAL_ACCESS_INTEGRATIONS = (creatio_api_access_integration)<br>PACKAGES = (&#39;snowflake-snowpark-python&#39;,&#39;requests&#39;)<br>SECRETS = (&#39;cred&#39; = creatio_api_secret )<br>AS<br>$$<br>import _snowflake<br>import requests<br>import json<br>session = requests.Session()<br>def get_accesstoken():<br>  credential= json.loads(_snowflake.get_generic_secret_string(&#39;cred&#39;))<br>  url = &quot;https://000-crm-bundle-is.creatio.com/connect/token&quot;;<br>  response = requests.post(url,data=credential)<br>  return response.json().get(&#39;access_token&#39;)<br>def get_creatiodata(modulename, datefield,datevalue):<br>  token=get_accesstoken()<br>  url = &quot;https://000-crm-bundle.creatio.com/0/odata/&quot;+modulename<br>  filter=(&quot;&quot; if datevalue is None else &quot;?$filter=&quot;+datefield+&quot; gt &quot;+datevalue+&quot;T00:00:00.000000Z&quot;);<br>  headers = {<br>        &quot;Authorization&quot;: &quot;Bearer &quot; + token<br>    }<br>  response = requests.get(url+filter,headers=headers)<br>  return response.json()<br><br>$$;</pre><p>The above function can be further used in a stored procedure which will convert the JSON output to tabular structure and perform necessary transformations. The process can be automated using tasks to complete the data pipeline.</p><p>The external access integration is a powerful feature in Snowflake that opens new possibilities in data warehousing. Beyond the data integration capabilities discussed, this feature also enables a range of data-driven activities that can enhance decision-making processes. Let me know any interesting use cases you have achieved using this feature.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9eeee13c5ebb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analyzing Reviews with Snowflake TOP_INSIGHTS to spot key trends]]></title>
            <link>https://medium.com/@abhilashp296/analyzing-reviews-with-snowflake-top-insights-to-spot-key-trends-aaf1bec33867?source=rss-fbaf9b601d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/aaf1bec33867</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[mls]]></category>
            <category><![CDATA[snowflake-cortex]]></category>
            <category><![CDATA[snowflake]]></category>
            <dc:creator><![CDATA[Abhilashp]]></dc:creator>
            <pubDate>Fri, 19 Apr 2024 07:41:23 GMT</pubDate>
            <atom:updated>2024-04-19T08:08:32.212Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Analyzing customer reviews with Snowflake TOP_INSIGHTS to spot key trends</strong></h3><p>Snowflake cortex provides two kinds of functions: LLM and ML. In this blog, let us explore one of the use cases of the ML function TOP_INSIGHTS.</p><p><strong>How it works</strong></p><p>TOP_INSIGHTS function helps us in identifying key dimensions (categorical and continuous) driving change in a particular metric . It accepts the dimensions, metric and label as inputs. The label input separates the data into test and control data.</p><p>Snowflake builds a predictive model based solely on the control data. It then uses this model to generate predictions for the test data. This happens for various combinations of the dimensions we provided. The output highlights the key deviations between the predicted values and the actual values in the test data for those combinations.</p><blockquote>Note: Above explanation intends to give an idea about the functionality and may not be the exact implementation by Snowflake</blockquote><p><strong>Use case</strong></p><p>I have chosen a <a href="https://zenodo.org/records/1219899">dataset </a>which contains hotel reviews and corresponding ratings extracted from Trip Advisor. The goal is to analyze the reviews and identify key factors that contribute to positive or negative guest sentiment.</p><p>This is done in two steps:</p><ol><li><strong>Extraction of key attributes</strong></li></ol><p>The key attributes are extracted from review text using the COMPLETE function in Snowflake Cortex. The prompt provides the JSON template which will be filled by the LLM.</p><pre>SELECT review,<br>   SNOWFLAKE.CORTEX.COMPLETE(&#39;mistral-7b&#39;,CONCAT(&#39;I want to understand and extract some elements from the review to fill the given json template. Json template: <br>   {&quot;View type&quot;:&quot;Value&quot;,<br>  &quot;Location&quot;:&quot;Value&quot;,<br>  &quot;Overall Staff Behaviour&quot;:&quot;Value&quot;,<br>  &quot;Food&quot;:&quot;Value&quot;,<br>  &quot;Price&quot;:&quot;Value&quot;,<br>  &quot;Cleanliness&quot;:&quot;Value&quot;}<br>  Value for each attribute must be only among these given below<br>  View type: Nature,City, NA<br>  Location:Accessible, Remote, NA<br>  Overall Staff Behaviour:Courteous,Arrogant,Mixed,NA<br>  Food:Great,Average,Bad,NA<br>  Price:Expensive,Moderate,Cheap<br>  Cleanliness:Clean,Average,Dirty,NA<br><br> Output should start directly with the json object. <br> Don&#39;&#39;t provide any explanation or justification for the answer&#39;,review,&#39;&#39;)) AS ExtractedJson,<br> IFF(RATING in (1,2),FALSE,TRUE) AS HighlyRated<br>FROM<br>  HOTELREVIEWS</pre><p>Extracted JSON is loaded into a table and it looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JCAlE8WBjCH51DfCAdURNw.png" /></figure><p><strong>2. Identification of key contributors</strong></p><p>This step analyzes the categorical dimensions extracted earlier to identify which combinations influence review sentiment. The continuous dimension is optional and metric is a constant value, since we’re only interested in comparing two data classes. We ensure the model trains on highly-rated reviews by using the label column value.</p><pre>with input as<br>(<br>select<br>{<br>&#39;ViewType&#39;:inp.ViewType,<br>&#39;Location&#39;: inp.Location,<br>&#39;Price&#39;: inp.Price,<br>&#39;StaffBehaviour&#39;: inp.StaffBehaviour,<br>&#39;Food&#39;: inp.Food,<br>&#39;Cleanliness&#39;: inp.Cleanliness<br>} as categorical_dimensions,<br>{<br>} continuous_dimensions,<br>1 AS metric,<br>not highlyrated as Label<br>from  hotelreviewdetail inp<br><br>)<br>SELECT res.* from input, TABLE(<br>  SNOWFLAKE.ML.TOP_INSIGHTS(<br>    input.categorical_dimensions,<br>    input.continuous_dimensions,<br>    CAST(input.metric AS FLOAT),<br>    input.label<br>  )<br>  OVER (PARTITION BY 0)<br>) res <br>ORDER BY res.surprise DESC ;</pre><p>The output looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*E5_W6MoxDG6JPaBzQ-y5ng.png" /><figcaption>Result</figcaption></figure><p>Based on this we can deduce that “cheaper hotels which are not clean are more likely to be rated lower by customers”. The results include all possible dimension combinations calculated by the function, along with their corresponding effect on the metric.</p><p>Let us try to test the output by manually comparing the top contributor with overall dataset. First query below shows the overall distribution of low ratings and second one shows the same for the top contributor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*O4ko0mUxOpbsF9Ds_dpnAA.png" /><figcaption>Overall</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*LrMwDqop5AuKQS-KNRcl9w.png" /><figcaption>Top contributor</figcaption></figure><p>Based on above it is clear that the top contributor has significantly higher percentage of low ratings compared to the overall dataset.</p><p><strong>Conclusion</strong></p><p>We have seen how TOP_INSIGHTS, along with the COMPLETE function can be used together to analyze reviews and find the key contributors for negative reviews. The reverse can be achieved by either inverting the label input or changing the sort direction of the final query. This use case can be further enhanced by using SUMMARIZE function to obtain shortened version of reviews and SENTIMENT function to understand the sentiment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aaf1bec33867" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated test data generation for Snowflake tables using Cortex]]></title>
            <link>https://medium.com/@abhilashp296/automated-test-data-generation-for-snowflake-tables-using-cortex-f078d17f6915?source=rss-fbaf9b601d4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f078d17f6915</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[cortex]]></category>
            <category><![CDATA[snowflake]]></category>
            <dc:creator><![CDATA[Abhilashp]]></dc:creator>
            <pubDate>Thu, 04 Apr 2024 08:01:30 GMT</pubDate>
            <atom:updated>2024-04-04T08:01:30.911Z</atom:updated>
            <content:encoded><![CDATA[<p>Snowflake has recently brought the power of LLMs to SQL via Cortex functions which are currently in public preview. This blog showcases the effortless generation of sample data for testing, eliminating the need for complex prompts.</p><p>Some of us are already using LLMs to generate sample data by leveraging services like ChatGPT, Gemini. However, this involves writing a prompt to provide the LLM with the table schema and other details. With Snowflake, we can do it in just a few clicks.</p><p>To showcase this functionality, we developed a simple Streamlit app. This app lets users select the tables they can access and then generate test data for those tables. The application looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*pC3gA-rsUrtZNItI0Dnx2A.jpeg" /><figcaption>Streamlit App</figcaption></figure><p>Users can select a table and specify the number of rows required. Clicking ‘Generate Test Data’ displays the sample data on the screen, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*9jq6FJHvdcUU2BYiX0KJMg.jpeg" /><figcaption>Sample output</figcaption></figure><p>Under the hood, this is achieved using these simple steps:</p><ol><li>Accept user inputs like table and number of rows to be generated. The inbuilt views in information_schema are utilized to populate the drop-downs.</li></ol><pre># Get list of databases<br>def get_databases():<br>  databases = session.sql(f&quot;select Database_name from information_schema.databases&quot;).to_pandas()<br>  return databases<br><br># Get list of schemas for a selected database<br>def get_schemas(selected_database):<br>  schemas = session.sql(f&quot;select Schema_name from information_schema.schemata where catalog_name=&#39;{selected_database}&#39;&quot;).to_pandas()<br>  return schemas<br><br># Get list of tables for a selected schema<br>def get_tables(selected_database, selected_schema):<br>  tables = session.sql(f&quot;select Table_name from information_schema.tables where table_schema=&#39;{selected_schema}&#39; and table_catalog=&#39;{selected_database}&#39;&quot;).to_pandas()<br>  return tables<br>    <br># Dropdowns to select the table and user input on number of rows<br>selected_database = st.selectbox(&quot;Select Database&quot;, get_databases())<br>selected_schema = st.selectbox(&quot;Select Schema&quot;, get_schemas(selected_database))<br>selected_table = st.selectbox(&quot;Select Table&quot;, get_tables(selected_database, selected_schema))<br>RowCount = st.text_input(&quot;Enter Number of rows to be generated&quot;)</pre><p>2. Extract the table schema as a JSON utilizing the information_schema.columns view</p><pre>if st.button(&quot;**Generate test data**&quot;):<br>    if selected_table:<br>        # Get the table schema as a json string<br>        table_schema=session.sql(f&quot;select  TO_JSON(ARRAY_AGG(OBJECT_CONSTRUCT_KEEP_NULL(*))) AS json_data from (select column_name,data_type from information_schema.columns where  upper(table_name)=upper(&#39;{selected_table}&#39;) limit 10)&quot;).to_pandas()</pre><p>3. Pass a prompt containing table schema to cortex complete function and generate the response.</p><pre>#Prompt the cortex function to generate test data based on table schema <br>        data_json=session.sql(f&quot;&quot;&quot;select SNOWFLAKE.CORTEX.COMPLETE(&#39;mistral-7b&#39;<br>            , Concat(&#39;You are a bot to automatically generate data for given table schema<br>            . Generate the data in json format which has {RowCount} objects. <br>            Output should have a valid JSON  with values for each column_name in the schema <br>            Don&#39;&#39;t provide any explanation or justification for the response &lt;schema&gt;&#39;,&#39;{str(table_schema.iloc[0][0])}&#39;))&quot;&quot;&quot;).to_pandas()</pre><p>4. Clean the response to extract only the JSON object and then display it as a table.</p><pre>#Extract only JSON from the response<br>        json_string=str(data_json.iloc[0][0])<br>        json_start = json_string.find(&quot;[&quot;)<br>        # Find the last closing square bracket (indicating the end of the JSON array)<br>        json_end = json_string.rfind(&quot;]&quot;)<br>        # Extract the JSON string<br>        json_string = json_string[json_start:json_end + 1]<br>        # Convert JSON to dataframe and display it<br>        data_df = pd.read_json(json_string)<br>        st.header(&quot;Generated data&quot;)<br>        st.dataframe(data_df)</pre><p><strong>Conclusion</strong></p><p>We have thus seen the simple implementation of Generative AI in Snowflake through Cortex functions and Streamlit, offering a potential productivity boost for data professionals. However, as with all LLM-based solutions, it’s crucial to acknowledge current limitations and potential inaccuracies.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f078d17f6915" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>