top of page

The UnionAll Blog

Insights and ideas on all things data, from innovation to implementation.


What is the Snowflake Native Apps framework?

The Snowflake native app framework (currently in preview for AWS-accounts) allows users to create and share data-applications with other snowflake accounts. The applications can be as simple as a custom stored procedure or an entire app with a Streamlit interface and custom tables.


Building a Snowflake Native App with external access table of contents:

💡 You currently have to have a snowflake account with AWS as a cloud provider in a non gov-region.


External access in Snowflake:

  • Creating a secret in snowflake

  • Setting up a network rule in snowflake

  • Setting up an external access integration in snowflake

  • Setting up an external function in snowflake


Creating a secret in snowflake (Optional)

CREATE SECRET MY_API_SECRET
    TYPE = GENERIC_STRING
    SECRET_STRING = '<your-api-key>';

Setting up a network rule in snowflake

CREATE NETWORK RULE MY_NETWORK_RULE
    MODE = EGRESS
    TYPE = HOST_PORT
    VALUE_LIST = ('<external-domain>');

Setting up an external access integration in snowflake

CREATE EXTERNAL ACCESS INTEGRATION MY_EXTERNAL_INTEGRATION
    ALLOWED_NETWORK_RULES = (MY_NETWORK_RULE)
    ALLOWED_AUTHENTICATION_SECRETS = (MY_API_SECRET)
    ENABLED = true;

Setting up an external function in snowflake

//Example function of a get-request with a single argument and the api-key as bearer token
CREATE SECURE FUNCTION CALL_YOUR_API(argument varchar)
    RETURNS STRING
    LANGUAGE PYTHON
    RUNTIME_VERSION = 3.9
    HANDLER = 'call_api'
    EXTERNAL_ACCESS_INTEGRATIONS = (MY_EXTERNAL_INTEGRATION)
    SECRETS = ('API_KEY' = MY_API_SECRET)
    PACKAGES = ('requests','urllib3')
    AS
$$
import _snowflake
import requests
from urllib.parse import urlencode
def call_api(argument):
    my_api_key = _snowflake.get_generic_secret_string('API_KEY')
    request_url = "<url-to-request>"
    headers = {
        "accept": "application/json",
        "Content-Type": "application/json",
        "Authorization": f"Bearer {my_api_key}",
    }
    response = requests.get(request_url + "?" + urlencode({"argument":argument}),headers=headers)
    return response.text
$$;

Calling the function from snowflake

select CALL_YOUR_API('my argument');

Building the app

App hierarchy

readme.md
manifest.yml
streamlit
|-- app.py
|-- environment.yml
scripts
|-- setup.sql

Creating a manifest-file

manifest_version: 1
artifacts:
  setup_script: scripts/setup.sql
  readme: readme.md
  extension_code: true

Creating a setup-script

CREATE APPLICATION ROLE app_public;

CREATE OR ALTER VERSIONED SCHEMA code_schema;
GRANT USAGE ON SCHEMA code_schema TO APPLICATION ROLE app_public;

CREATE STREAMLIT code_schema.your_streamlit_app
  FROM '/streamlit'
  MAIN_FILE = '/app.py'
;

GRANT USAGE ON STREAMLIT code_schema.your_streamlit_app TO APPLICATION ROLE app_public;

Creating a streamlit app

import streamlit as st
from snowflake.snowpark.context import get_active_session
import snowflake.permissions as permission
import json

st.title("Hello world")

# Get the current credentials
session = get_active_session()

Set the environment for the streamlit app

name: sf_env
channels:
- snowflake
dependencies:
- snowflake-native-apps-permission

Putting it all together

Setting your function-reference

💡 You have to add a version to the app to be able to set and use references


Adding the reference to the manifest:

references:
  - function_reference:
      label: "External function"
      description: "Function to external resource"
      privileges:
        - USAGE
      object_type: FUNCTION
      register_callback: code_schema.update_reference

Setting the reference in the streamlit app

request_attribute = "Some attribute"
# Fetching the function reference
function_reference = permission.get_reference_associations("function_reference")
if len(function_reference) == 0:
    permission.request_reference("function_reference")
else:
    results = session.sql(f"SELECT reference('function_reference')('{request_attribute}')")
		st.write("Success!")
		st.write(results)

Adding a reference setter in the setup-script

create or replace procedure code_schema.update_reference(ref_name string, operation string, ref_or_alias string)
returns string
language sql
as $$
begin
  case (operation)
    when 'ADD' then
       select system$set_reference(:ref_name, :ref_or_alias);
    when 'REMOVE' then
       select system$remove_reference(:ref_name, :ref_or_alias);
    when 'CLEAR' then
       select system$remove_all_references();
    else
       return 'Unknown operation: ' || operation;
  end case;
  return 'Success';
end;
$$;

