当我在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>
我可以看到full_name,email,birth_year,性别,但是当我使用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),但没有区别。我在这里想念的是什么可以帮忙吗?
答案 0 :(得分:1)
在Java代码中,您调用dumpSchema(String alias)
,这类似于在grunt中调用DESCRIBE
。这就是输出不同的原因。
您可以按如下方式存储查询结果:pigServer.store("emailgroup", "out");
另请尝试getExamples()
,但我从未使用过它。
http://pig.apache.org/docs/r0.11.1/api/org/apache/pig/PigServer.html