1

Below error is triggered when i added the below dependency to the code,

'--packages org.apache.spark:spark-sql-kafka-0-10_2.11:2.2.0,org.apache.spark:spark-streaming-kafka-0-8-assembly_2.11:2.1.1'

Below is the code,

from pyspark.sql import SparkSession, Row
from pyspark.context import SparkContext
from kafka import KafkaConsumer
import os

os.environ['PYSPARK_SUBMIT_ARGS'] = '--packages org.apache.spark:spark-sql-kafka-0-10_2.11:2.2.0,org.apache.spark:spark-streaming-kafka-0-8-assembly_2.11:2.1.1'


sc = SparkContext.getOrCreate()
spark = SparkSession(sc)

df = spark \
  .read \
  .format("kafka") \
  .option("kafka.bootstrap.servers", "localhost:9092") \
  .option("subscribe", "Jim_Topic") \
  .load()
df.selectExpr("CAST(key AS STRING)", "CAST(value AS STRING)")

Below is the error,

Error: Missing application resource.

Usage: spark-submit [options] [app arguments] Usage: spark-submit --kill [submission ID] --master [spark://...] Usage: spark-submit --status [submission ID] --master [spark://...] Usage: spark-submit run-example [options] example-class [example args]

1 Answer 1

1

You also need to provide the name of your python file.

os.environ['PYSPARK_SUBMIT_ARGS'] = '--packages org.apache.spark:spark-sql-kafka-0-10_2.11:2.2.0,org.apache.spark:spark-streaming-kafka-0-8-assembly_2.11:2.1.1 your_python_file.py'

Alternatively, a nicer way would be:

conf = SparkConf().set("spark.jars", "/path/to/your/jar")
sc = SparkContext(conf=conf)
Sign up to request clarification or add additional context in comments.

1 Comment

I use your alternate wayby providing the path to the jars. Am getting below error To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). 20/06/12 22:32:17 ERROR SparkContext: Failed to add /C:/Hadoop/Spark/spark-3.0.0-preview2-bin-hadoop2.7/bin/ to Spark environment java.lang.IllegalArgumentException: Directory C:\Hadoop\Spark\spark-3.0.0-preview2-bin-hadoop2.7\bin is not allowed for addJar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.