Reputation: 6138
I'm very new with Big Data and more especially Apache Spark
/Hadoop YARN
.
I installed Hadoop single node into my virtual machine in order to make some tries and I added Spark too.
I think the environment is well-installed because I can access to :
Then I created a pythonic file which let to count words :
from pyspark import SparkConf, SparkContext
from operator import add
import sys
## Constants
APP_NAME = " HelloWorld of Big Data"
##OTHER FUNCTIONS/CLASSES
def main(sc,filename):
textRDD = sc.textFile(filename)
words = textRDD.flatMap(lambda x: x.split(' ')).map(lambda x: (x, 1))
wordcount = words.reduceByKey(add).collect()
for wc in wordcount:
print wc[0],wc[1]
if __name__ == "__main__":
# Configure Spark
conf = SparkConf().setAppName(APP_NAME)
conf = conf.setMaster("local[*]")
sc = SparkContext(conf=conf)
filename = sys.argv[1]
# Execute Main functionality
main(sc, filename)
I have a textfile too named data.txt. I upload this file to HDFS with :
hadoop fs -put data.txt hdfs://localhost:9000
My file is located on : hdfs://localhost:9000/user/hduser
So I would like to execute my pythonic script thanks to Spark/Hadoop.
I made : ./bin/spark-submit /home/hduser/count.py /home/hduser/data.txt
But I get :
Traceback (most recent call last):
File "/home/hduser/count.py", line 25, in <module>
main(sc, filename)
File "/home/hduser/count.py", line 13, in main
wordcount = words.reduceByKey(add).collect()
File "/usr/local/spark/python/lib/pyspark.zip/pyspark/rdd.py", line 1623, in reduceByKey
File "/usr/local/spark/python/lib/pyspark.zip/pyspark/rdd.py", line 1849, in combineByKey
File "/usr/local/spark/python/lib/pyspark.zip/pyspark/rdd.py", line 2259, in _defaultReducePartitions
File "/usr/local/spark/python/lib/pyspark.zip/pyspark/rdd.py", line 2455, in getNumPartitions
File "/usr/local/spark/python/lib/py4j-0.10.6-src.zip/py4j/java_gateway.py", line 1160, in __call__
File "/usr/local/spark/python/lib/py4j-0.10.6-src.zip/py4j/protocol.py", line 320, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o21.partitions.
: org.apache.hadoop.mapred.InvalidInputException: Input path does not exist: hdfs://localhost:9000/home/hduser/data.txt
at org.apache.hadoop.mapred.FileInputFormat.singleThreadedListStatus(FileInputFormat.java:285)
at org.apache.hadoop.mapred.FileInputFormat.listStatus(FileInputFormat.java:228)
at org.apache.hadoop.mapred.FileInputFormat.getSplits(FileInputFormat.java:313)
at org.apache.spark.rdd.HadoopRDD.getPartitions(HadoopRDD.scala:200)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:253)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:251)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.spark.rdd.RDD.partitions(RDD.scala:251)
at org.apache.spark.rdd.MapPartitionsRDD.getPartitions(MapPartitionsRDD.scala:35)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:253)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:251)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.spark.rdd.RDD.partitions(RDD.scala:251)
at org.apache.spark.api.java.JavaRDDLike$class.partitions(JavaRDDLike.scala:61)
at org.apache.spark.api.java.AbstractJavaRDDLike.partitions(JavaRDDLike.scala:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:214)
at java.lang.Thread.run(Thread.java:748)
It's pretty strange because my data.txt file is into HDFS but I have this issue : Input path does not exist: hdfs://localhost:9000/home/hduser/data.txt
Any idea ?
Upvotes: 0
Views: 154
Reputation: 561
Ensure HADOOP_HOME and SPARK_HOME path variable is set in your spark-env.sh. So that you can perform I/O operations with HDFS and submit jobs to YARN cluster.
Upvotes: 0
Reputation: 1360
Your URL is not valid. There is no home
folder in HDFS. Try this instead:
./bin/spark-submit /home/hduser/count.py /user/hduser/data.txt
Upvotes: 1