Common Hive SQL syntax summary

  Hive is a data warehouse based application tool for processing structured data in Hadoop, operate on data through SQL-language. Hive convert the sql statement submitted by the parser into MapReduce jobs on Hadoop cluster, Hadoop monitoring during job execution, and the results returned to the user.

  It is noteworthy that, Hive and support update row-level data, mainly using the occasion as a batch job large data sets.

  SUMMARY The following '[]' is determined according to the actual needs either to write Hive commonly used in SQL statements.

- Create a database 
the Create  Database name; 

- Common display commands 
show Databases; - what database Access to 
show the Tables;   - view the current database under which tables 
show the Tables like  ' * CC * '   - regular expression shown in the table 
show partitions;   - view the partition 
Show Functions; 
DESCRIBE Extended table_name;     - view the table of the structure, the fields, partition, etc. 

- construction of the table statement to 
the create  [ External ]  the table  [ IF not EXISTS ] table_name    - create a table, specify the table name, The default is an internal table 
[(col_name data_type [the Comment col_comment ] , ...)]   - create field, specify the field type, annotation 
[ the Comment table_comment ]   - Table of Notes 
[ Partitioned by (col_name data_type [the Comment col_comment ] , col_name_2 data_type_2, ...) ] - specify the partition, pay attention to the fields to build the table of partition field can not appear in 
[ clustered by (col_name, col_name_2, ...) ]  [ sorted by (col_name [ASC | DESC ] , ...)] INTO num_buckets buckets ] - sub-barrel 
[ Row ROW_FORMAT the format ] 
[ stored AS FILE_FORMAT ]   - specifies the storage file type 
[hdfs_path LOCATION ]   - storage path 

· External create a table showing whether the external table, the default is the inner table
 · IF  not  EXISTS represents the creation of the table when the table does not exist, or ignore the exception
 · the Comment table, add comments field
 · ROW_FORMAT 
    Row DELIMITED format [ Fields terminated by char ] 
                         [ Collection items terminated by char ] 
                         [ the Map Keys terminated by char ] 
                         [ Lines terminated by char ] 
· FILE_FORMAT 
   the Stored AS textfile   - plain text data 
   the Stored AS SequenceFile   -Data compression is needed to save storage space 

- like keyword copy table structure 
the Create  the Table table_name like old_table_name;          

- change the name of the table 
the ALTER  the Table table_name the rename to new_table_name; 

- add a field and add comments to 
the ALTER  the Table table_name the Add the Columns ( col_name data_type the Comment ' col_comment ' ); 

- delete column 
alter  Table table_name Replace columns ( col_name data_type, col_name_2 data_type_2); 

- add, delete partitions 
alter table table_name add [if not exists] partition_name;  -- 增加
alter table table_name drop partition_name, partition_name_2;   -- 删除

 

- inserting data 
INSERT  INTO table_1 SELECT  *  from table_2;   - additional data after table_1 
INSERT Overwrite table_1 SELECT  *  from table_2;   - first data table_1 empty, then add data 

- to extract data common statement 
SELECT  [ DISTINCT ] select_expr_1 , select_expr_2
 from table_name
 [ WHERE for condition condition ]    - filters 
[ Group by col_list [HAVING for condition condition ] ]   - packet, the return packet condition 
[ Order by col_list ]  - sorting 
[ limit NUM_1, NUM_2 ]    - the number of records (NUM_2) returns the data start (NUM_1) position and back data

 

Guess you like

Origin www.cnblogs.com/beyondChan/p/11409134.html