我在 Hive 工作了一段时间。请注意,我根本不使用 Hue。我一直使用 Hive shell,现在我遇到了一个奇怪但有用的问题。
每当我们在 Hive shell 中执行查询时,我们可以在屏幕上看到相关结果,但我们无法识别与数据对应的列名,除非我们执行“desc 格式化表名”或任何其他类似命令并向上滚动/将结果与表结构相匹配。我们很可能一直这样做。
出于好奇,我想知道当我们执行诸如“select * from table_name”之类的基本查询时,是否有任何方法可以至少将列名与数据一起打印出来?
最佳答案
打开配置单元 session 后设置此属性
hive> set hive.cli.print.header=true;
这样它将显示您的列名称。
示例:
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
一旦我设置了上述属性
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
如果你想去掉 table name i.e. sales. before each column name 那么设置下面的属性
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
(或)
作为永久解决方案,您可以在 hive-site.xml 中找到此属性值并将其更改为 true。
关于hadoop - Hive - 如何在命令行中显示 Hive 查询结果以及列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48896362/