I have a file on my server at location
/user/data/abc.csv
I need to create a hive table on top of this data in the file. So i need to move this file to hdfs location
/user/hive/warehouse/xyz.db
How can we do that using python?
I have a file on my server at location
/user/data/abc.csv
I need to create a hive table on top of this data in the file. So i need to move this file to hdfs location
/user/hive/warehouse/xyz.db
How can we do that using python?
First you need to retrieve the file from server. Use this pyhton code to retrieve it to your local machine.
import ftplib
path = '/user/data/'
filename = 'abc.csv'
ftp = ftplib.FTP("Server IP")
ftp.login("UserName", "Password")
ftp.cwd(path)
ftp.retrbinary("RETR " + filename ,open(filename, 'wb').write) #Download the file from server to local on same path.
ftp.quit()
Once the file downloaded to local, then do usual hive query to Load data from local or put data into HDFS then load to hive.
Load data directly from local to hive:
LOAD DATA local INPATH '/user/data/abc.csv' into table <table name>;
Load data to HDFS:
hadoop fs -copyFromLocal ~/user/data/abc.csv /your/hdfs/path
then load it to hive by using hive query.
LOAD DATA INPATH '/your/hdfs/path' into table <table name>;