Hive - Saving Data




Not able to play video? Try with youtube

Important Note - We recommend you to execute the given commands on Hive Console instead of Hue. The video is only for representational purposes.

We can save data from Hive tables or queries to the local file system as well as to HDFS. Let's save CMC stock data from nyse table to onlycmc file in the local file system. Login to CloudxLab Linux console and launch hive shell.

Select your database and type insert overwrite local directory '/home/your-user-name/onlycmc' select * from nyse where symbol1 = 'CMC';. Press enter. Quit hive shell and type "tail onlycmc/000000_0" to see the CMC stock data.

Now save the CMC stock data in onlycmc file in your home directory in HDFS. Open Hive query editor in Hue. Type command insert overwrite directory 'onlycmc' select * from nyse where symbol1 = 'CMC';.

Click on execute. To see the data, go to the file browser, navigate to your home directory in HDFS and see if onlycmc file exists.

INSTRUCTIONS

Steps:

  • Login to the web console
  • Launch Hive with typing in hive on the console. Run below commands in Hive.
  • Use your database by using the below command. ${env:USER} gets replaced by your username automatically:

    use ${env:USER};
    
  • To save the data in the local file system

    insert overwrite local directory '/home/${env:USER}/onlycmc'
    select * from nyse where symbol1 = 'CMC';
    
  • To view this data type in the following commands (Run in the web console)

     tail onlycmc/000000_0
    
  • To save data in HDFS (Run in Hive)

    insert overwrite directory 'onlycmc' select * from nyse where
    symbol1 = 'CMC';
    

Loading comments...