Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search a table in all databases in hive

In Hive, how do we search a table by name in all databases?

I am a Teradata user. Is there any counterpart of systems tables (present in Teradata) like dbc.tables, dbc.columns which are present in HIVE?

like image 913
v83rahul Avatar asked May 24 '17 07:05

v83rahul


People also ask

How do I find tables in all Hive databases?

'Show tables' displays all the tables within Hive. Show databases displays all the database name.

How do I find a column in all tables in Hive?

select TBL_NAME, COLUMN_NAME, TYPE_NAME from TBLS left join COLUMNS_V2 on CD_ID = TBL_ID where COLUMN_NAME like 'column'; where 'column' is the column name you're looking for.

How do I see all schemas in Hive?

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.

Which command is used to display the list of tables in Hive?

Show Table Command in Hive. Gives the list of existing tables in the current database schema.


2 Answers

You can use SQL like to search a table. Example: I want to search a table with the name starting from "Benchmark" I don't know the rest of it.

Input in HIVE CLI:

show tables like 'ben*'

Output:

+-----------------------+--+
|       tab_name        |
+-----------------------+--+
| benchmark_core_month  |
| benchmark_core_qtr    |
| benchmark_core_year   |
+-----------------------+--+
3 rows selected (0.224 seconds)

Or you can try below command if you are using Beeline

!tables

Note: It will work with Beeline only (JDBC client based)

More about beeline: http://blog.cloudera.com/blog/2014/02/migrating-from-hive-cli-to-beeline-a-primer/

like image 52
Mantej Singh Avatar answered Oct 03 '22 16:10

Mantej Singh


Searching for tables with name containing infob across all Hive databases

for i in `hive -e "show schemas"`; do echo "Hive DB: $i"; hive -e "use $i; show tables"|grep "infob"; done
like image 36
ashok viswanathan Avatar answered Oct 03 '22 15:10

ashok viswanathan