how do I get - only count of tables from a database as output - only count of columns from a table as output
how do I get - only count of tables from a database as output - only count of columns from a table as output
You can get this information from the metastore database:
hive=> SELECT "TBL_NAME", "COLUMN_NAME", "TYPE_NAME" FROM "TBLS" , "COLUMNS_V2" WHERE "TBL_ID"="CD_ID" UNION SELECT "TBL_NAME", "PKEY_NAME", "PKEY_TYPE" FROM "PARTITION_KEYS" p , "TBLS" t WHERE p."TBL_ID"=t."TBL_ID" ORDER BY "TBL_NAME";
TBL_NAME | COLUMN_NAME | TYPE_NAME
------------+-------------+-----------
tableA | aaa | string
tableA | bbb | string
tableB | foo | string
tableB | bar | int
tableC | cola | string
tableD | colb | string
(6 rows)
Let me know if this helps.
hive> select count(column_name) as NoOfColumns from information_schema.columns where table_name= "TableName";
hive> select count(table_name) as NoOfTables from information_schema.tables;
for more details: click here