grant usage on procedure code_schema.update_reference(string, string, string) to application role app_public;

Adding a CI-script to run as a github-action

name: CI

on:
  # Triggers the workflow on main
  push:
    branches:
      - "main"
    tags:
      - "v*"

  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest

    env:
      SNOWSQL_PWD: ${{ secrets.SNOWFLAKE_PASSWORD }}
      SNOWSQL_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }}
      SNOWSQL_USER: ${{ secrets.SNOWFLAKE_USERNAME }}
      SNOWSQL_DATABASE: ${{ secrets.SNOWFLAKE_DATABASE }}
      SNOWSQL_SCHEMA: ${{ secrets.SNOWFLAKE_SCHEMA }}
      SNOWSQL_ROLE: ${{ secrets.SNOWFLAKE_ROLE }}
      SNOWSQL_WAREHOUSE: ${{ secrets.SNOWFLAKE_WAREHOUSE }}

    steps:
      - uses: actions/checkout@v3

      - name: Install SnowSQL
        run: |
          curl -O <https://sfc-repo.snowflakecomputing.com/snowsql/bootstrap/1.2/linux_x86_64/snowsql-1.2.9-linux_x86_64.bash>
          SNOWSQL_DEST=~/bin SNOWSQL_LOGIN_SHELL=~/.profile bash snowsql-1.2.9-linux_x86_64.bash
      - name: Upload artifact to Snowflake
        env:
          GITHUB_ACTION_PATH: ${{ github.action_path }}
        run: |
          ~/bin/snowsql -q 'put file://'$(pwd)'/manifest.yml @<your-application-package>.<your-stage-schema>.<your-stage> overwrite=true auto_compress=false;'
          ~/bin/snowsql -q 'put file://'$(pwd)'/scripts/setup.sql @<your-application-package>.<your-stage-schema>.<your-stage>/scripts overwrite=true auto_compress=false;'
          ~/bin/snowsql -q 'put file://'$(pwd)'/readme.md @<your-application-package>.<your-stage-schema>.<your-stage> overwrite=true auto_compress=false;'
          ~/bin/snowsql -q 'put file://'$(pwd)'/streamlit/app.py @<your-application-package>.<your-stage-schema>.<your-stage>/streamlit overwrite=true auto_compress=false;'
          ~/bin/snowsql -q 'put file://'$(pwd)'/streamlit/environment.yml @<your-application-package>.<your-stage-schema>.<your-stage>/streamlit overwrite=true auto_compress=false;'
      - name: Create or update Application
        run: |
          ~/bin/snowsql -q 'ALTER APPLICATION PACKAGE <your_application-package> DROP VERSION V1_0;
                            ALTER APPLICATION PACKAGE <your_application-package>
                              ADD VERSION V1_0 USING '@<your-application-package>.<your-stage-schema>.<your-stage>';
                            DROP APPLICATION IF EXISTS <your-application>;
                            CREATE APPLICATION <your-application>
                              FROM APPLICATION PACKAGE <your_application-package>
                              USING VERSION V1_0;'

Now you are all done!

Feel free to reach out if you have any questions.

In the era of constant change, businesses face a critical decision: adapt or fade away. The key to thriving in the digital age lies in cultivating a data-driven culture within your organization. This post provides tangible tips for leaders to empower their teams with curiosity and drive innovation through data exploration.

  1. Curiosity as a Catalyst: Cultivate a culture of curiosity by actively encouraging questions. Create a safe space for your team to express curiosity without fear of judgment. This simple shift can spark a mindset that drives data exploration and problem-solving.

  2. Democratize Access to Data: Break down the traditional silos around data. Make information accessible to all employees, not just those with a background in analytics. Invest in user-friendly platforms that empower individuals to explore and interpret data, fostering a sense of ownership and accountability.

  3. Actionable Insights, Not Overwhelming Data: Shift the focus from drowning in data to extracting actionable insights. Provide training that helps your team translate data findings into practical strategies. Emphasize the importance of taking informed action based on these insights, creating a culture where data is a tool for decision-making, not an overwhelming burden.

  4. Balance Human Judgment and Data Insights: Acknowledge the power of human intuition and experience in decision-making. Highlight real-world examples where combining human judgment with data insights has led to successful outcomes. It's the synergy between human understanding and data-driven insights that often produces the most effective strategies.

  5. Cross-Functional Collaboration Workshops: Organize regular workshops or collaborative sessions that bring together members from both the IT and business departments. These sessions should focus on specific projects or challenges where joint efforts are essential. By working side by side, teams can bridge the communication gap, gain a deeper understanding of each other's perspectives, and develop shared solutions. This hands-on approach fosters a sense of unity and breaks down the traditional barriers between IT and business, creating a more integrated and collaborative working environment.

  6. Storytelling for Impact: Share success stories within your organization that showcase the positive outcomes of data-driven initiatives. Use storytelling to convey the real-world impact of data exploration and how it has contributed to the company's overall success. This helps inspire others to embrace a similar approach.

  7. Recognition and Rewards: Recognize and reward individuals and teams who actively contribute to the data-driven culture. This can include acknowledging innovative uses of data, successful problem-solving, or significant improvements resulting from data-driven decision-making. Positive reinforcement reinforces the desired behavior.

