apache hive - hive sql - hive commands - hive tutorial - hadoop hive - hadoop hive - hiveql
What is hive sql - hive commands ?
- Commands are instructions, coded into SQL statements, which are used to communicate with the database to perform specific tasks, work, functions and queries with data. ...
- These Data Manipulation Language commands are: SELECT, INSERT, UPDATE, and DELETE.
--------$ hive
--------hive>
--------hive> set propkey=value;
--------hive> set –v;
--------hive> add [ARCHIVE|FILE|JAR] filename;
-------- hive> show tables;
-------- hive> describe <tablename>;
-------- hive> describe extended <tablename>;
-------- hive> show functions;
-------- hive> describe function <functionname>;
-------- hive> SELECT * FROM <tablename> LIMIT 10;
-------- hive> SELECT * FROM <tablename> WHERE freq > 100 SORT BY freq ASC LIMIT 10;
-------- CREATE TABLE foo(id INT, msg STRING);
-------- CREATE TABLE foo(id INT, msg STRING) DELIMITED FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\n’;
learn hive - hive tutorial - apache hive - Apache Hive database connectivity - hive examples
Partitioning Data
-------- CREATE TABLE foo (id INT, msg STRING)PARTITIONED BY (dt STRING);
-------- /user/hive/warehouse/foo/dt=2009-03-20/
DML OPERATIONS
Examples:--------hive> LOAD DATA LOCAL INPATH './examples/files/kv1.txt'
--------hive> OVERWRITE INTO TABLE wikitechy;
--------hive> LOAD DATA LOCAL INPATH './examples/files/kv2.txt' OVERWRITE INTO TABLE invite PARTITION (ds='2008-08-15');
--------hive> LOAD DATA LOCAL INPATH './examples/files/kv3.txt' OVERWRITE INTO TABLE invites PARTITION (ds='2008-08-08');
--------hive> LOAD DATA INPATH '/user/myname/kv2.txt';
--------hive>OVERWRITE INTO TABLE invites PARTITION (ds='2008-08-15');
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
Hive Commands
- Hive supports Data definition Language(DDL), Data Manipulation Language(DML) and User defined functions.
Hive DDL Commands
- create database
- drop database
- create table
- drop table
- Truncate table
- alter table
- create index
- create views
Create Database in Hive
- DDL command in Hive is used for creating databases.
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
Syntax
- In the above syntax for create database command, the values mentioned in square brackets [] are optional.
Drop Database in Hive
- This command is used for deleting an already created database in Hive.
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
Syntax
Alter Database Command in Hive
- The developers want to change the metadata of any of the databases, can be used alter hive DDL command.
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
Syntax
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
DDL Commands on Tables in Hive
Create Table Command in Hive
- Hive create table command is used to create a table in the existing database that is in use for a particular session.
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
Syntax
DROP Table Command in Hive
- Drops the table and all the data associated with it in the Hive metastore.
Syntax
TRUNCATE Table Command in Hive
- This hive command is used to truncate all the rows present in a table.
- It is deletes all the data from the Hive meta store and the data cannot be restored.
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
Syntax
ALTER Table Command in Hive
- To use ALTER Table command, the structure and metadata of the table can be modified even after the table has been created.
- Let us try to change the name of an existing table using the ALTER command
Syntax
Hive DML Commands
- DML (Data Manipulation Language) commands in Hive are used for inserting and querying the data from hive tables once the structure and architecture of the database has been defined using the DDL commands.
- Select
- Where
- Group By
- Order By
- Load Data
- Join
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
SELECT Table command in Hive
- · Let check whether the data has been loaded correctly by selecting the rows from Student_name.
Example
Where Table command in Hive
- A WHERE clause is used to filter the result set by using predicate operators and logical operators.
- Functions can also be used to compute the condition.
- List of Predicate Operators
- List of Logical Operators
- List of Functions
Example
GROUP BY
- Contrast this to the GROUP BY clause, which is used to group like column values into a single row.
- This is useful as it allows you to summarize information.
- For example you can use aggregate functions such as SUM and AVERAGE to calculate values.
Example
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
ORDER BY
- The ORDER BY statement is used to sort values.
Example
- It will sort the value, according to SalesOrderID.
- Every row in the table is included in the result. The values are sorted in ascending order according to the SalesOrderID.
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
LOAD DATA Statement
- The LOAD DATA statement streamlines the ETL process for an internal Impala table by moving a data file or all the data files in a directory from an HDFS location into the Impala data directory for that table.
Syntax:
- When the LOAD DATA statement operates on a partitioned table, it always operates on one partition at a time.
- Require the PARTITION clauses and list all the partition key columns, with a constant value specified for each.
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
Hive Special Commands
learn hive - hive tutorial - hive run query command - hive programs - hive examples
apache hive related article tags - hive tutorial - hadoop hive - hadoop hive - hiveql - hive hadoop - learnhive - hive sql
Hive Shell Commands
learn hive - hive tutorial - hive shell command - hive programs - hive examples