In this tutorial, you'll create a Hive table, load data from a tab-delimited text file, and run a couple of basic queries against the table.
First, make sure you have downloaded the sample table. Select Tools > Attachments and right-click on
Save Link As... from the pop-up menu, select a directory to save to, then click OK. If you're working on the MapR Virtual Machine, we'll be loading the file from the MapR Virtual Machine's local file system (not the cluster storage layer), so save the file in the MapR Home directory (for example,
Take a look at the source data
First, take a look at the contents of the file using the terminal:
- Make sure you are in the Home directory where you saved
cd ~if you are not sure).
cat sample-table.txtto display the following output.
Notice that the file consists of only three lines, each of which contains a row of data fields separated by the TAB character. The data in the file represents a web log.
Create a table in Hive and load the source data:
Type the following command to start the Hive shell, using tab-completion to expand the
hive>prompt, type the following command to create the table:
Type the following command to load the data from
sample-table.txtinto the table:
Run basic queries against the table:
Try the simplest query, one that displays all the data in the table:
This query would be inadvisable with a large table, but with the small sample table it returns very quickly.
Try a simple SELECT to extract only data that matches a desired string:
This query launches a MapReduce job to filter the data.