Review Board 1.7.22


PIG-3331 Default values not written to Schema when specified in the output schema

Review Request #11355 - Created May 23, 2013 and updated

Viraj Bhat
Reviewers
pig
rohini
pig
Patch to write default values to the Schema when the writer schema contains that in the AvroStorage.
Yes against the Piggybank  in Pig trunk/Pig 0.12
http://svn.apache.org/repos/asf/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/avro/PigSchema2Avro.java
Revision 1485826 New Change
[20] 23 lines
[+20]
24
import org.apache.avro.Schema.Field;
24
import org.apache.avro.Schema.Field;
25
import org.apache.pig.ResourceSchema;
25
import org.apache.pig.ResourceSchema;
26
import org.apache.pig.ResourceSchema.ResourceFieldSchema;
26
import org.apache.pig.ResourceSchema.ResourceFieldSchema;
27
import org.apache.pig.data.DataType;
27
import org.apache.pig.data.DataType;
28

    
   
28

   

    
   
29
import org.codehaus.jackson.JsonNode;

    
   
30

   
29
/**
31
/**
30
 * This class contains functions to convert Pig schema to Avro. It consists of
32
 * This class contains functions to convert Pig schema to Avro. It consists of
31
 * two sets of methods:
33
 * two sets of methods:
32
 * 
34
 * 
33
 * 1. Convert a Pig schema to Avro schema;
35
 * 1. Convert a Pig schema to Avro schema;
[+20] [20] 309 lines
[+20] [+] protected static Schema validateAndConvertRecord(Schema avroSchema, ResourceFieldSchema[] pigFields) throws IOException {
343
                outname = FIELD_NAME + "_" + i; // field name cannot be null
345
                outname = FIELD_NAME + "_" + i; // field name cannot be null
344

    
   
346

   
345
            /* get doc of output */
347
            /* get doc of output */
346
            String doc = (isPartialSchema) ? pigFields[i].getDescription() : inputField.doc();
348
            String doc = (isPartialSchema) ? pigFields[i].getDescription() : inputField.doc();
347

    
   
349

   
348
            outFields.add(new Field(outname, fieldSchema, doc, null));
350
            JsonNode defaultvalue = (inputField != null) ? inputField.defaultValue() : null;

    
   
351

   

    
   
352
            outFields.add(new Field(outname, fieldSchema, doc, defaultvalue));

    
   
353

   
349
        }
354
        }
350

    
   
355

   
351
        outSchema.setFields(outFields);
356
        outSchema.setFields(outFields);
352
        return outSchema;
357
        return outSchema;
353

    
   
358

   
[+20] [20] 50 lines
http://svn.apache.org/repos/asf/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/storage/avro/TestAvroStorage.java
Revision 1489655 New Change
 
  1. http://svn.apache.org/repos/asf/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/avro/PigSchema2Avro.java: Loading...
  2. http://svn.apache.org/repos/asf/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/storage/avro/TestAvroStorage.java: Loading...