Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read the file from hdfs [duplicate]

I have a text file name mr.txt in the hadoop file sytem under /project1 directory. I need to write the python code to read the first line of the text file without downloading mr.txt file into local. But I have trouble to open the mr.txt file from hdfs. I had tried:

open('hdfs:///project1/mr.txt','r') 
like image 295
gd1 Avatar asked Sep 19 '25 04:09

gd1


1 Answers

Get PySpark installed.

text = sc.textFile('hdfs:///project1/mr.txt')
first_line = text.first()
like image 83
OneCricketeer Avatar answered Sep 22 '25 02:09

OneCricketeer