jupyter cassandra保存问题-java.lang.noclassdeffounderror:com/twitter/jsr166e/longadder

z3yyvxxp  于 2021-06-10  发布在  Cassandra
关注(0)|答案(1)|浏览(403)

我正在使用jupyter笔记本,想保存csv文件到cassandra数据库。在获取数据并显示它时没有问题,但是当我尝试将这个csv数据保存到cassandradb时,它抛出以下异常。

: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 1.0 failed 1 times, most recent failure: Lost task 0.0 in stage 1.0 (TID 1, localhost, executor driver): java.lang.NoClassDefFoundError: com/twitter/jsr166e/LongAdder

我手动下载了maven包2.4.0和2.4.1,但都没有成功。在代码顶部还声明了包。

import sys
import uuid
import time
import os

os.environ['PYSPARK_SUBMIT_ARGS'] = '--packages com.datastax.spark:spark-cassandra-connector_2.11:2.4.0 pyspark-shell'

try:
    from pyspark import SparkContext
    from pyspark import SparkConf
    from pyspark.sql import SparkSession
    from itertools import islice
    from pyspark.sql import SQLContext
    from pyspark.sql.types import *
    from pyspark.sql import Row
    from datetime import datetime

except ImportError as e:
    print("error importing spark modules", e)
    sys.exit(1)

conf = SparkConf().setAppName("Stand Alone Python Script").setMaster("local[*]")\
                        .setAll([('spark.executor.memory', '8g'),\
                        ('spark.executor.cores', '3'),\
                        ('spark.cores.max', '3'),\
                        ('spark.cassandra.connection.host', 'cassandra_ip'),\
                        ('spark.cassandra.auth.username', 'cassandra_user_name'),\
                        ('spark.cassandra.auth.password', 'cassandra_password'),\
                        ('spark.driver.memory','8g')])

sc = SparkContext(conf=conf)
sql_context = SQLContext(sc)

consumer_complaints = sql_context.read.format("csv").option("header", "true").option("inferSchema", "false").load("in/Consumer_Complaints.csv")
consumer_complaints.write\
    .format("org.apache.spark.sql.cassandra")\
    .mode('append')\
    .options(table="table_name", keyspace="space_name")\
    .save()

sc.stop()
ftf50wuq

ftf50wuq1#

你好,我通过以下步骤解决了问题:
下载了twitterjsrjar并将其移动到$spark\u home/jars目录。

cp /home/jovyan/.m2/repository/com/twitter/jsr166e/1.1.0/jsr166e-1.1.0.jar /usr/local/spark/jars/

也因为docker的jupyter用户是jovyan而不是root,所以我授予这个文件夹的权限
我直接使用下面的语句,但你可以使用更严格的方式。

chmod -R 777 /usr/local/spark/jars/

谢谢您

相关问题