<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Query to find the count of columns for all tables in impala in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Query-to-find-the-count-of-columns-for-all-tables-in-impala/m-p/337498#M232597</link>
    <description>&lt;P&gt;I am trying to fetch a count of total columns for a list of individual tables/views from Impala from the same schema.&lt;/P&gt;
&lt;P&gt;however i wanted to scan through all the tables from that schema to capture the counts of columns of all the tables in a single query ?&lt;/P&gt;
&lt;P&gt;i have already performed a similar exercise from Oracle Exa data ,however since i a new to Impala is there a way to capture all the tables in a single query ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Exadata query for reference&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;# Oracle Exadata query i used&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;select owner, table_name as view_name, count(*) as counts
from dba_tab_cols /*DBA_TABLES_COLUMNS*/
where (owner, table_name) in
(
select owner, view_name
from dba_views /*DBA_VIEWS*/
where 1=1
and owner='DESIRED_SCHEMA_NAME'
)
group by owner ,table_name
order by counts desc;

impala /hive

DESCRIBE schemaName.tableName;

&lt;/LI-CODE&gt;
&lt;P&gt;# Impala /Hive&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how to find out ? if i need to run a single query check i was following the below&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for multiple tables/view how to find out the total column counts ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2022 21:34:10 GMT</pubDate>
    <dc:creator>bdworld2</dc:creator>
    <dc:date>2022-03-02T21:34:10Z</dc:date>
    <item>
      <title>Query to find the count of columns for all tables in impala</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Query-to-find-the-count-of-columns-for-all-tables-in-impala/m-p/337498#M232597</link>
      <description>&lt;P&gt;I am trying to fetch a count of total columns for a list of individual tables/views from Impala from the same schema.&lt;/P&gt;
&lt;P&gt;however i wanted to scan through all the tables from that schema to capture the counts of columns of all the tables in a single query ?&lt;/P&gt;
&lt;P&gt;i have already performed a similar exercise from Oracle Exa data ,however since i a new to Impala is there a way to capture all the tables in a single query ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Exadata query for reference&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;# Oracle Exadata query i used&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;select owner, table_name as view_name, count(*) as counts
from dba_tab_cols /*DBA_TABLES_COLUMNS*/
where (owner, table_name) in
(
select owner, view_name
from dba_views /*DBA_VIEWS*/
where 1=1
and owner='DESIRED_SCHEMA_NAME'
)
group by owner ,table_name
order by counts desc;

impala /hive

DESCRIBE schemaName.tableName;

&lt;/LI-CODE&gt;
&lt;P&gt;# Impala /Hive&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how to find out ? if i need to run a single query check i was following the below&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for multiple tables/view how to find out the total column counts ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 21:34:10 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Query-to-find-the-count-of-columns-for-all-tables-in-impala/m-p/337498#M232597</guid>
      <dc:creator>bdworld2</dc:creator>
      <dc:date>2022-03-02T21:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Query to find the count of columns for all tables in impala</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Query-to-find-the-count-of-columns-for-all-tables-in-impala/m-p/379310#M243828</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Hive, metadata related to tables and columns is typically stored in the 'hive' database, specifically within the 'TBLS' and 'COLUMNS_V2' tables in the 'metastore' database. It is not recommended for users to query the metadata directly. Instead, users can leverage the 'sys' database tables.&lt;/P&gt;&lt;P&gt;Here is a modified query that utilizes the 'hive' database tables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="bg-black rounded-md"&gt;&lt;DIV class="flex items-center relative text-gray-200 bg-gray-800 gizmo:dark:bg-token-surface-primary px-4 py-2 text-xs font-sans justify-between rounded-t-md"&gt;&lt;SPAN&gt;&lt;SPAN&gt;sql&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;USE sys;

-- Get the count of columns for all tables 
SELECT
  t.tbl_name AS TABLE_NAME,
  COUNT(c.column_name) AS COLUMN_COUNT
FROM
  tbls t
JOIN
  columns_v2 c
ON
  t.tbl_id = c.cd_id
GROUP BY
  t.tbl_name;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Explanation:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The 'sys.tbls' table contains information about tables, while the 'sys.columns_v2' table contains information about columns.&lt;/LI&gt;&lt;LI&gt;We join these tables on the 'TBL_ID' and 'CD_ID' columns to retrieve information about columns for each table.&lt;/LI&gt;&lt;LI&gt;The 'COUNT(c.COLUMN_NAME)' expression calculates the count of columns for each table.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;This query provides a list of tables along with the count of columns for each table, using the 'sys' database tables."&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 14:10:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Query-to-find-the-count-of-columns-for-all-tables-in-impala/m-p/379310#M243828</guid>
      <dc:creator>ggangadharan</dc:creator>
      <dc:date>2023-11-21T14:10:13Z</dc:date>
    </item>
  </channel>
</rss>

