插入覆盖目录时出现问题

y0u0uwnf  于 2021-06-27  发布在  Hive
关注(0)|答案(1)|浏览(406)
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

taor4pac

taor4pac1#

在执行插入覆盖目录时添加头还不受支持,请参阅此jira
可以将输出文件与头文件连接起来:

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

或者像这样重写select查询(order by将触发单个final reducer,并且可能运行缓慢):

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;

相关问题