Skip to main content

Snowflake Data Source

Introduction

Snowflake is a cloud-based data warehousing platform that provides scalable storage and compute resources for data analytics, data sharing, and business intelligence workloads. This topic explains how to connect to Snowflake data sources in your Reveal application to visualize and analyze your data.

Server Configuration

Installation

Step 1 - Install the Reveal Snowflake connector package

For ASP.NET applications, you need to install a separate NuGet package to enable Snowflake support:

dotnet add package Reveal.Sdk.Data.Snowflake

Step 2 - Register the Snowflake data source in your application:

builder.Services.AddControllers().AddReveal( builder =>
{
builder.DataSources.RegisterSnowflake();
});

Connection Configuration

public class DataSourceProvider : IRVDataSourceProvider
{
public Task<RVDataSourceItem> ChangeDataSourceItemAsync(IRVUserContext userContext, string dashboardId,
RVDataSourceItem dataSourceItem)
{
if (dataSourceItem is RVSnowflakeDataSourceItem snowflakeDataSourceItem)
{
//update underlying data source
ChangeDataSourceAsync(userContext, snowflakeDataSourceItem.DataSource);

//only change the table if we have selected our custom data source item
if (snowflakeDataSourceItem.Id == "MySnowflakeDataSourceItem")
{
snowflakeDataSourceItem.Schema = "TPCDS_SF100TCL";
snowflakeDataSourceItem.Table = "CUSTOMER";
}
}

return Task.FromResult(dataSourceItem);
}

public Task<RVDashboardDataSource> ChangeDataSourceAsync(IRVUserContext userContext,
RVDashboardDataSource dataSource)
{
if (dataSource is RVSnowflakeDataSource snowflakeDataSource)
{
snowflakeDataSource.Account = "your-account";
snowflakeDataSource.Host = "your-account-host";
snowflakeDataSource.Database = "SNOWFLAKE_SAMPLE_DATA";
}

return Task.FromResult(dataSource);
}
}
Important

Any changes made to the data source in the ChangeDataSourceAsync method are not carried over into the ChangeDataSourceItemAsync method. You must update the data source properties in both methods. We recommend calling the ChangeDataSourceAsync method within the ChangeDataSourceItemAsync method passing the data source item's underlying data source as the parameter as shown in the examples above.

Authentication

Authentication for Snowflake is handled on the server side using username and password credentials. For detailed information on all authentication options, see the Authentication topic.

public class AuthenticationProvider: IRVAuthenticationProvider
{
public Task<IRVDataSourceCredential> ResolveCredentialsAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
IRVDataSourceCredential userCredential = null;
if (dataSource is RVSnowflakeDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential("username", "password");
}
return Task.FromResult<IRVDataSourceCredential>(userCredential);
}
}

Client-Side Implementation

Creating Data Sources

Step 1 - Add an event handler for the RevealView.onDataSourcesRequested event.

const revealView = new $.ig.RevealView("#revealView");
revealView.onDataSourcesRequested = (callback) => {
// Add data source here
callback(new $.ig.RevealDataSources([], [], false));
};

Step 2 - In the RevealView.onDataSourcesRequested event handler, create a new instance of the RVSnowflakeDataSource object. Set the title and subtitle properties. After you have created the RVSnowflakeDataSource object, add it to the data sources collection.

revealView.onDataSourcesRequested = (callback) => {
const snowflakeDS = new $.ig.RVSnowflakeDataSource();
snowflakeDS.title = "Snowflake";
snowflakeDS.subtitle = "Data Source";

callback(new $.ig.RevealDataSources([snowflakeDS], [], false));
};

When the application runs, create a new Visualization and you will see the newly created Snowflake data source listed in the "Select a Data Source" dialog.

Creating Data Source Items

Data source items represent specific datasets within your Snowflake data source that users can select for visualization. On the client side, you only need to specify ID, title, and subtitle.

revealView.onDataSourcesRequested = (callback) => {
// Create the data source
const snowflakeDS = new $.ig.RVSnowflakeDataSource();
snowflakeDS.title = "My Snowflake Datasource";
snowflakeDS.subtitle = "Snowflake";

// Create a data source item
const snowflakeDSI = new $.ig.RVSnowflakeDataSourceItem(snowflakeDS);
snowflakeDSI.id = "MySnowflakeDataSourceItem";
snowflakeDSI.title = "My Snowflake Datasource Item";
snowflakeDSI.subtitle = "Snowflake";

callback(new $.ig.RevealDataSources([snowflakeDS], [snowflakeDSI], false));
};

When the application runs, create a new Visualization and you will see the newly created Snowflake data source item listed in the "Select a Data Source" dialog.

Additional Resources

API Reference