Snowflake

circle-exclamation

This article demonstrates how to bring your existing Excel logic into Snowflakearrow-up-right using Coherent Sparkarrow-up-right .

You’ll learn how Coherent Spark (or simply Spark) lets you run complex Excel models as API services inside Snowflake, so you can tap directly into your existing data. This guide assumes some familiarity with Snowflake and walks you through prerequisites, setup, and common practices. It covers logging into both Coherent Spark and Snowflake, using the Snowflake CLI, and configuring network rules for external access. You’ll also find examples of calling Spark services with the requests library and the Coherent Spark Python SDKarrow-up-right. The article wraps up with advanced use cases and links to additional resources.

Why would you want to do this? In an ideal world, your modeling logic should live where your data lives. But while Snowflake is powerful for data storage and processing, building complex functions directly in Snowflake can be challenging. On the other hand, most business users prefer Excel for modeling because it’s intuitive and flexible. Coherent Spark bridges that gap by transforming your Excel models into scalable API services that integrate coherently with Snowflake.

After reading this guide, you’ll be able to run your externalized Excel functions directly from within Snowflake.

chevron-rightPrerequisiteshashtag

Before you begin, make sure you have:

  • access to a Snowflake account with ACCOUNTADMIN or similar privileges

  • access to a Coherent Spark account with READ and EXECUTE permissions

  • basic familiarity with Python and SQL

  • Snowflake CLI installed (optional but recommended)

circle-info

Most actions can be performed in the Snowflake UI, but some are better suited for the Snowflake CLI.

Getting started

Let’s start by gathering the necessary credentials and information to work with both Snowflake and Coherent Spark.

circle-info

We recommend working within a testing or development environment for both Snowflake (e.g., Snowflake warehouse, which should allow you to safely run queries and procedures without affecting your production environment) and Coherent Spark during this setup.

Log in to Coherent Spark

Coherent Spark is a platform that allows you to run Excel models in a cloud environment, exposing them as API services.

Log in to your Coherent Spark accountarrow-up-right to get the following:

Roughly speaking, a folder acts as a container that holds one or more services. Think of folders as a way to organize and group related services together. Each service represents an Excel model that has been converted into a Spark service. Services can exist in multiple versions, representing different iterations or updates of that service over time. When interacting with a Spark service, you are always working with a specific version – the latest one by default. You can explicitly specify an older version if you need to work with a previous iteration of the service.

Find more information about Spark services in the How to: Create a Spark service.

Log in to Snowflake

Using the right credentials, log into your Snowflake accountarrow-up-right, which will take you to the Snowflake Dashboard by default. If you are an ACCOUNTADMIN (or similar role), you will be able to see all the projects, including worksheets and notebooks, in the left sidebar.

Confirm in your Catalogarrow-up-right that you are able to see the database, schema, and tables you intend to use. Visit the Snowflake documentationarrow-up-right page to learn more.

2 Different ways of accessing Coherent within Snowflake

Within Snowflake, you will utilize notebook to create access to Coherent Spark. There, we describe 2 ways to achieve this:

  1. Using Python library: requestarrow-up-right

  2. Or using Coherent Python SDK: csparkarrow-up-right.

To start, click the top-right button to create a new notebook. You can also use the provided sample Jupyter notebook at the bottom of this page for a quick start guide. Once you are within the notebook environment, ensure requests library is installed (ideally, its latest version).

Once this is installed, your environment will restart, and you can proceed to the next phase.

Snowflake + Coherent Spark

Snowflake needs to be able to communicate with Coherent Spark. This is done by setting up network rules and external access integrations. By default, outbound traffic is blocked.

Let’s start a notebook so we can leverage Snowpark to execute Python and SQL code alongside your data. Snowflake Labsarrow-up-right has a great collection of notebooks that you can use to get started. The Access External Endpointsarrow-up-right one is a good starting point.

Setting up external access integration

To enable communication between Snowflake and Coherent Spark, you need to set up network rules. Here’s an example of a network rule cs_network_rule for Coherent Spark:

In the example above, the network rule allows the following services to be accessed:

  • https://keycloak.{region}.coherent.global for Keycloak (Coherent’s Identity Provider)

  • https://excel.{region}.coherent.global for Excel calculations (Coherent Spark’s main Excel engine)

circle-info

The {region} is the environment where Coherent Spark services are hosted. In the SQL example above, the region is uat.us, meaning UAT environment in the United States.

After creating the network rule, set up the external access integration:

Finally, locate the notebook Settings and enable the external access integration for the rule you just created, as illustrated below.

Enable external access integration

Calling a Spark service

Depending on the method you have chosen above, we have 2 different code snippets:

Within a Python-enabled cell, let’s call a Spark service using the Python requests library.

requestsarrow-up-right is an elegant and simple HTTP library for Python, which is already installed in the Snowpark environment (see Snowflake Anaconda Channelarrow-up-right for more details).

Here’s a simple example of calling a Coherent Spark service using the requests library. In the example, we are calling the volume-cylinder service with some inputs.

Calling Spark using the requests library

To make things even easier, we’ve also included a Snowpark-adapted Jupyter Notebook (see attached file below) that developers can use to accelerate the integration process and quickly experiment with running Excel-based models in Snowflake.

circle-exclamation

What’s next?

Now that you have a basic understanding of how to call Coherent Spark services from Snowflake, you can start introducing more Snowflake native features (e.g., UDFs, stored procedures, etc.) into the picture. Remember, for your bulk processing needs, Spark supports both synchronous and asynchronous batch processing.

For more details on the advanced use cases, visit the SDK documentationarrow-up-right. Some of the topics covered in the guide are:

  • How-to: Execute records sequentially (1 record at a time)

  • How-to: Execute batch of records synchronously (up to 100 records at a time)

  • Asynchronous batch processing (high-throughput processing)

Last updated