"error"という語を含む行を持つログファイルがあります。どのように私はapache sparkでこの用語を含む行の総数を数えますか?Spark Count特定の単語を含む行の数
これまでのところ私はこのアプローチを使用しています。
from pyspark import SparkConf, SparkContext
conf = SparkConf().setMaster("local").setAppName("WordCount")
sc = SparkContext(conf = conf)
input = sc.textFile("errors.txt")
words = input.flatMap(lambda x: x for x if "errors" in input)
wordCounts = input.countByValue()
for word, count in wordCounts.items():
print str(count)
しかし、この方法は機能しません。誰が私にカウントを取得する方法を教えてもらえますか?
編集:Scalaでは等価は、この行のPythonの同等であるものを
lines = spark.textFile("hdfs://...")
errors = lines.filter(_.startsWith("ERROR"))
errors.persist()
です。
'rdd.count'が – philantrovert