CREATE TABLE statement is used to create a new HIVE table.
The following SQL statement creates a table called "Employee":
Let us suppose we have a file named 'employee.csv' in HDFS in '/data/employee.csv' location.The sample file is displayed below:
employee.csv
Csv files are comma separated files. As you can see above emp_id, name, city, salary are the headers and just below are the values. And as the name suggests (Comma separated values), all the values are separated by commas.
Now, when we are creating a table with the CREATE command, we will be telling HIVE the exact location of the 'employee.csv' file. And HIVE will intelligently map the table with the 'employee.csv' file.
The CREATE command is listed below:
The EXTERNAL keyword in the CREATE command says the table is an external table and the 'location' keyword mentions the path of the external file(/data/employee.csv). Most importantly the 'row format delimited' statement tells HIVE that every element of 'employee.csv' is separated by ','.
When we trigger a select query, HIVE will return the same values in the form of a table.
emp_id | name | city | salary |
---|---|---|---|
101 | John | California | 50000 |
102 | Tom | Mumbai | 40000 |
103 | Harry | Delhi | 80000 |
104 | Rahul | Bangalore | 60000 |
105 | Sakil | Delhi | 90000 |