0

当我在 grunt 上运行我的猪脚本时,输出看起来不错。下面是示例

2013-07-08 16:58:40,640 [main] INFO  org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher - Success!
2013-07-08 16:58:40,647 [main] INFO  org.apache.hadoop.mapreduce.lib.input.FileInputFormat - Total input paths to process : 1
2013-07-08 16:58:40,647 [main] INFO  org.apache.pig.backend.hadoop.executionengine.util.MapRedUtil - Total input paths to process : 1
((email,r@gmail.com),{(rrr24,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr10,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr20,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr23,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr9,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr8,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr22,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr21,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{})})
((email,zzzz@gmail.com),{(rrr0,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr6,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr7,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr3,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr1,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr5,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr4,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{}),(rrr2,(full_name,rachana),email,(state,ca),(birth_year,2013),(gender,female),{})})
grunt> 

我可以看到全名、电子邮件、出生年份、性别,但是当我使用 java 运行时

package com.chegg.hwh.tracking.dao;

import org.apache.pig.ExecType;
import org.apache.pig.PigServer;

public class HWHDataPigMapReduce {

    public static void main(String args[]) throws Exception {
        PigServer pigServer = new PigServer(ExecType.LOCAL);

        pigServer.registerQuery("rows = LOAD 'cassandra://hwh_tracking/users' USING org.apache.cassandra.hadoop.pig.CassandraStorage();");
        pigServer.registerQuery("emailgroup = group rows by email;");
        pigServer.dumpSchema("emailgroup");

    }

}

输出 :

emailgroup: {group: (name: chararray,value: chararray),rows: {(key: chararray,full_name: (name: chararray,value: chararray),email: (name: chararray,value: chararray),state: (name: chararray,value: chararray),birth_year: (name: chararray,value: long),gender: (name: chararray,value: chararray),columns: {(name: chararray,value: bytearray)})}}

我尝试使用 as (full_name:chararray) 但没有区别。我在这里想念什么。任何人都可以帮忙吗?

4

1 回答 1

1

在您正在调用的 Java 代码dumpSchema(String alias)中,这类似于DESCRIBE在 grunt 中调用。这就是输出不同的原因。

您可以按如下方式存储查询结果:pigServer.store("emailgroup", "out");

也试试getExamples(),不过我没用过。

http://pig.apache.org/docs/r0.11.1/api/org/apache/pig/PigServer.html

于 2013-07-09T12:10:30.287 回答