没有注册输出操作,因此在PySpark中无需执行任何操作

loading...


0

我试图将Spark与Kafka整合在一起 . 我有kafka消费者有json数据 . 我想用Spark来处理kafka消费者 . 当我运行以下代码错误是扔 .

bin\spark-submit --packages org.apache.spark:spark-streaming-kafka-0-8_2.11:2.0.0 test.py localhost:9092 maktest

我的test.py在下面

import sys
from pyspark import SparkContext
from pyspark.streaming import StreamingContext
from pyspark.streaming.kafka import KafkaUtils
if __name__ == "__main__":
    sc = SparkContext(appName="PythonStreamingDirectKafkaWordCount")
    ssc = StreamingContext(sc, 2)
    brokers, topic = sys.argv[1:]
    kvs = KafkaUtils.createDirectStream(ssc,[topic],{"metadata.broker.list": brokers})
    lines = kvs.map(lambda x: x[1])
    print (lines)
    ssc.start()
    ssc.awaitTermination()

我收到了以下错误

18/12/10 16:41:40 INFO VerifiableProperties: Verifying properties
18/12/10 16:41:40 INFO VerifiableProperties: Property group.id is overridden to
18/12/10 16:41:40 INFO VerifiableProperties: Property zookeeper.connect is overridden to
<pyspark.streaming.kafka.KafkaTransformedDStream object at 0x000002A6DA9FE6A0>
18/12/10 16:41:40 ERROR StreamingContext: Error starting the context, marking it as stopped
java.lang.IllegalArgumentException: requirement failed: No output operations registered, so nothing to execute
        at scala.Predef$.require(Predef.scala:224)


Traceback (most recent call last):
  File "C:/Users/maws/Desktop/spark-2.2.1-bin-hadoop2.7/test.py", line 12, in <module>
    ssc.start()

py4j.protocol.Py4JJavaError: An error occurred while calling o25.start.
: java.lang.IllegalArgumentException: requirement failed: No output operations registered, so nothing to execute

loading...

1回答

  • 1

    您没有使用受支持的Spark Streaming DStream output operation .

    对于pyspark API,您应该使用:

    pprint()
    saveAsTextFiles(prefix, [suffix])
    saveAsObjectFiles(prefix, [suffix])
    saveAsHadoopFiles(prefix, [suffix])
    foreachRDD(func)
    

    print() 不能与pyspark一起使用,因此请确保在检查Scala或Java的其他Spark Streaming示例时,更改为 pprint()

评论

暂时没有评论!