-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-6027][SPARK-5546] Fixed --jar and --packages not working for KafkaUtils and improved error message #4779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ | |
| # | ||
|
|
||
| from py4j.java_collections import MapConverter | ||
| from py4j.java_gateway import java_import, Py4JError | ||
| from py4j.java_gateway import java_import, Py4JError, Py4JJavaError | ||
|
|
||
| from pyspark.storagelevel import StorageLevel | ||
| from pyspark.serializers import PairDeserializer, NoOpSerializer | ||
|
|
@@ -50,8 +50,6 @@ def createStream(ssc, zkQuorum, groupId, topics, kafkaParams={}, | |
| :param valueDecoder: A function used to decode value (default is utf8_decoder) | ||
| :return: A DStream object | ||
| """ | ||
| java_import(ssc._jvm, "org.apache.spark.streaming.kafka.KafkaUtils") | ||
|
|
||
| kafkaParams.update({ | ||
| "zookeeper.connect": zkQuorum, | ||
| "group.id": groupId, | ||
|
|
@@ -63,20 +61,34 @@ def createStream(ssc, zkQuorum, groupId, topics, kafkaParams={}, | |
| jparam = MapConverter().convert(kafkaParams, ssc.sparkContext._gateway._gateway_client) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove java_import() |
||
| jlevel = ssc._sc._getJavaStorageLevel(storageLevel) | ||
|
|
||
| def getClassByName(name): | ||
| return ssc._jvm.org.apache.spark.util.Utils.classForName(name) | ||
|
|
||
| try: | ||
| array = getClassByName("[B") | ||
| decoder = getClassByName("kafka.serializer.DefaultDecoder") | ||
| jstream = ssc._jvm.KafkaUtils.createStream(ssc._jssc, array, array, decoder, decoder, | ||
| jparam, jtopics, jlevel) | ||
| except Py4JError, e: | ||
| # Use KafkaUtilsPythonHelper to access Scala's KafkaUtils (see SPARK-6027) | ||
| helperClass = ssc._jvm.java.lang.Thread.currentThread().getContextClassLoader()\ | ||
| .loadClass("org.apache.spark.streaming.kafka.KafkaUtilsPythonHelper") | ||
| helper = helperClass.newInstance() | ||
| jstream = helper.createStream(ssc._jssc, jparam, jtopics, jlevel) | ||
| except Py4JJavaError, e: | ||
| # TODO: use --jar once it also work on driver | ||
| if not e.message or 'call a package' in e.message: | ||
| print "No kafka package, please put the assembly jar into classpath:" | ||
| print " $ bin/spark-submit --driver-class-path external/kafka-assembly/target/" + \ | ||
| "scala-*/spark-streaming-kafka-assembly-*.jar" | ||
| if 'ClassNotFoundException' in str(e.java_exception): | ||
| print """ | ||
| ________________________________________________________________________________________________ | ||
|
|
||
| Spark Streaming's Kafka libraries not found in class path. Try one of the following. | ||
|
|
||
| 1. Include the Kafka library and its dependencies with in the | ||
| spark-submit command as | ||
|
|
||
| $ bin/spark-submit --packages org.apache.spark:spark-streaming-kafka:%s ... | ||
|
|
||
| 2. Download the JAR of the artifact from Maven Central http://search.maven.org/, | ||
| Group Id = org.apache.spark, Artifact Id = spark-streaming-kafka-assembly, Version = %s. | ||
| Then, innclude the jar in the spark-submit command as | ||
|
|
||
| $ bin/spark-submit --jars <spark-streaming-kafka-assembly.jar> ... | ||
|
|
||
| ________________________________________________________________________________________________ | ||
|
|
||
| """ % (ssc.sparkContext.version, ssc.sparkContext.version) | ||
| raise e | ||
| ser = PairDeserializer(NoOpSerializer(), NoOpSerializer()) | ||
| stream = DStream(jstream, ssc, ser) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it still work if this is strictly
private? Just wonderingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if I will be able to call from python if this is strictly private. I havent tested it though. I dont think that;s a big deal, as long as its hidden from public view