teja
teja

Reputation: 13

How to count Columns in a table in Databricks Hive storage

This code is not working when inserted table name no table found in information_schema.columns

select count(*) from information_schema.columns where table_name = 'emp'

And this is not usefull SHOW COLUMNS (FROM|IN) table_name [(FROM|IN) db_name

Even Describe table

Please suggest some other code to count the columns in a particular table.

Upvotes: 1

Views: 3052

Answers (1)

liamvt
liamvt

Reputation: 223

spark.sql("SHOW COLUMNS IN emp").count()

is a Scala or Python solution in a Databricks notebook. show columns returns a DataFrame with one column col_name and one row for each column, so counting the rows of that DF returns the number of columns in emp

Upvotes: 2

Related Questions