Leadership plays a crucial role in transforming a company into a data-driven powerhouse. By implementing these practical tips, you can create an environment where curiosity thrives, data is a tool for empowerment, and innovation becomes a natural byproduct. The journey toward a data-driven culture is not just for the elite few—it's a path that every business leader can navigate, leading their team to success in the digital age.

In today’s fast-paced business world, using data for key company decisions is critical in steering the organisation in the right direction. While this practice may be second nature for successful companies, we will delve into the evolution of Data-Driven 2.0, providing a competitive edge. We’ll explore the ways companies are getting smart with data: by looking inside their own office walls and checking what’s happening beyond.


What it means to be Data-Driven

Being “Data-Driven” means taking strategic decisions based on empirical data analysis and interpretation in contrast to a human intuition or instinct. Decisions backed by actual data consistently outperform those based on intuition alone. According to research conducted by McKinsey Global Institute in 2020, organisations that prioritise data-driven approaches are significantly more successful in various aspects. These data-centric companies are 23 times more likely to attract new customers, exhibit a sixfold increase in customer retention rates, and are 19 times more likely to achieve profitability compared to those not leveraging data-driven strategies.


How organisations are Data-Driven today

In the automotive industry, an approach to data-driven optimization can be implemented with a focus on vehicle maintenance and customer satisfaction. Imagine an auto repair shop that meticulously records data on every repair job it undertakes. This data includes the types of vehicles serviced, the nature of the repairs, the time taken for each job, customer feedback, and the frequency of repeat visits for similar issues.


By analysing this data, the shop can identify patterns and trends. For instance, they might discover that certain models of cars frequently require specific types of repairs after a certain mileage. With this insight, the shop can proactively reach out to owners of these vehicles for preemptive maintenance, thereby reducing the likelihood of major breakdowns and enhancing customer satisfaction.


Moreover, by tracking the time efficiency of different repair jobs, the shop can optimise its scheduling and staffing, ensuring that it has the right number of technicians with the appropriate skills available at peak times. This leads to quicker service times and increased customer satisfaction.


Additionally, the shop can use this data to maintain an optimal inventory of parts. By knowing which parts are most commonly used for the types of vehicles they service, the shop can keep a well-stocked inventory, reducing wait times for repairs and avoiding the cost of holding unnecessary inventory.


In essence, the auto repair shop uses its internal data to optimise operational efficiency, improve customer service, and enhance overall profitability.


5-step process for implementing Data Driven Decisions


1. Clarify Digital Business Goals:

Review existing documentation regarding company vision, strategy and existing goals. Gather insights on digital business objectives, including their priority.


2. Identify Key Metrics

Collaborate with departments to identify existing or desired key performance indicators (KPI’s). Prioritise the metrics in collaboration with stakeholders.


3. Access Key Metric Measurability

Evaluate data availability for the prioritised metrics. Assess measurability in terms of dimensionality and historization and map it to user needs.


4. Map Key Metrics to Data Sources:

Identify what data sources that are involved in the calculation of the prioritised metrics. Engage IT/data team to assess data source reliability and accessibility. Prioritise data sources based on relevance to key metrics.


5. List Data Source Gaps (Data Driven 2.0):

Identify gaps in data coverage. List potential new data sources to explore from a technical standpoint.


Become Data-Driven 2.0 with External Data Sources

Data-Driven 2.0 signifies the next phase in the evolution of data-driven decision-making. It involves not just understanding internal metrics but also harnessing data from diverse external sources to gain a comprehensive view.


By tapping into a variety of external data sources, companies can paint a vivid picture of the market landscape, consumer behaviours, and industry trends. This expanded perspective allows for a more nuanced understanding, enabling businesses to make informed decisions that go beyond the confines of internal data.


The synergy of internal and external data sources is the cornerstone of Data-Driven 2.0, where the richness of insights from the broader world becomes an integral part of strategic decision-making.


External data is available within industry specific data platforms, such as leads databases containing contact information on relevant clients to approach, or financial analysis platforms to better benchmark your performance against peers. Also, external datasets can be found available for sale on public data marketplaces.


However, grasping how to best use and apply external datasets to get the most relevant insights and analysis input to your own business needs might not always be crystal clear. This is where the UnionAll platform enters the playing field - it helps you both identify what external metrics, KPI’s and trends are essential to incorporate and deliver these external data sources all within one platform.


On this, we will delve deeper into in our upcoming article - applying external data to your business.


bottom of page