Populating the Sample Table with Test Data
Now that we have created the "sample_table" in the "sample_db" database, let's populate it with some test data.
Inserting Data Manually
You can insert data into the table manually using the INSERT INTO
statement in the Hive CLI. For example:
INSERT INTO sample_table VALUES (1, 'John Doe', 35, 'Male');
INSERT INTO sample_table VALUES (2, 'Jane Smith', 28, 'Female');
INSERT INTO sample_table VALUES (3, 'Bob Johnson', 42, 'Male');
This will add three rows of data to the "sample_table".
Inserting Data from a File
Alternatively, you can load data from a file into the table. First, create a file named "sample_data.txt" with the following content:
4,Alice Williams,31,Female
5,Michael Brown,27,Male
6,Sarah Davis,39,Female
Then, you can use the LOAD DATA LOCAL INPATH
statement to load the data from the file into the table:
LOAD DATA LOCAL INPATH '/path/to/sample_data.txt' INTO TABLE sample_table;
Replace /path/to/sample_data.txt
with the actual path to the file on your system.
Verifying the Data
You can verify that the data has been inserted correctly by running a SELECT
query:
SELECT * FROM sample_table;
This will display all the rows in the "sample_table".
Now that you have populated the sample table, you can start testing conditional functions and other Hive features using this data.