Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: add links to Authorization doc

...

In Hive 0.7.0 or later, DROP returns an error if the function doesn't exist, unless IF EXISTS is specified or the configuration variable hive.exec.drop.ignorenonexistent is set to true.

Create/Drop/Grant/Revoke Roles and Privileges

The Authorization document has information about these DDL statements:

Show

Table of Content Zone
maxLevel5
locationtop
typelist

These statements provide a way to query the Hive metastore for existing data and metadata accessible to this Hive system.

Show Databases

Code Block
SHOW (DATABASES|SCHEMAS) [LIKE identifier_with_wildcards];

SHOW DATABASES lists all of the databases defined in the metastore. The optional LIKE clause allows the list of databases to be filtered using a regular expression. Wildcards in the regular expression can only be '' for any character(s) or '|' for a choice. Examples are 'employees', 'emp', 'emp*|*ees', all of which will match the database named 'employees'.

Show Tables/Partitions/Indexes

Show Tables

Code Block
SHOW TABLES [IN database_name] [identifier_with_wildcards];

SHOW TABLES lists all the base tables and views in the current database (or the one explicitly named using the IN clause) with names matching the optional regular expression. Wildcards in the regular expression can only be '' for any character(s) or '|' for a choice. Examples are 'page_view', 'page_v', 'view|page', all which will match the 'page_view' table. Matching tables are listed in alphabetical order. It is not an error if there are no matching tables found in metastore. If no regular expression is given then all tables in the selected database are listed.

Show Partitions

Code Block
SHOW PARTITIONS table_name

SHOW PARTITIONS lists all the existing partitions for a given base table. Partitions are listed in alphabetical order.

Info
titleVersion information

As of Hive 0.6, SHOW PARTITIONS can filter the list of partitions as shown below.

It is also possible to specify parts of a partition specification to filter the resulting list. For example:

Code Block
SHOW PARTITIONS table_name PARTITION(ds='2010-03-03');            (Hive 0.6 and later)
SHOW PARTITIONS table_name PARTITION(hr='12');                    (Hive 0.6 and later)
SHOW PARTITIONS table_name PARTITION(ds='2010-03-03', hr='12');   (Hive 0.6 and later)
Info
titleVersion information

Starting with Hive 0.13.0, SHOW PARTITIONS can specify a database (HIVE-5912).

Code Block
SHOW PARTITIONS [db_name.]table_name [PARTITION(partition_desc)]            (Hive 0.13.0 and later)

Example:

Code Block
SHOW PARTITIONS databaseFoo.tableBar PARTITION(ds='2010-03-03', hr='12');   (Hive 0.13.0 and later)

Show Tables/Partitions Extended

Code Block
SHOW TABLE EXTENDED [IN|FROM database_name] LIKE identifier_with_wildcards [PARTITION(partition_desc)]

SHOW TABLE EXTENDED will list information for all tables matching the given regular expression. Users cannot use regular expression for table name if a partition specification is present. This command's output includes basic table information and file system information like totalNumberFiles, totalFileSize, maxFileSize, minFileSize,lastAccessTime, and lastUpdateTime. If partition is present, it will output the given partition's file system information instead of table's file system information.

Show Table Properties

Info
titleVersion information

As of Hive 0.10.0

Code Block
SHOW TBLPROPERTIES tblname;
SHOW TBLPROPERTIES tblname("foo");

The first form lists all of the table properties for the table in question one per row separated by tabs. The second form of the command prints only the value for the property that's being asked for.

Show Create Table

Info
titleVersion information

As of Hive 0.10

Code Block
SHOW CREATE TABLE ([db_name.]table_name|view_name)

SHOW CREATE TABLE shows the CREATE TABLE statement that creates a given table, or the CREATE VIEW statement that creates a given view.

Show Indexes

Info
titleVersion information

As of Hive 0.7

Code Block
SHOW [FORMATTED] (INDEX|INDEXES) ON table_with_index [(FROM|IN) db_name]

SHOW INDEXES shows all of the indexes on a certain column, as well as information about them: index name, table name, names of the columns used as keys, index table name, index type, and comment. If the FORMATTED keyword is used, then column titles are printed for each column.

Show Columns

Info
titleVersion information

As of Hive 0.10

Code Block
SHOW COLUMNS (FROM|IN) table_name [(FROM|IN) db_name]

SHOW COLUMNS shows all the columns in a table including partition columns.

Show Functions

Code Block
SHOW FUNCTIONS "a.*"

SHOW FUNCTIONS lists all the user defined and builtin functions matching the regular expression. To get all functions use ".*"

Show Granted Roles and Privileges

The Authorization document has information about these SHOW statements:

Describe

Table of Content Zone
maxLevel4
locationtop
typelist

Describe Database

Info
titleVersion information

As of Hive 0.7

Code Block
DESCRIBE DATABASE db_name

DESCRIBE DATABASE shows the name of the database, its comment (if one has been set), and its root location on the filesystem.

Describe Table/View/Column

Code Block
DESCRIBE [EXTENDED|FORMATTED] [db_name.]table_name[DOT col_name ( [DOT field_name] | [DOT '$elem$'] | [DOT '$key$'] | [DOT '$value$'] )* ]

DESCRIBE shows the list of columns including partition columns for the given table. If the EXTENDED keyword is specified then it will show all the metadata for the table in Thrift serialized form. This is generally only useful for debugging and not for general use. If the FORMATTED keyword is specified, then it will show the metadata in a tabular format.

If a table has complex column then you can examine the attributes of this column by specifying table_name.complex_col_name (and '$elem$' for array element, '$key$' for map key, and '$value$' for map value). You can specify this recursively to explore the complex column type.

For a view, DESCRIBE EXTENDED or FORMATTED can be used to retrieve the view's definition. Two relevant attributes are provided: both the original view definition as specified by the user, and an expanded definition used internally by Hive.

Describe Partition

Code Block
DESCRIBE [EXTENDED|FORMATTED] [db_name.]table_name PARTITION partition_spec

This statement lists metadata for a given partition. The output is similar to that of DESCRIBE table_name. Presently, the column information associated with a particular partition is not used while preparing plans.

Example:

Code Block
DESCRIBE page_view PARTITION (ds='2008-08-08');

...