【问题标题】:How to append input schema to output in pig如何将输入模式附加到猪的输出
【发布时间】:2014-06-06 09:32:36
【问题描述】:

我编写了一个 UDF,其中我的输入模式是一组元组,现在在我的 UDF 中,我正在处理每个元组并为每个元组附加额外的字段并将其提供给输出包。 这很好用,现在在我的下一步中,我尝试创建输出包的输出模式,我只想在我的包输入的元组中附加一个字段。 我该怎么做?

这是我的输入包模式。

xx: {(uniqueRS::PreprocUDF::id: long,uniqueRS::PreprocUDF::dominion: chararray,uniqueRS::PreprocUDF::affectedItemGRN: chararray,uniqueDomAndUser: {(PreprocUDF::dominion: chararray)},uniqueRS::PreprocUDF::count: long)}

现在我需要这种方式

outputBag: {(uniqueRS::PreprocUDF::id: long,uniqueRS::PreprocUDF::dominion: chararray,uniqueRS::PreprocUDF::affectedItemGRN: chararray,uniqueDomAndUser: {(PreprocUDF::dominion: chararray)},uniqueRS::PreprocUDF::count: long,grpName:chararray)}

我尝试将此作为我的输出架构,但没有成功,

public Schema outputSchema(Schema input) {
     Schema.FieldSchema grpName = new Schema.FieldSchema("grpName", DataType.CHARARRAY);
     input.add(grpName);
retrun input;
}

我也尝试了 `mergePrefixSchema() 仍然没有运气,请帮帮我。

也尝试过这种方式

    public Schema outputSchema(Schema input) {

    Schema.FieldSchema inputTupleFS = input.getField(0);
    Schema.FieldSchema grpName = new Schema.FieldSchema("grpName", DataType.CHARARRAY);


    ArrayList<Schema.FieldSchema> tupleList=new ArrayList();
    tupleList.add(inputTupleFS);
    tupleList.add(grpName);

    Schema bagSchema =new Schema(tupleList);
    Schema.FieldSchema bagFS =new Schema.FieldSchema("testBag", bagSchema, DataType.BAG);

    Schema outputBag=new Schema(bagFS);
}

谢谢。

【问题讨论】:

    标签: hadoop apache-pig cloudera piggybak


    【解决方案1】:

    感谢 [http://mail-archives.apache.org/mod_mbox/pig-user/201208.mbox/%3C79A5BC65BFC37343844D4BB8A05DD3EE0183A649BA@opera-ex5.ny.os.local%3E][1]

    得到答案

    public Schema outputSchema(Schema input) {
    
    
                Schema tupleSchema = new Schema(input.getField(0).schema.getField(0).schema.getFields());
                Schema.FieldSchema grpName = new Schema.FieldSchema("grpName", DataType.CHARARRAY);
    
                tupleSchema.add(grpName);
    
                Schema.FieldSchema tupleFs = new Schema.FieldSchema("with_grpName", tupleSchema, DataType.TUPLE);
    
    
    
                Schema bagSchema =new Schema(tupleFs);
                Schema.FieldSchema bagFS =new Schema.FieldSchema("testBag", bagSchema, DataType.BAG);
    
                Schema outputBag=new Schema(bagFS);
    
    
    
    
                    return outputBag;
                }
    

    【讨论】:

      猜你喜欢
      • 2016-05-13
      • 2014-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-06
      • 1970-01-01
      相关资源
      最近更新 更多