Setting Up the Scala REPL for Snowpark Scala¶
This topic explains how to set up the Scala REPL for Snowpark.
Installing the Scala REPL¶
The Scala REPL (https://docs.scala-lang.org/overviews/repl/overview.html) (read-eval-print loop) is provided with the Scala build tool. To install the supported version of the Scala build tool, find the version that you plan to use (https://www.scala-lang.org/download/all.html), and follow the installation instructions.
Running the Scala REPL¶
To use the Snowpark library in the Scala REPL:
- If you have not already done so, download the Snowpark library archive file and extract the contents of the file.
- Start the REPL by running the
run.shshell script provided in the archive file:
cd <path>/snowpark-1.18.0 ./run.sh
The run.sh script does the following:
- Adds the Snowpark library and dependencies to the classpath.
- Creates a <path>/snowpark-1.18.0/repl_classes/ directory for the classes generated by the Scala REPL.
- Preloads the
preload.scalafile, which imports thecom.snowflake.snowparkpackage and thecom.snowflake.snowpark.functionsobject.
If you are using a different REPL for Scala:
-
Add the Snowpark library JAR file and dependencies to the classpath.
- The Snowpark library JAR file is in the top level directory of the extracted TAR/ZIP archive file.
- The dependencies are in the
libdirectory of the extracted TAR/ZIP archive file.
-
Create a temporary directory for the classes generated by the REPL, and configure the REPL to generate classes in that directory.
Later, when defining inline user-defined functions (UDFs), you’ll need to specify the directory for the REPL classes as a dependency.
Verifying Your Scala REPL Configuration¶
To verify that you have configured your project to use Snowpark, run a simple example of Snowpark code.
-
In the directory containing the files extracted from the
.zip/.tar.gzfile (i.e. the directory containing therun.shscript), create aMain.scalafile that contains the code below:Note the following:
-
Replace the
placeholderswith 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.
- Replace
- If you plan to create UDFs:
- Don’t set up your
objectto extend theApptrait. For details, see Caveat About Creating UDFs in an Object With the App Trait. - Don’t set up your
objectto extend a class or trait that is not serializable.
- Don’t set up your
-
-
From within the directory, run the
run.shscript to start the Scala REPL with the settings needed for the Snowpark library: -
In the Scala REPL shell, enter the following command to load the sample file that you just created:
-
Run the following statement to execute the
mainmethod of the class that you loaded:This runs the
SHOW TABLEScommand and prints out the first 10 rows of the results.