1

When I run the create external table query, I have to provide a directory for the 'Location' attribute. But if the directory I point to has more than one file, then it reads both files. For example, if I put LOCATION 'dir1/', and dir1 contains file1 and file2, both files will be read.

To avoid this, I want to point to a single file. When I tried LOCATION 'dir1/file1', it gave me an error that the file path is not a directory or unable to create one. Is there a way to point to just the single file?

covfefe
  • 2,485
  • 8
  • 47
  • 77
  • is there an extension/file type for `file1`? If so, you should declare it. – Vamsi Prabhala Oct 04 '16 at 14:02
  • 3
    Possible duplicate of [when creating an external table in hive can I point the location to specific files in a direcotry?](http://stackoverflow.com/questions/11269203/when-creating-an-external-table-in-hive-can-i-point-the-location-to-specific-fil) – Sandesh Jain Oct 04 '16 at 14:05

1 Answers1

0

If You want to load data from HDFS so try this

LOAD DATA INPATH '/user/data/file1' INTO TABLE table1;

And if you want to load data from local storage so,

LOAD DATA LOCAL INPATH '/data/file1' INTO TABLE table1;
Sahil Desai
  • 3,418
  • 4
  • 20
  • 41