Setting Up IntelliJ IDEA CE for Snowpark

This topic explains how to set up IntelliJ IDEA CE for Snowpark.

In this Topic:

Setting Up IntelliJ IDEA CE for Scala Development

To use Scala in IntelliJ IDEA CE, you need to install the Scala plugin. See the Installation section of the tutorial Getting Started with Scala in IntelliJ IDEA.

Creating a New Scala Project in IntelliJ IDEA

Next, create a new Scala project for Snowpark.

  1. Choose File » New » Project.

    1. In the list on the left, select Scala.

    2. In the list on the right, select sbt.

      Window for selecting the type of project to create
    3. Click Next.

  2. Fill in the details for your new project.

    For the JDK and Scala SDK, select the JDK and Scala versions supported for use with Snowpark.

  3. Click Finish to create the new project.

Configuring the IntelliJ IDEA Project for Snowpark

Next, configure the project for Snowpark.

In the Project tool window on the left, double-click on the build.sbt file for your project.

In the build.sbt file for your project, make the following changes:

  1. If the scalaVersion setting does not match the version that you plan to use, update the setting. For example:

    scalaVersion := "2.12.13"
    

    Note that you must use a Scala version that is supported for use with the Snowpark library.

  2. Add the OSGEO release repository to the list of resolvers, and add the Snowpark library to the list of dependencies. For example:

    resolvers += "OSGeo Release Repository" at "https://repo.osgeo.org/repository/release/"
    libraryDependencies += "com.snowflake" % "snowpark" % "0.6.0"
  3. Save the changes to the build.sbt file.

  4. Reload the SBT project:

    1. Choose View » Tool Windows » sbt to display the sbt Tool window.

    2. Right-click on the project name, and choose Reload sbt Project.

    This causes IntelliJ IDEA CE to download the Snowpark library and makes the API available for use in your code.

Verifying Your IntelliJ IDEA Project Configuration

To verify that you have configured your project to use Snowpark, run a simple example of Snowpark code.

  1. In the Project tool window on the left, expand your project, expand the src/main folders, and select the scala folder.

  2. Right-click on the folder, and choose New » Scala class.

  3. In the Create New Scala Class dialog box, enter the name “Main”, select Object, and press the Enter key.

  4. In the Main.scala file, replace the contents with the code below:

    import com.snowflake.snowpark._
    import com.snowflake.snowpark.functions._
    
    object Main {
      def main(args: Array[String]): Unit = {
        // Replace the <placeholders> below.
        val configs = Map (
          "URL" -> "https://<account_identifier>.snowflakecomputing.com:443",
          "USER" -> "<user name>",
          "PASSWORD" -> "<password>",
          "ROLE" -> "<role name>",
          "WAREHOUSE" -> "<warehouse name>",
          "DB" -> "<database name>",
          "SCHEMA" -> "<schema name>"
        )
        val session = Session.builder.configs(configs).create
        session.sql("show tables").show()
      }
    }
    

    Note the following:

    • Replace the <placeholders> with values that you use to connect to Snowflake.

    • For <account_identifier>, specify your account identifier.

    • If you prefer to use key pair authentication:

      • Replace PASSWORD with PRIVATE_KEY_FILE, and set it to the path to your private key file.

      • If the private key is encrypted, you must set PRIVATE_KEY_FILE_PWD to the passphrase for decrypting the private key.

      As an alternative to setting PRIVATE_KEY_FILE, you can set the PRIVATEKEY property to the value of the private key from the private key file. Note that you must remove the -----BEGIN ... PRIVATE KEY----- and -----END ... PRIVATE KEY----- lines as well as the carriage returns and line feeds.

    • If you plan to create UDFs:

  5. Click the green arrow next to the Object line, and choose Run Main to run the example.

    Arrow icon for running the sample program