8

在直线中使用 hive 和使用简单select查询时,我想在列名中返回没有表名的表作为默认值。

例子

数据

以简单表(TutorialsPoint)为例:

CREATE TABLE IF NOT EXISTS employee ( eid int, name String,
salary String, destination String)
COMMENT 'Employee details'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;

SELECT查询返回:

SELECT * FROM employee;
+---------------+----------------+------------------+-----------------------+--+
| employee.eid  | employee.name  | employee.salary  | employee.destination  |
+---------------+----------------+------------------+-----------------------+--+
+---------------+----------------+------------------+-----------------------+--+

期望的结果

使用以下方法可以达到预期的结果AS

SELECT eid AS eid, name AS name, salary AS salary, 
       destination AS destination FROM employee;

+------+-------+---------+--------------+--+
| eid  | name  | salary  | destination  |
+------+-------+---------+--------------+--+
+------+-------+---------+--------------+--+

问题

我想避免AS每次运行select查询时都键入并返回列名中没有表名的结果作为默认行为。

4

1 回答 1

23

set hive.resultset.use.unique.column.names=false

配置属性

演示

hive> create table t (i int,j int,k int);
hive> select * from t;

t.i t.j t.k

hive> set hive.resultset.use.unique.column.names=false;
hive> select * from t;

i   j   k
于 2017-03-30T08:54:37.590 回答