使用beeline时,避免在列名中打印表名

时间:2017-03-30 08:50:12

标签: sql select hive beeline

在beeline中使用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 ,并将列名中没有表名的结果作为默认行为返回。

1 个答案:

答案 0 :(得分:9)

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

Configuration Properties

演示

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