Saturday, 5 August 2017

3)Hive CLI and SHELL Commands information

Hive CLI and SHELL Commands information:

SQL QUERIES USAGE AND SYNTAX:
Function
My SQL
Hive QL
Retrieving information
SELECT from_columns FROM table WHERE conditions;
SELECT from_columns FROM table WHERE conditions;
All values
SELECT * FROM table;
SELECT * FROM table;
Some values
SELECT * FROM table WHERE rec_name = “value”;
SELECT * FROM table WHERE rec_name = "value";
Multiple criteria
SELECT * FROM table WHERE rec1=”value1” AND rec2=”value2”;
SELECT * FROM TABLE WHERE rec1 = "value1" AND
rec2 = "value2";
Selecting specific columns
SELECT column_name FROM table;
SELECT column_name FROM table;
Retrieving unique output records
SELECT DISTINCT column_name FROM table;
SELECT DISTINCT column_name FROM table;
Sorting
SELECT col1, col2 FROM table ORDER BY col2;
SELECT col1, col2 FROM table ORDER BY col2;
Sorting backward
SELECT col1, col2 FROM table ORDER BY col2 DESC;
SELECT col1, col2 FROM table ORDER BY col2 DESC;
Counting rows
SELECT COUNT(*) FROM table;
SELECT COUNT(*) FROM table;
Grouping with counting
SELECT owner, COUNT(*) FROM table GROUP BY owner;
SELECT owner, COUNT(*) FROM table GROUP BY owner;
Maximum value
SELECT MAX(col_name) AS label FROM table;
SELECT MAX(col_name) AS label FROM table;
Selecting from multiple tables (Join same table using alias w/”AS”)
SELECT pet.name, comment FROM pet, event WHERE pet.name = event.name;
SELECT pet.name, comment FROM pet JOIN event ON (pet.name = event.name);



Hive Tables Metadata:

Function
My SQL
Hive QL
Selecting a database
USE database;
USE database;
Listing databases
SHOW DATABASES;
SHOW DATABASES;
Listing tables in a database
SHOW TABLES;
SHOW TABLES;
Describing the format of a table
DESCRIBE table;
DESCRIBE (FORMATTED|EXTENDED) table;
Creating a database
CREATE DATABASE db_name;
CREATE DATABASE db_name;
Dropping a database
DROP DATABASE db_name;
DROP DATABASE db_name (CASCADE);

CLI(Command Line) Options:

usage: hive -H
 -d,--define <key=value>          Variable substitution to apply to Hive
                                  commands. e.g. -d A=B or --define A=B
 -e <quoted-query-string>         SQL from command line
 -f <filename>                    SQL from files
 -H,--help                        Print help information
 -h <hostname>                    Connecting to Hive Server on remote host
    --hiveconf <property=value>   Use value for given property
    --hivevar <key=value>         Variable substitution to apply to hive
                                  commands. e.g. --hivevar A=B
 -i <filename>                    Initialization SQL file
 -p <port>                        Connecting to Hive Server on port number
 -S,--silent                      Silent mode in interactive shell
 -v,--verbose                     Verbose mode (echo executed SQL to the
                                  console)

Function
Hive
Run query
hive ‐e 'select a.col from tab1 a'
Run query silent mode
hive ‐S ‐e 'select a.col from tab1 a'
Set hive config variables
hive ‐e 'select a.col from tab1 a' ‐hiveconf hive.root.logger=DEBUG,console
Use initialization script
hive ‐i initialize.sql
Run non-interactive script
hive ‐f script.sql

HIVE shell Options:

Function
Hive
Run script inside shell
source file_name
Run ls (dfs) commands
dfs –ls /user
Run ls (bash command) from shell
!ls
Set configuration variables
set mapred.reduce.tasks=32
TAB auto completion
set hive.<TAB>
Show all variables starting with hive
set
Revert all variables
reset
Add jar to distributed cache
add jar jar_path
Show all jars in distributed cache
list jars
Delete jar from distributed cache
delete jar jar_name
Note: 
! <command>
Executes a shell command from the Hive shell.

No comments:

Post a Comment

Fundamentals of Python programming

Fundamentals of Python programming: Following below are the fundamental constructs of Python programming: Python Data types Python...