Skip to main content

Adding a Snowflake Data Source

breaking changes

Currently, the Reveal SDK is in the process of decoupling the data sources from the Reveal SDK core package. In order to ensure the project's continued functionality, you might be required to install additional packages into your project. Please see the Supported Data Sources topic for more information.

On the Client

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

var revealView = new $.ig.RevealView("#revealView");
revealView.onDataSourcesRequested = (callback) => {
//add code 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 property. After you have created the RVSnowflakeSource object, add it to the data sources collection.

revealView.onDataSourcesRequested = (callback) => {
var snowflakeDataSource = new $.ig.RVSnowflakeDataSource();
snowflakeDataSource.title = "My Snowflake";

callback(new $.ig.RevealDataSources([snowflakeDataSource], [], 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.

Step 3 - Add a new Data Source Item by creating a new instance of the RVSnowflakeDataSourceItem object. Set the Id and Title properties that correspond to your database table. After you have created the RVSnowflakeDataSourceItem object, add it to the data source items collection.

revealView.onDataSourcesRequested = (callback) => {
var mySnowflakeDataSource = new $.ig.RVSnowflakeDataSource();
mySnowflakeDataSource.id = "MySnowflakeDataSource";
mySnowflakeDataSource.title = "My Snowflake";

var mySnowflakeDataSourceItem = new $.ig.RVSnowflakeDataSourceItem(mySnowflakeDataSource);
mySnowflakeDataSourceItem.id = "MySnowflakeDataSourceItem";
mySnowflakeDataSourceItem.title = "My Snowflake Item";

callback(new $.ig.RevealDataSources([mySnowflakeDataSource], [mySnowflakeDataSourceItem], true));
};

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.

On the Server

Step 1 - Create the data source and data source item on the client, but do not provide any connection information. Only provie an id, title, and/or subtitle.

revealView.onDataSourcesRequested = (callback) => {
var mySnowflakeDataSource = new $.ig.RVSnowflakeDataSource();
mySnowflakeDataSource.id = "MySnowflakeDataSource";
mySnowflakeDataSource.title = "My Snowflake";

var mySnowflakeDataSourceItem = new $.ig.RVSnowflakeDataSourceItem(mySnowflakeDataSource);
mySnowflakeDataSourceItem.id = "MySnowflakeDataSourceItem";
mySnowflakeDataSourceItem.title = "My Snowflake Item";

callback(new $.ig.RevealDataSources([mySnowflakeDataSource], [mySnowflakeDataSourceItem], true));
};

Step 2 - Create the data source provider. In this example, we are providing connection information to connect to our Snowflake database that was defined on the client. To achieve this, we determine the type of the data source/item we are working with, and set the available properties on the object.

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);
}
}
Get the Code

The source code to this sample can be found on GitHub