मुझे पता चला यह (here) कैसे करना है और सोचा कि यह अन्य उपयोगकर्ताओं के लिए उपयोगी है, तो यहां साझा करने हो जाएगा। take(x)
का चयन करता है पहले एक्स वस्तुओं और foreach उन्हें प्रिंट:
scala> val readmeFile = sc.textFile("input/tmp/README.md")
scala> readmeFile.take(5).foreach(println)
# Apache Spark
Spark is a fast and general cluster computing system for Big Data. It provides
high-level APIs in Scala, Java, and Python, and an optimized engine that
supports general computation graphs for data analysis. It also supports a
और ...
scala> val linesContainingSpark = readmeFile.filter(line => line.contains("Spark"))
scala> linesContainingSpark.take(5).foreach(println)
# Apache Spark
Spark is a fast and general cluster computing system for Big Data. It provides
rich set of higher-level tools including Spark SQL for SQL and structured
and Spark Streaming.
You can find the latest Spark documentation, including a programming
नीचे दिए गए उदाहरणों बराबर लेकिन का उपयोग कर pyspark हैं:
>>> readmeFile = sc.textFile("input/tmp/README.md")
>>> for line in readmeFile.take(5): print line
...
# Apache Spark
Spark is a fast and general cluster computing system for Big Data. It provides
high-level APIs in Scala, Java, and Python, and an optimized engine that
supports general computation graphs for data analysis. It also supports a
और
>>> linesContainingSpark = readmeFile.filter(lambda line: "Spark" in line)
>>> for line in linesContainingSpark.take(5): print line
...
# Apache Spark
Spark is a fast and general cluster computing system for Big Data. It provides
rich set of higher-level tools including Spark SQL for SQL and structured
and Spark Streaming.
You can find the latest Spark documentation, including a programming
स्रोत
2015-06-29 12:35:49
शायद आप पहले ही महसूस कर चुके हैं; 'ले लें (5)' वास्तव में यूनिक्स में 'हेड' की तरह होगा, और आपके द्वारा पोस्ट किए गए प्रश्न में आप जिस 'फ़िल्टर' का उपयोग कर रहे थे वह' grep' जैसा होगा। हालांकि, 'फ़िल्टर' ने आपको ऐसा कोई परिणाम नहीं दिया क्योंकि आपने उन्हें एकत्र नहीं किया था; सबसे आसान तरीका 'फ़िल्टर' के बाद 'टेक' जोड़ना होगा। – lrnzcig