How to create an internal table and import data in Hive?
You can follow these steps to create an internal table and import data into Hive :
- Open the Hive command line or Hue (Hive user interface).
- Create a database table internally (if it does not already exist):
CREATE DATABASE IF NOT EXISTS your_database_name;
- Switch to the required database:
USE your_database_name;
- Create an internal table and specify its structure.
CREATE TABLE your_table_name (
column1 data_type,
column2 data_type,
...
) STORED AS file_format;
In the above code, ‘your_table_name’ is the name of the table you wish to create, ‘column1, column2, …’ are the column names in the table, ‘data_type’ is the data type of each column (such as INT, STRING, etc.), and ‘file_format’ is the storage format of the table (such as TEXTFILE, PARQUET, etc.).
- There are several options to import data into the internal table.
- Import data from a local file.
- Import the data file located at ‘/path/to/your/data/file’ into the table named your_table_name.
- In the code above, “/path/to/your/data/file” is the local file path that contains the data you want to import.
- Importing data from HDFS.
- Upload the data file located at ‘/path/to/your/data/file’ into the table named your_table_name.
- In the code above, “/path/to/your/data/file” is the HDFS file path that contains the data you want to import.
- c. Enter data:
- Add the specified values to your_table_name in the database.
- In the code above, value1, value2, … are the values of the data you want to insert.
Please choose the appropriate method to import data into the internal table based on your specific needs.