2

1)

insert overwrite directory `'/user/sample/newfolder'` 

row format delimited

fields terminated by ', '

select * from emp;

给我没有标题的数据。即使在使用set hive.cli.print.header=true;

我试过做hive -e 'set hive.cli.print.header=true;select * from emp;' > /user/sample/newfolder/sample.xls- 它没有工作说:没有这样的文件或目录

2)每条记录的数据将转到另一行。如何将其限制为单行?

ex: 1, ppp, ddd,44,

45,www

但我想要它1,ppp,ddd,44,45,www

4

1 回答 1

1

尚不支持在插入覆盖目录时添加标题,请参阅此Jira

您可以将输出文件与头文件连接起来:

hadoop fs -cat /user/dir/header.csv /user/dir/output_file.csv | hadoop fs -put - /user/dir/output_w_header.csv

或者像这样重写您的选择查询(ORDER BY 将触发单个最终减速器并且可能工作缓慢):

select * from 
(
select --header
      0           as order_col
      'col1_name' as col1,
      'col2_name' as col2,
       ...
      'colN_name' as colN
UNION ALL 
select --data
       1                    order_col,
       cast(col1 as string) col1, --cast to strings
       col2, ... coln 
  from emp
)s 
order by order_col;
于 2019-02-25T14:35:02.907 回答