java读取hive导出的数据

来源:互联网 发布:身份鉴权超时cms 编辑:程序博客网 时间:2024/05/22 17:01

通过HQL语句:

insert overwrite directory '/COMP/206/OUT/LDAPD_BUSI_CMNCTN_ACCU/${current_date}'select  callingnum,custphone,count(*) as callcountfrom DAPD_VOICE_LOG_TMPgroup by callingnum,custphone;

将统计信息导出到HDFS上,导出了3个字段,HIVE默认字段分隔符为'\001',我将导出到HDFS的数据拷贝到了本地D盘重命名为testdata,尝试解析它,解析代码如下:

public static void main(String[] args) throws Exception {// TODO Auto-generated method stubFileReader reader = new FileReader("d:\\testdata");BufferedReader br = new BufferedReader(reader);String line = "";String[] arrs = null;while ((line = br.readLine()) != null) {byte[] bytes = new byte[] { 1 };String sendString = new String(bytes, "GBK");arrs = line.split(sendString);System.out.println(arrs[0] + " : " + arrs[1] + " : " + arrs[2]);}br.close();reader.close();}

输出为:

13860393195 : 114 : 1
15280154404 : 0591-87677500 : 1
18059386085 : 0593-7668885 : 1

说明可以被正确的解析。

0 0