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] 342 lines
[+20] [+] protected static Schema validateAndConvertRecord(Schema avroSchema, ResourceFieldSchema[] pigFields) throws IOException {
343
                outname = FIELD_NAME + "_" + i; // field name cannot be null
343
                outname = FIELD_NAME + "_" + i; // field name cannot be null
344

    
   
344

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

    
   
347

   

    
   
348
            // if schema contains default values fill in the description

    
   
349
            if (inputField != null && (inputField.defaultValue() != null)) {

    
   
350
                 outFields.add(new Field(outname, fieldSchema, doc, inputField.defaultValue()));

    
   
351
            }

    
   
352
            else {
348
            outFields.add(new Field(outname, fieldSchema, doc, null));
353
                 outFields.add(new Field(outname, fieldSchema, doc, null));
349
        }
354
            }

    
   
355
        }
350

    
   
356

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

    
   
359

   
354
    }
360
    }
[+20] [20] 49 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 1485826 New Change
 
http://svn.apache.org/repos/asf/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/storage/avro/avro_test_files/numbers.txt
New File
 
  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...
  3. http://svn.apache.org/repos/asf/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/storage/avro/avro_test_files/numbers.txt: Loading...