Setting Up IntelliJ IDEA CE for Snowpark Java¶
This topic explains how to set up IntelliJ IDEA CE for Snowpark.
Creating a New Maven Project in IntelliJ IDEA¶
Create a new Maven project for Snowpark.
Choose File » New » Project.
From the Project SDK menu, select 11 (for Java version 11).
Note that you don’t need to select an archetype. You can just leave the Create from archetype box unchecked.
Click Next.
Enter a name and location for your project (e.g.
hello-snowpark).Click Finish to create the new project.
Configuring the IntelliJ IDEA Project for Snowpark¶
Next, configure the project for Snowpark.
Open the
pom.xmlfile for the project.In the
<project>tag, add the tags to specify a dependency on the Snowpark library:<dependencies> ... <dependency> <groupId>com.snowflake</groupId> <artifactId>snowpark</artifactId> <version>1.16.0</version> </dependency> ... </dependencies>Save the changes to the
pom.xmlfile.Update your Maven repositories.
Verifying Your IntelliJ IDEA Project Configuration¶
To verify that you have configured your project to use Snowpark, run a simple example of Snowpark code.
In the Project tool window on the left, expand your project, expand the
src/mainfolders, and select thejavafolder.Right-click on the folder, and choose New » Java class.
In the New Java Class dialog box, enter the name “HelloSnowpark”, select Class, and press the Enter key.
In the
HelloSnowpark.javafile, replace the contents with the code below:import com.snowflake.snowpark_java.*; import java.util.HashMap; import java.util.Map; public class HelloSnowpark { public static void main(String[] args) { // Replace the <placeholders> below. Map<String, String> properties = new HashMap<>(); properties.put("URL", "https://<account_identifier>.snowflakecomputing.com:443"); properties.put("USER", "<user name>"); properties.put("PASSWORD", "<password>"); properties.put("ROLE", "<role name>"); properties.put("WAREHOUSE", "<warehouse name>"); properties.put("DB", "<database name>"); properties.put("SCHEMA", "<schema name>"); Session session = Session.builder().configs(properties).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
PASSWORDwithPRIVATE_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_PWDto the passphrase for decrypting the private key.
As an alternative to setting
PRIVATE_KEY_FILEandPRIVATE_KEY_FILE_PWD, you can set thePRIVATEKEYproperty to the string value of the unencrypted private key from the private key file.For example, if your private key file is unencrypted, set this to the value of the key in the file (without the
-----BEGIN PRIVATE KEY-----and-----END PRIVATE KEY-----header and footer and without the line endings).Note that if the private key is encrypted, you must decrypt the key before setting it as the value of the
PRIVATEKEYproperty.
Click the green arrow next to the
Classline, and choose Run HelloSnowpark.main() to run the example.