TP : HIVE
The Prerequisites :
Java and hadoop should be already installed (from the tp1)
You have a fully functional Hadoop installation on the server
Switch to user hadoop using # su hadoop
Step-by-Step Setup :
1. Download and Install Hive:
Once Hadoop is up and running, you can install Apache Hive. The first step of
the process is to run this command to download the Hive binaries :
# sudo apt update
# sudo wget [Link]
[Link]
extract the downloaded files using the following command:
# tar -xzf [Link]
copy the extracted Hive directory to a suitable location
# sudo mv apache-hive-4.0.0-bin /opt/hive
# sudo chown -R hadoop:hadoop /opt/hive
2 . Configure Hive in .bashrc: Open the ~/.bashrc file and add the Hive
environment variables:
Add the following lines at the end of the file and save it
# export HIVE_HOME=/opt/hive
# export PATH=$PATH:$HIVE_HOME/bin
3 . Apply the changes to the current session and verify that Hive has been set
up correctly:
# source ~/.bashrc
# echo $HIVE_HOME
# echo $PATH
[Link] and start Hive
Initialize the Hive schema using Derby
# schematool -dbType derby -initSchema
Start Hive: Run the Hive command to start the Hive shell:
# hive
Working with Hive Tables :
[Link] beeline to connect to Derby and perform database operations:
Open Beeline and connect to the default embedded Derby metastore:
# beeline
Connect to the Derby metastore:
# !connect jdbc:derby:metastore_db;create=true
Create a table in Hive:
# CREATE TABLE test_table (id INT, name VARCHAR(255));
Insert data into the table:
# INSERT INTO test_table VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Charlie'),
(4, 'Hannah');
Select all data from the table:
# SELECT * FROM test_table;
Update a record in the table:
# UPDATE test_table SET name = 'Alice Smith' WHERE id = 1;
Delete a record from the table:
# DELETE FROM test_table WHERE id = 3;
Select specific records based on a condition:
# SELECT * FROM test_table WHERE id > 1;
Verify the existence of the table in the system catalog:
# SELECT * FROM [Link] WHERE TABLENAME =
'TEST_TABLE';
Exit :
# !quit
END