3

I am working in Hive for quite a while . Please note that I don't use Hue at all. I use the Hive shell all the time and now I got a weird but useful question.

Whenever we execute a query in the Hive shell, we can see the relevant results on screen but we cannot recognise the column names corresponding to the data unless we do a "desc formatted table_name" or any other similar command and scroll up / down the screen to match the results with the table structure. We do this all the time most probably.

Just out of curiosity I want to know whether is there any way to print the column names along with the data atleast when we execute a basic query such as "select * from table_name" ?

JKC
  • 2,498
  • 6
  • 30
  • 56
  • Use Beeline. It will show the columns. Also SparkSQL – OneCricketeer Feb 21 '18 at 01:35
  • @cricket_007 Thank you for your inputs but I don't have the connection parameters to start the Beeline. By any chance can we get the connection details from any of the config files – JKC Feb 21 '18 at 02:42
  • You should be able to know which server HiveServer2 runs on. If not, talk to the cluster administrator to make sure it's documented. The later releases of Hive, there are configuration files will allow one to just use the beeline command itself without lots of options – OneCricketeer Feb 21 '18 at 02:54
  • Thanks @cricket_007 . will check it out – JKC Feb 21 '18 at 05:39

1 Answers1

7

set this property once you open hive session

hive> set hive.cli.print.header=true;

so that it will display your column names.

Example:

hive> desc sales;
OK
col_name        data_type       comment
year                    string
month                   string
customer                string
stateid                 string
productid               string
qty                     string
billed                  string

hive> select * from sales;
OK
2011    1.2     A       2       1       2       8
2011    5.2     C       3       1       1       8
2011    2       B       1       2       1       2
2011    3       B       1       2       2       2

once i set the above property

hive> set hive.cli.print.header=true;
hive> select * from sales;
OK
sales.year      sales.month     sales.customer  sales.stateid   sales.productid sales.qty       sales.billed
2011    1.2     A       2       1       2       8
2011    5.2     C       3       1       1       8
2011    2       B       1       2       1       2

if you want to get rid of table name i.e sales. before each column name then set the below property

hive> set hive.resultset.use.unique.column.names=false;
hive> select * from sales;
OK
year    month   customer        stateid productid       qty     billed
2011    1.2     A       2       1       2       8
2011    5.2     C       3       1       1       8
2011    2       B       1       2       1       2

(or)

As a permanent solution,you can find and change this property value to true in your hive-site.xml.

notNull
  • 30,258
  • 4
  • 35
  • 50