只需从 hive 表中获取列名 [英] Just get column names from hive table

查看:151
本文介绍了只需从 hive 表中获取列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以通过 hive 中的以下技巧从表中获取列名:

I know that you can get column names from a table via the following trick in hive:

hive> set hive.cli.print.header=true;
hive> select * from tablename;

是否也可以只是从表中获取列名?

Is it also possible to just get the column names from the table?

我不喜欢为我只需要一次的东西更改设置.

I dislike having to change a setting for something I only need once.

我目前的解决方案如下:

My current solution is the following:

hive> set hive.cli.print.header=true;
hive> select * from tablename;
hive> set hive.cli.print.header=false;

这似乎过于冗长并且违反了 DRY 原则.

This seems too verbose and against the DRY-principle.

推荐答案

如果你只是想查看列名,这一行应该提供它而无需更改任何设置:

If you simply want to see the column names this one line should provide it without changing any settings:

describe database.tablename;

但是,如果这不适用于您的 hive 版本,此代码将提供它,但您的默认数据库现在将是您正在使用的数据库:

However, if that doesn't work for your version of hive this code will provide it, but your default database will now be the database you are using:

use database;
describe tablename;

这篇关于只需从 hive 表中获取列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