0
votes

Hi am loading some files data from hdfs location to hive table using load commnad.

    Load data inpath 'hdfspath/filename' into table tablename.

But after loading data into hive table data is moving to some other location but i dont want to move my source file from location is there any way to keep the data at same location after loading also

1

1 Answers

0
votes

@PriyaBanerjee It seems like you are describing creating a native hive table from the path. My advice would be to create an External Table on the path. This will retain the location for the data.

Here is an example:

CREATE EXTERNAL TABLE IF NOT EXISTS Cars(
    Name STRING,
    Miles_per_Gallon INT,
    Cylinders INT,
    Displacement INT,
    Horsepower INT,
    Weight_in_lbs INT,
    Acceleration DECIMAL,
    Year DATE,
    Origin CHAR(1))
COMMENT 'Data about cars from a public database'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS TEXTFILE
location '/user/<username>/visdata';

You would just need to adjust the statement to fit your data source. If you already have the table in hive, you can run show create table on the existing table to get the schema. Then just adjust top line to CREATE EXTERNAL and the bottom line to the hdfs path.