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 :

  1. Open the Hive command line or Hue (Hive user interface).
  2. Create a database table internally (if it does not already exist):
CREATE DATABASE IF NOT EXISTS your_database_name;
  1. Switch to the required database:
USE your_database_name;
  1. 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.).

  1. There are several options to import data into the internal table.
  2. Import data from a local file.
  3. Import the data file located at ‘/path/to/your/data/file’ into the table named your_table_name.
  4. In the code above, “/path/to/your/data/file” is the local file path that contains the data you want to import.
  5. Importing data from HDFS.
  6. Upload the data file located at ‘/path/to/your/data/file’ into the table named your_table_name.
  7. In the code above, “/path/to/your/data/file” is the HDFS file path that contains the data you want to import.
  8. c. Enter data:
  9. Add the specified values to your_table_name in the database.
  10. 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.

bannerAds