使用spark读取雪花表时,面向pyspark的classnotfound异常

oyjwcjzk  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(578)

我正试着读《星火弹》里的雪花表。为此,我做了以下工作。

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()

运行load语句后,我将面临以下classnotfound异常:

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

在上面的操作中,只需要读取一个雪花表,根据文档,我传递了启动sparkshell所需的jar文件。
启动pyspark时加载的spark版本是 version 2.3.2.3.1.5.37-1 我尝试了多个版本的雪花连接器 2.3/2.4/2.8/3.0 我还传递了jar文件 jackson-dataformat-xml-2.10.3.jar 但我还是看到了同样的例外。
有谁能告诉我我在这里犯了什么错误,我该怎么改正?

vddsk6oq

vddsk6oq1#

你应该跑

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

对于代码相关问题:

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()

相关问题