apache-sparkpysparksnowflake-cloud-data-platformsnowflake-task

Facing classnotfound exception while reading a snowflake table using spark


I am trying to read a snowflake table from spark-shell. To do that, I did the following.

pyspark --jars spark-snowflake_2.11-2.8.0-spark_2.4.jar,jackson-dataformat-xml-2.10.3.jar
Using Python version 2.7.5 (default, Feb 20 2018 09:19:12)
SparkSession available as 'spark'.
>>> from pyspark import SparkConf, SparkContext
>>> from pyspark.sql import SQLContext
>>> from pyspark.sql.types import *
>>> from pyspark import SparkConf, SparkContext
>>> sc = SparkContext("local", "Simple App")
>>> spark = SQLContext(sc)
>>> spark_conf = SparkConf().setMaster('local').setAppName('CHECK')
>>> sfOptions = {
... "sfURL" : "url",
... "sfAccount" : "acntname",
... "sfUser" : 'username',
... "sfPassword" : 'pwd',
... "sfRole" :    'role',
... "sfDatabase" : 'dbname',
... "sfSchema" :  'schema',
... "sfWarehouse" : 'warehousename'
... }
>>> SNOWFLAKE_SOURCE = 'net.snowflake.spark.snowflake'
>>> df = spark.read.format(SNOWFLAKE_SOURCE).options(**sfOptions).option("query","select column from schema.table limit 1").load()

Once I run the load statement, I am facing the below classnotfound exception:

Caused by: java.lang.ClassNotFoundException: net.snowflake.client.jdbc.internal.fasterxml.jackson.databind.ObjectMapper

In the above operation, there is nothing but reading a snowflake table and as per the documentation, I passed the required jar file I started spark-shell.

The spark version that loads when I start pyspark is version 2.3.2.3.1.5.37-1 I tried with multiple versions of snowflake connector which are 2.3/2.4/2.8/3.0 and I also passed the jar file jackson-dataformat-xml-2.10.3.jar but I still see the same exception.

Could anyone let me know what is the mistake I am doing here and how can I correct it ?


Solution

  • You should run

    pyspark --jars spark-snowflake_2.11-2.8.0-spark_2.4.jar,snowflake-jdbc-3.12.5.jar
    

    For the code related question :

    spark = SparkSession \
    .builder \
    .config("spark.jars", "<pathto>/snowflake-jdbc-3.12.5.jar,<pathto>/spark-snowflake_2.11-2.7.1-spark_2.4.jar") \
    .config("spark.repl.local.jars",
            "<pathto>/snowflake-jdbc-3.12.5.jar,<pathto>/spark-snowflake_2.11-2.7.1-spark_2.4.jar") \
    .config("spark.sql.catalogImplementation", "in-memory") \
    .getOrCreate()