Java Code Examples for org.apache.pig.impl.logicalLayer.schema.Schema#generateNestedSchema()
The following examples show how to use
org.apache.pig.impl.logicalLayer.schema.Schema#generateNestedSchema() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBuiltInBagToTupleOrString.java From spork with Apache License 2.0 | 6 votes |
@Test public void testOutputSchemaForBagToTupleUDF() throws Exception { Schema expectedSch = Schema.generateNestedSchema(DataType.TUPLE, DataType.INTEGER, DataType.CHARARRAY); FieldSchema tupSch = new FieldSchema(null, DataType.TUPLE); tupSch.schema = new Schema(); tupSch.schema.add(new FieldSchema(null, DataType.INTEGER)); tupSch.schema.add(new FieldSchema(null, DataType.CHARARRAY)); FieldSchema bagSch = new FieldSchema(null, DataType.BAG); bagSch.schema = new Schema(tupSch); Schema inputSch = new Schema(); inputSch.add(bagSch); BagToTuple udf = new BagToTuple(); Schema outputSchema = udf.outputSchema(inputSch); assertEquals("schema of BagToTuple input", expectedSch.size(), outputSchema.size()); assertTrue("schema of BagToTuple input", Schema.equals(expectedSch, outputSchema, false, true)); }
Example 2
Source File: Over.java From spork with Apache License 2.0 | 6 votes |
@Override public Schema outputSchema(Schema inputSch) { try { if (returnType == DataType.UNKNOWN) { return Schema.generateNestedSchema(DataType.BAG, DataType.NULL); } else { Schema outputTupleSchema = new Schema(new Schema.FieldSchema(returnName, returnType)); return new Schema(new Schema.FieldSchema( getSchemaName(this.getClass().getName().toLowerCase(), inputSch), outputTupleSchema, DataType.BAG)); } } catch (FrontendException fe) { throw new RuntimeException("Unable to create nested schema", fe); } }
Example 3
Source File: TestStitch.java From spork with Apache License 2.0 | 6 votes |
@Test public void testSchema2() throws Exception { Schema t = new Schema(); Schema b = new Schema(); t.add(new FieldSchema("x", DataType.CHARARRAY)); t.add(new FieldSchema("y", DataType.INTEGER)); b.add(new FieldSchema("A", t, DataType.TUPLE)); Schema in = new Schema(new FieldSchema("", b, DataType.BAG)); FieldSchema fs = new FieldSchema("Over", new Schema(Schema.generateNestedSchema(DataType.BAG, DataType.NULL)), DataType.BAG); in.add(fs); Stitch func = new Stitch(); Schema out = func.outputSchema(in); assertEquals("{stitched: {x: chararray,y: int,{NULL}}}", out.toString()); }
Example 4
Source File: TOBAG.java From spork with Apache License 2.0 | 5 votes |
@Override public Schema outputSchema(Schema inputSch) { byte type = DataType.ERROR; Schema innerSchema = null; if(inputSch != null){ for(FieldSchema fs : inputSch.getFields()){ if(type == DataType.ERROR){ type = fs.type; innerSchema = fs.schema; }else{ if( type != fs.type || !nullEquals(innerSchema, fs.schema)){ // invalidate the type type = DataType.ERROR; break; } } } } try { if(type == DataType.ERROR){ return Schema.generateNestedSchema(DataType.BAG, DataType.NULL); } FieldSchema innerFs = new Schema.FieldSchema(null, innerSchema, type); Schema innerSch = new Schema(innerFs); Schema bagSchema = new Schema(new FieldSchema(null, innerSch, DataType.BAG)); return bagSchema; } catch (FrontendException e) { //This should not happen throw new RuntimeException("Bug : exception thrown while " + "creating output schema for TOBAG udf", e); } }
Example 5
Source File: TOBAG2.java From spork with Apache License 2.0 | 5 votes |
@Override public Schema outputSchema(Schema inputSch) { byte type = DataType.ERROR; Schema innerSchema = null; if(inputSch != null){ for(FieldSchema fs : inputSch.getFields()){ if(type == DataType.ERROR){ type = fs.type; innerSchema = fs.schema; }else{ if( type != fs.type || !nullEquals(innerSchema, fs.schema)){ // invalidate the type type = DataType.ERROR; break; } } } } try { if(type == DataType.ERROR){ return Schema.generateNestedSchema(DataType.BAG, DataType.NULL); } FieldSchema innerFs = new Schema.FieldSchema(null, innerSchema, type); Schema innerSch = new Schema(innerFs); Schema bagSchema = new Schema(new FieldSchema(null, innerSch, DataType.BAG)); return bagSchema; } catch (FrontendException e) { //This should not happen throw new RuntimeException("Bug : exception thrown while " + "creating output schema for TOBAG udf", e); } }
Example 6
Source File: TestOver.java From spork with Apache License 2.0 | 5 votes |
@Test public void testSchema() throws Exception { // No type Over func = new Over(); Schema in = Schema.generateNestedSchema(DataType.BAG, DataType.INTEGER); Schema out = func.outputSchema(in); assertEquals("{{NULL}}", out.toString()); // chararray func = new Over("chararray"); in = Schema.generateNestedSchema(DataType.BAG, DataType.INTEGER); out = func.outputSchema(in); assertEquals("{org.apache.pig.piggybank.evaluation.over_1: {result: chararray}}", out.toString()); // int func = new Over("Int"); in = Schema.generateNestedSchema(DataType.BAG, DataType.INTEGER); out = func.outputSchema(in); assertEquals("{org.apache.pig.piggybank.evaluation.over_2: {result: int}}", out.toString()); // double func = new Over("DOUBLE"); in = Schema.generateNestedSchema(DataType.BAG, DataType.INTEGER); out = func.outputSchema(in); assertEquals("{org.apache.pig.piggybank.evaluation.over_3: {result: double}}", out.toString()); // named func = new Over("bob:chararray"); in = Schema.generateNestedSchema(DataType.BAG, DataType.INTEGER); out = func.outputSchema(in); assertEquals("{org.apache.pig.piggybank.evaluation.over_4: {bob: chararray}}", out.toString()); }
Example 7
Source File: TestStitch.java From spork with Apache License 2.0 | 5 votes |
@Test public void testSchema() throws Exception { Schema s = new Schema(); Schema in = new Schema(); s.add(new FieldSchema("x", DataType.CHARARRAY)); s.add(new FieldSchema("y", DataType.INTEGER)); in.add(new FieldSchema("A", s, DataType.BAG)); FieldSchema fs = new FieldSchema("Over", new Schema(Schema.generateNestedSchema(DataType.BAG, DataType.NULL)), DataType.BAG); in.add(fs); Stitch func = new Stitch(); Schema out = func.outputSchema(in); assertEquals("{stitched: {x: chararray,y: int,{NULL}}}", out.toString()); }