Snowflake Connector with Apache Spark(scala)- Source-Sink Connectivity
If there is a requirement to add Cloud warehouse Snowflake connector to a Spark application written in scala, then here you can refer below code snippet(Test.scala) which will help you to read from Snowflake and writing a Dataframe to this locally provided you have been given with connection details. Try test connection from DB client as mentioned below.
- First you have to create a sample table in Snowflake and import data to it from any file system(say csv).
- Next you have to read this table as a Dataframe to your Spark.
- After reading you can do some query onto it and create a new table where you can write the results of the query as a dataframe there in Snowflake.
4. And in build.sbt, add the below library.(it depends on Scala version used in your application)
libraryDependencies += "net.snowflake" % "spark-snowflake_2.11" % "2.5.9-spark_2.4"
5. Create a test.scala file, run it locally using the above and verify if you are able to connect to Snowflake and do read/write operations.
This is written to do a quick connection test from your local environement to Snowflake Cloud warehouse. Hope this helps!