Dear Wiki user, You have subscribed to a wiki page or wiki category on "Pig Wiki" for change notification.
The following page has been changed by SanthoshSrinivasan: http://wiki.apache.org/pig/UDFManual ------------------------------------------------------------------------------ } public Schema outputSchema(Schema input) { try{ + Schema.FieldSchema tokenFs = new Schema.FieldSchema("token", + DataType.CHARARRAY); + Schema tupleSchema = new Schema(tokenFs); + + Schema.FieldSchema tupleFs; + tupleFs = new Schema.FieldSchema("tuple_of_tokens", tupleSchema, + DataType.TUPLE); + - Schema bagSchema = new Schema(); + Schema bagSchema = new Schema(tupleFs); - bagSchema.add(new Schema.FieldSchema("token", DataType.CHARARRAY)); + bagSchema.setTwoLevelAccessRequired(true); + Schema.FieldSchema bagFs = new Schema.FieldSchema( + "bag_of_tokenTuples",bagSchema, DataType.BAG); + + return new Schema(bagFs); - return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), - bagSchema, DataType.BAG)); }catch (Exception e){ return null; } @@ -410, +420 @@ } }}} - As you can see, this is very similar to the output schema definition in the `Swap` function. One difference is that instead of reusing input schema, we create a brand new field schema to represent the tokens stored in the bag. The other difference is that the type of the schema created is `BAG` (not =TUPLE=). + As you can see, this is very similar to the output schema definition in the `Swap` function. One difference is that instead of reusing input schema, we create a brand new field schema to represent the tokens stored in the bag. The other difference is that the type of the schema created is `BAG` (not `TUPLE`). In addition note that the `bagSchema` explicitly sets two level access to indicate the fact that the bag schema contains a tuple which in turn contains the schema. [[Anchor(Error_Handling)]] === Error Handling ===
