Connect to Snowflake Data Warehouse with GO

In this installment, I am going to walk through the process of connecting GO to the Snowflake Data Warehouse Service (DWaaS). This tutorial requires that you have a Snowflake account. You can sign up here for a 30 day/$400.00 trial.

Download and Install the ODBC Driver

Once you have your account set up in Snowflake, follow the directions to download the ODBC Driver. It will the same place you find the snowSQL download:

Warehouse driver download

Installing GO

Installing GO can be accomplished via Homebrew or visiting the GoLang download page. If you chose Homebrew, can find installation instructions on their page, or you can copy and paste:

which will get you going right away. Once you get Homebrew going, you can simply type:

Confirm GO is installed:

After you install GO, this would be a good time to update you .profile to include a GOPATH environment variable. For my configuration, it looks like this:

Install dep

dep is a prototype dependency management tool for Go. It requires Go 1.9 or newer to compile. Since Homebrew is already on your machine, we can easily install dep using brew:

Install the GO Snowflake Driver:

Get Gosnowflake source code and dep (dependency managment tool), if not installed, and ensure the dependent libraries are installed.

Now that we have most of the prerequisites for the connection done, we need to build the sample programs

After executing the make install command, I found our test file “select1.go” in the following subdirectory:

If you have all of your path information configured correctly, this should be okay for you test a connection. This test program will simply attempt to connect to the Snowflake data warehouse. There are three parameters required for connecting to Snowflake via GO and the select1.go test file.

Let’s take a look at the snippet from the select1.go file

The function above comes from the select1.go test file. You should notice that the env function for account, user, and password pass a true parameter. These are values read from your O/S environment variables. I created a shell script to set these values for testing purposes.

Once you have run the script, check that your environment variables are set:

After verifying these environment variables have been set correctly, confirm that you are in the directory with the select1.go file and execute the following:

If you see the Congrats! message, then congratulations, you have successfully connect to the Snowflake Data Warehouse Cloud Service.

dbaontap warehosue


Also published on Medium.

This site uses Akismet to reduce spam. Learn how your comment data is processed.