Hive 查询输出分隔符 [英] Hive query output delimiter

查看:26
本文介绍了Hive 查询输出分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Hive 中有 2 个表 - 第一个是外部的,第二个是管理的.托管表是使用 INSERT OVERWRITE...SELECT FROM external_table 从外部填充的.两个表都是用','分隔的行创建的.当我运行选择查询到文件时,结果文件中的分隔符是 Tab,但我需要逗号.如何将其更改为逗号,我看不到它的属性.

I have 2 tables in Hive - first is external, the second one is managed. Managed table is populated from external using INSERT OVERWRITE...SELECT FROM external_table. Both tables are created with row delimited by ','. When I run selects queries into file, the delimiter in result file is Tab, but I need comma. How to change it to comma, I see no properties for that.

推荐答案

首先,你需要改变你的 field delimiter ,而不是你的 line delimiter ie.

First of all, you need to change you field delimiter , not your line delimiter ie.

hive >> CREATE TABLE some_table 
        (col1 int,
         col2 int,
         col3 string)
        ROW FORMAT DELIMITED
        FIELDS TERMINATED BY ','
        STORED AS TEXTFILE;

其次,如果你仍然遇到这个问题,你可以简单地使用 sed 进行更改.

Secondly, if you still face this issue, you can simply change it using sed.

bash >> hive -e 'select * from some_Table' | sed 's/[	]/,/g'  > outputfile.txt

请注意 [ ] 是按 Control+V 然后按制表符:

Please not that [ ] is to press Control+V and then the tab char:

sed 's/<Control+V><TAB character>/,/g'

这篇关于Hive 查询输出分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