Author: daijy
Date: Fri Jun 12 17:25:30 2015
New Revision: 1685138

URL: http://svn.apache.org/r1685138
Log:
PIG-4570: Allow AvroStorage to use a class for the schema

Added:
    pig/trunk/test/org/apache/pig/builtin/avro/code/java/
    pig/trunk/test/org/apache/pig/builtin/avro/code/java/RecordPojo.java
    pig/trunk/test/org/apache/pig/builtin/avro/schema/RecordPojo.avsc
Modified:
    pig/trunk/src/org/apache/pig/builtin/AvroStorage.java
    pig/trunk/test/org/apache/pig/builtin/TestAvroStorage.java

Modified: pig/trunk/src/org/apache/pig/builtin/AvroStorage.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/AvroStorage.java?rev=1685138&r1=1685137&r2=1685138&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/AvroStorage.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/AvroStorage.java Fri Jun 12 17:25:30 
2015
@@ -29,6 +29,7 @@ import org.apache.avro.Schema;
 import org.apache.avro.SchemaParseException;
 import org.apache.avro.Schema.Type;
 import org.apache.avro.file.DataFileStream;
+import org.apache.avro.generic.GenericContainer;
 import org.apache.avro.generic.GenericDatumReader;
 import org.apache.avro.generic.GenericData;
 import org.apache.avro.mapred.AvroInputFormat;
@@ -120,6 +121,8 @@ public class AvroStorage extends LoadFun
    *  <li><code>-schemafile</code> Specifies URL for avro schema file
    *    from which to read the input schema (can be local file, hdfs,
    *    url, etc).</li>
+   *  <li><code>-schemaclass</code> Specifies fully qualified class name for 
avro
+   *    class in your classpath which implements GenericContainer.</li>
    *  <li><code>-examplefile</code> Specifies URL for avro data file from
    *    which to copy the input schema (can be local file, hdfs, url, 
etc).</li>
    *  <li><code>-allowrecursive</code> Option to allow recursive schema
@@ -153,6 +156,9 @@ public class AvroStorage extends LoadFun
         validOptions.addOption("f", "schemafile", true,
             "Specifies URL for avro schema file from which to read "
             + "the input or output schema");
+        validOptions.addOption("c", "schemaclass", true,
+            "Specifies fully qualified class name for avro "
+            + "class in your classpath which implements GenericContainer.");
         validOptions.addOption("e", "examplefile", true,
             "Specifies URL for avro data file from which to copy "
             + "the output schema");
@@ -179,6 +185,25 @@ public class AvroStorage extends LoadFun
                 "schema was described in a local file on the front end, and 
this message " + 
                 "is in the back end log, you can ignore this mesasge.)", fnfe);
           }
+        } else if (configuredOptions.hasOption('c')) {
+          String schemaClass = configuredOptions.getOptionValue('c');
+          try {
+            Schema s = ((GenericContainer) 
Class.forName(schemaClass).newInstance()).getSchema();
+            setInputAvroSchema(s);
+            setOutputAvroSchema(s);
+          } catch (ClassNotFoundException | IllegalAccessException cnfe) {
+            System.err.printf("class not found exception\n");
+            log.error("Schema class '" + schemaClass + "' was not found in the 
classpath.", cnfe);
+            throw new RuntimeException(cnfe);
+          } catch (InstantiationException ie) {
+            System.err.printf("instantiation exception\n");
+            log.error("Schema class '" + schemaClass + "' must have a public 
empty args constructor.", ie);
+            throw new RuntimeException(ie);
+          } catch (ClassCastException cce) {
+            System.err.printf("class cast exception\n");
+            log.error("Schema class '" + schemaClass + "' must implement 
org.apache.avro.generic.GenericContainer interface.", cce);
+            throw new RuntimeException(cce);
+          }
         } else if (configuredOptions.hasOption('e')) {
           setOutputAvroSchema(
               getAvroSchema(configuredOptions.getOptionValue('e'),

Modified: pig/trunk/test/org/apache/pig/builtin/TestAvroStorage.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/builtin/TestAvroStorage.java?rev=1685138&r1=1685137&r2=1685138&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/builtin/TestAvroStorage.java (original)
+++ pig/trunk/test/org/apache/pig/builtin/TestAvroStorage.java Fri Jun 12 
17:25:30 2015
@@ -429,6 +429,21 @@ public class TestAvroStorage {
     }
 
     @Test
+    public void testLoadRecordsSpecifyFullSchemaFromClass() throws Exception {
+      final String input = basedir + "data/avro/uncompressed/records.avro";
+      final String check = basedir + 
"data/avro/uncompressed/recordsAsOutputByPig.avro";
+      testAvroStorage(true, basedir + "code/pig/identity.pig",
+          ImmutableMap.of(
+               "INFILE",            input,
+               "OUTFILE",           createOutputName(),
+               "AVROSTORAGE_IN_2",  "-c 
org.apache.pig.builtin.avro.code.java.RecordPojo",
+               "AVROSTORAGE_OUT_1", "''",
+               "AVROSTORAGE_OUT_2", "-c 
org.apache.pig.builtin.avro.code.java.RecordPojo")
+        );
+      verifyResults(createOutputName(),check);
+    }
+
+    @Test
     public void testLoadRecordsSpecifyFullSchemaFromFile() throws Exception {
       final String input = basedir + "data/avro/uncompressed/records.avro";
       final String check = basedir + 
"data/avro/uncompressed/recordsAsOutputByPig.avro";

Added: pig/trunk/test/org/apache/pig/builtin/avro/code/java/RecordPojo.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/builtin/avro/code/java/RecordPojo.java?rev=1685138&view=auto
==============================================================================
--- pig/trunk/test/org/apache/pig/builtin/avro/code/java/RecordPojo.java (added)
+++ pig/trunk/test/org/apache/pig/builtin/avro/code/java/RecordPojo.java Fri 
Jun 12 17:25:30 2015
@@ -0,0 +1,981 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Autogenerated by Avro
+ * 
+ * DO NOT EDIT DIRECTLY
+ */
+package org.apache.pig.builtin.avro.code.java;  
+@SuppressWarnings("all")
+/** to test a generated Avro Java class */
[email protected]
+public class RecordPojo extends org.apache.avro.specific.SpecificRecordBase 
implements org.apache.avro.specific.SpecificRecord {
+  public static final org.apache.avro.Schema SCHEMA$ = new 
org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"RecordPojo\",\"namespace\":\"org.apache.pig.builtin.avro.code.java\",\"doc\":\"to
 test a generated Avro Java 
class\",\"fields\":[{\"name\":\"key\",\"type\":\"string\"},{\"name\":\"intValue\",\"type\":\"int\"},{\"name\":\"longValue\",\"type\":\"long\"},{\"name\":\"booleanValue\",\"type\":\"boolean\"},{\"name\":\"floatValue\",\"type\":\"float\"},{\"name\":\"doubleValue\",\"type\":\"double\"},{\"name\":\"bytesValue\",\"type\":\"bytes\"},{\"name\":\"nullValue\",\"type\":\"null\"}]}");
+  public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
+  @Deprecated public java.lang.CharSequence key;
+  @Deprecated public int intValue;
+  @Deprecated public long longValue;
+  @Deprecated public boolean booleanValue;
+  @Deprecated public float floatValue;
+  @Deprecated public double doubleValue;
+  @Deprecated public java.nio.ByteBuffer bytesValue;
+  @Deprecated public java.lang.Void nullValue;
+
+  /**
+   * Default constructor.
+   */
+  public RecordPojo() {}
+
+  /**
+   * All-args constructor.
+   */
+  public RecordPojo(java.lang.CharSequence key, java.lang.Integer intValue, 
java.lang.Long longValue, java.lang.Boolean booleanValue, java.lang.Float 
floatValue, java.lang.Double doubleValue, java.nio.ByteBuffer bytesValue, 
java.lang.Void nullValue) {
+    this.key = key;
+    this.intValue = intValue;
+    this.longValue = longValue;
+    this.booleanValue = booleanValue;
+    this.floatValue = floatValue;
+    this.doubleValue = doubleValue;
+    this.bytesValue = bytesValue;
+    this.nullValue = nullValue;
+  }
+
+  public org.apache.avro.Schema getSchema() { return SCHEMA$; }
+  // Used by DatumWriter.  Applications should not call. 
+  public java.lang.Object get(int field$) {
+    switch (field$) {
+    case 0: return key;
+    case 1: return intValue;
+    case 2: return longValue;
+    case 3: return booleanValue;
+    case 4: return floatValue;
+    case 5: return doubleValue;
+    case 6: return bytesValue;
+    case 7: return nullValue;
+    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+    }
+  }
+  // Used by DatumReader.  Applications should not call. 
+  @SuppressWarnings(value="unchecked")
+  public void put(int field$, java.lang.Object value$) {
+    switch (field$) {
+    case 0: key = (java.lang.CharSequence)value$; break;
+    case 1: intValue = (java.lang.Integer)value$; break;
+    case 2: longValue = (java.lang.Long)value$; break;
+    case 3: booleanValue = (java.lang.Boolean)value$; break;
+    case 4: floatValue = (java.lang.Float)value$; break;
+    case 5: doubleValue = (java.lang.Double)value$; break;
+    case 6: bytesValue = (java.nio.ByteBuffer)value$; break;
+    case 7: nullValue = (java.lang.Void)value$; break;
+    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+    }
+  }
+
+  /**
+   * Gets the value of the 'key' field.
+   */
+  public java.lang.CharSequence getKey() {
+    return key;
+  }
+
+  /**
+   * Sets the value of the 'key' field.
+   * @param value the value to set.
+   */
+  public void setKey(java.lang.CharSequence value) {
+    this.key = value;
+  }
+
+  /**
+   * Gets the value of the 'intValue' field.
+   */
+  public java.lang.Integer getIntValue() {
+    return intValue;
+  }
+
+  /**
+   * Sets the value of the 'intValue' field.
+   * @param value the value to set.
+   */
+  public void setIntValue(java.lang.Integer value) {
+    this.intValue = value;
+  }
+
+  /**
+   * Gets the value of the 'longValue' field.
+   */
+  public java.lang.Long getLongValue() {
+    return longValue;
+  }
+
+  /**
+   * Sets the value of the 'longValue' field.
+   * @param value the value to set.
+   */
+  public void setLongValue(java.lang.Long value) {
+    this.longValue = value;
+  }
+
+  /**
+   * Gets the value of the 'booleanValue' field.
+   */
+  public java.lang.Boolean getBooleanValue() {
+    return booleanValue;
+  }
+
+  /**
+   * Sets the value of the 'booleanValue' field.
+   * @param value the value to set.
+   */
+  public void setBooleanValue(java.lang.Boolean value) {
+    this.booleanValue = value;
+  }
+
+  /**
+   * Gets the value of the 'floatValue' field.
+   */
+  public java.lang.Float getFloatValue() {
+    return floatValue;
+  }
+
+  /**
+   * Sets the value of the 'floatValue' field.
+   * @param value the value to set.
+   */
+  public void setFloatValue(java.lang.Float value) {
+    this.floatValue = value;
+  }
+
+  /**
+   * Gets the value of the 'doubleValue' field.
+   */
+  public java.lang.Double getDoubleValue() {
+    return doubleValue;
+  }
+
+  /**
+   * Sets the value of the 'doubleValue' field.
+   * @param value the value to set.
+   */
+  public void setDoubleValue(java.lang.Double value) {
+    this.doubleValue = value;
+  }
+
+  /**
+   * Gets the value of the 'bytesValue' field.
+   */
+  public java.nio.ByteBuffer getBytesValue() {
+    return bytesValue;
+  }
+
+  /**
+   * Sets the value of the 'bytesValue' field.
+   * @param value the value to set.
+   */
+  public void setBytesValue(java.nio.ByteBuffer value) {
+    this.bytesValue = value;
+  }
+
+  /**
+   * Gets the value of the 'nullValue' field.
+   */
+  public java.lang.Void getNullValue() {
+    return nullValue;
+  }
+
+  /**
+   * Sets the value of the 'nullValue' field.
+   * @param value the value to set.
+   */
+  public void setNullValue(java.lang.Void value) {
+    this.nullValue = value;
+  }
+
+  /** Creates a new RecordPojo RecordBuilder */
+  public static org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
newBuilder() {
+    return new org.apache.pig.builtin.avro.code.java.RecordPojo.Builder();
+  }
+  
+  /** Creates a new RecordPojo RecordBuilder by copying an existing Builder */
+  public static org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
newBuilder(org.apache.pig.builtin.avro.code.java.RecordPojo.Builder other) {
+    return new org.apache.pig.builtin.avro.code.java.RecordPojo.Builder(other);
+  }
+  
+  /** Creates a new RecordPojo RecordBuilder by copying an existing RecordPojo 
instance */
+  public static org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
newBuilder(org.apache.pig.builtin.avro.code.java.RecordPojo other) {
+    return new org.apache.pig.builtin.avro.code.java.RecordPojo.Builder(other);
+  }
+  
+  /**
+   * RecordBuilder for RecordPojo instances.
+   */
+  public static class Builder extends 
org.apache.avro.specific.SpecificRecordBuilderBase<RecordPojo>
+    implements org.apache.avro.data.RecordBuilder<RecordPojo> {
+
+    private java.lang.CharSequence key;
+    private int intValue;
+    private long longValue;
+    private boolean booleanValue;
+    private float floatValue;
+    private double doubleValue;
+    private java.nio.ByteBuffer bytesValue;
+    private java.lang.Void nullValue;
+
+    /** Creates a new Builder */
+    private Builder() {
+      super(org.apache.pig.builtin.avro.code.java.RecordPojo.SCHEMA$);
+    }
+    
+    /** Creates a Builder by copying an existing Builder */
+    private Builder(org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
other) {
+      super(other);
+    }
+    
+    /** Creates a Builder by copying an existing RecordPojo instance */
+    private Builder(org.apache.pig.builtin.avro.code.java.RecordPojo other) {
+            super(org.apache.pig.builtin.avro.code.java.RecordPojo.SCHEMA$);
+      if (isValidValue(fields()[0], other.key)) {
+        this.key = data().deepCopy(fields()[0].schema(), other.key);
+        fieldSetFlags()[0] = true;
+      }
+      if (isValidValue(fields()[1], other.intValue)) {
+        this.intValue = data().deepCopy(fields()[1].schema(), other.intValue);
+        fieldSetFlags()[1] = true;
+      }
+      if (isValidValue(fields()[2], other.longValue)) {
+        this.longValue = data().deepCopy(fields()[2].schema(), 
other.longValue);
+        fieldSetFlags()[2] = true;
+      }
+      if (isValidValue(fields()[3], other.booleanValue)) {
+        this.booleanValue = data().deepCopy(fields()[3].schema(), 
other.booleanValue);
+        fieldSetFlags()[3] = true;
+      }
+      if (isValidValue(fields()[4], other.floatValue)) {
+        this.floatValue = data().deepCopy(fields()[4].schema(), 
other.floatValue);
+        fieldSetFlags()[4] = true;
+      }
+      if (isValidValue(fields()[5], other.doubleValue)) {
+        this.doubleValue = data().deepCopy(fields()[5].schema(), 
other.doubleValue);
+        fieldSetFlags()[5] = true;
+      }
+      if (isValidValue(fields()[6], other.bytesValue)) {
+        this.bytesValue = data().deepCopy(fields()[6].schema(), 
other.bytesValue);
+        fieldSetFlags()[6] = true;
+      }
+      if (isValidValue(fields()[7], other.nullValue)) {
+        this.nullValue = data().deepCopy(fields()[7].schema(), 
other.nullValue);
+        fieldSetFlags()[7] = true;
+      }
+    }
+
+    /** Gets the value of the 'key' field */
+    public java.lang.CharSequence getKey() {
+      return key;
+    }
+    
+    /** Sets the value of the 'key' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setKey(java.lang.CharSequence value) {
+      validate(fields()[0], value);
+      this.key = value;
+      fieldSetFlags()[0] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'key' field has been set */
+    public boolean hasKey() {
+      return fieldSetFlags()[0];
+    }
+    
+    /** Clears the value of the 'key' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder clearKey() 
{
+      key = null;
+      fieldSetFlags()[0] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'intValue' field */
+    public java.lang.Integer getIntValue() {
+      return intValue;
+    }
+    
+    /** Sets the value of the 'intValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setIntValue(int value) {
+      validate(fields()[1], value);
+      this.intValue = value;
+      fieldSetFlags()[1] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'intValue' field has been set */
+    public boolean hasIntValue() {
+      return fieldSetFlags()[1];
+    }
+    
+    /** Clears the value of the 'intValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearIntValue() {
+      fieldSetFlags()[1] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'longValue' field */
+    public java.lang.Long getLongValue() {
+      return longValue;
+    }
+    
+    /** Sets the value of the 'longValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setLongValue(long value) {
+      validate(fields()[2], value);
+      this.longValue = value;
+      fieldSetFlags()[2] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'longValue' field has been set */
+    public boolean hasLongValue() {
+      return fieldSetFlags()[2];
+    }
+    
+    /** Clears the value of the 'longValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearLongValue() {
+      fieldSetFlags()[2] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'booleanValue' field */
+    public java.lang.Boolean getBooleanValue() {
+      return booleanValue;
+    }
+    
+    /** Sets the value of the 'booleanValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setBooleanValue(boolean value) {
+      validate(fields()[3], value);
+      this.booleanValue = value;
+      fieldSetFlags()[3] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'booleanValue' field has been set */
+    public boolean hasBooleanValue() {
+      return fieldSetFlags()[3];
+    }
+    
+    /** Clears the value of the 'booleanValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearBooleanValue() {
+      fieldSetFlags()[3] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'floatValue' field */
+    public java.lang.Float getFloatValue() {
+      return floatValue;
+    }
+    
+    /** Sets the value of the 'floatValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setFloatValue(float value) {
+      validate(fields()[4], value);
+      this.floatValue = value;
+      fieldSetFlags()[4] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'floatValue' field has been set */
+    public boolean hasFloatValue() {
+      return fieldSetFlags()[4];
+    }
+    
+    /** Clears the value of the 'floatValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearFloatValue() {
+      fieldSetFlags()[4] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'doubleValue' field */
+    public java.lang.Double getDoubleValue() {
+      return doubleValue;
+    }
+    
+    /** Sets the value of the 'doubleValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setDoubleValue(double value) {
+      validate(fields()[5], value);
+      this.doubleValue = value;
+      fieldSetFlags()[5] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'doubleValue' field has been set */
+    public boolean hasDoubleValue() {
+      return fieldSetFlags()[5];
+    }
+    
+    /** Clears the value of the 'doubleValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearDoubleValue() {
+      fieldSetFlags()[5] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'bytesValue' field */
+    public java.nio.ByteBuffer getBytesValue() {
+      return bytesValue;
+    }
+    
+    /** Sets the value of the 'bytesValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setBytesValue(java.nio.ByteBuffer value) {
+      validate(fields()[6], value);
+      this.bytesValue = value;
+      fieldSetFlags()[6] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'bytesValue' field has been set */
+    public boolean hasBytesValue() {
+      return fieldSetFlags()[6];
+    }
+    
+    /** Clears the value of the 'bytesValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearBytesValue() {
+      bytesValue = null;
+      fieldSetFlags()[6] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'nullValue' field */
+    public java.lang.Void getNullValue() {
+      return nullValue;
+    }
+    
+    /** Sets the value of the 'nullValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setNullValue(java.lang.Void value) {
+      validate(fields()[7], value);
+      this.nullValue = value;
+      fieldSetFlags()[7] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'nullValue' field has been set */
+    public boolean hasNullValue() {
+      return fieldSetFlags()[7];
+    }
+    
+    /** Clears the value of the 'nullValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearNullValue() {
+      nullValue = null;
+      fieldSetFlags()[7] = false;
+      return this;
+    }
+
+    @Override
+    public RecordPojo build() {
+      try {
+        RecordPojo record = new RecordPojo();
+        record.key = fieldSetFlags()[0] ? this.key : (java.lang.CharSequence) 
defaultValue(fields()[0]);
+        record.intValue = fieldSetFlags()[1] ? this.intValue : 
(java.lang.Integer) defaultValue(fields()[1]);
+        record.longValue = fieldSetFlags()[2] ? this.longValue : 
(java.lang.Long) defaultValue(fields()[2]);
+        record.booleanValue = fieldSetFlags()[3] ? this.booleanValue : 
(java.lang.Boolean) defaultValue(fields()[3]);
+        record.floatValue = fieldSetFlags()[4] ? this.floatValue : 
(java.lang.Float) defaultValue(fields()[4]);
+        record.doubleValue = fieldSetFlags()[5] ? this.doubleValue : 
(java.lang.Double) defaultValue(fields()[5]);
+        record.bytesValue = fieldSetFlags()[6] ? this.bytesValue : 
(java.nio.ByteBuffer) defaultValue(fields()[6]);
+        record.nullValue = fieldSetFlags()[7] ? this.nullValue : 
(java.lang.Void) defaultValue(fields()[7]);
+        return record;
+      } catch (Exception e) {
+        throw new org.apache.avro.AvroRuntimeException(e);
+      }
+    }
+  }
+}
+/**
+ * Autogenerated by Avro
+ * 
+ * DO NOT EDIT DIRECTLY
+ */
+package org.apache.pig.builtin.avro.code.java;  
+@SuppressWarnings("all")
+/** to test a generated Avro Java class */
[email protected]
+public class RecordPojo extends org.apache.avro.specific.SpecificRecordBase 
implements org.apache.avro.specific.SpecificRecord {
+  public static final org.apache.avro.Schema SCHEMA$ = new 
org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"RecordPojo\",\"namespace\":\"org.apache.pig.builtin.avro.code.java\",\"doc\":\"to
 test a generated Avro Java 
class\",\"fields\":[{\"name\":\"key\",\"type\":\"string\"},{\"name\":\"intValue\",\"type\":\"int\"},{\"name\":\"longValue\",\"type\":\"long\"},{\"name\":\"booleanValue\",\"type\":\"boolean\"},{\"name\":\"floatValue\",\"type\":\"float\"},{\"name\":\"doubleValue\",\"type\":\"double\"},{\"name\":\"bytesValue\",\"type\":\"bytes\"},{\"name\":\"nullValue\",\"type\":\"null\"}]}");
+  public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
+  @Deprecated public java.lang.CharSequence key;
+  @Deprecated public int intValue;
+  @Deprecated public long longValue;
+  @Deprecated public boolean booleanValue;
+  @Deprecated public float floatValue;
+  @Deprecated public double doubleValue;
+  @Deprecated public java.nio.ByteBuffer bytesValue;
+  @Deprecated public java.lang.Void nullValue;
+
+  /**
+   * Default constructor.
+   */
+  public RecordPojo() {}
+
+  /**
+   * All-args constructor.
+   */
+  public RecordPojo(java.lang.CharSequence key, java.lang.Integer intValue, 
java.lang.Long longValue, java.lang.Boolean booleanValue, java.lang.Float 
floatValue, java.lang.Double doubleValue, java.nio.ByteBuffer bytesValue, 
java.lang.Void nullValue) {
+    this.key = key;
+    this.intValue = intValue;
+    this.longValue = longValue;
+    this.booleanValue = booleanValue;
+    this.floatValue = floatValue;
+    this.doubleValue = doubleValue;
+    this.bytesValue = bytesValue;
+    this.nullValue = nullValue;
+  }
+
+  public org.apache.avro.Schema getSchema() { return SCHEMA$; }
+  // Used by DatumWriter.  Applications should not call. 
+  public java.lang.Object get(int field$) {
+    switch (field$) {
+    case 0: return key;
+    case 1: return intValue;
+    case 2: return longValue;
+    case 3: return booleanValue;
+    case 4: return floatValue;
+    case 5: return doubleValue;
+    case 6: return bytesValue;
+    case 7: return nullValue;
+    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+    }
+  }
+  // Used by DatumReader.  Applications should not call. 
+  @SuppressWarnings(value="unchecked")
+  public void put(int field$, java.lang.Object value$) {
+    switch (field$) {
+    case 0: key = (java.lang.CharSequence)value$; break;
+    case 1: intValue = (java.lang.Integer)value$; break;
+    case 2: longValue = (java.lang.Long)value$; break;
+    case 3: booleanValue = (java.lang.Boolean)value$; break;
+    case 4: floatValue = (java.lang.Float)value$; break;
+    case 5: doubleValue = (java.lang.Double)value$; break;
+    case 6: bytesValue = (java.nio.ByteBuffer)value$; break;
+    case 7: nullValue = (java.lang.Void)value$; break;
+    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+    }
+  }
+
+  /**
+   * Gets the value of the 'key' field.
+   */
+  public java.lang.CharSequence getKey() {
+    return key;
+  }
+
+  /**
+   * Sets the value of the 'key' field.
+   * @param value the value to set.
+   */
+  public void setKey(java.lang.CharSequence value) {
+    this.key = value;
+  }
+
+  /**
+   * Gets the value of the 'intValue' field.
+   */
+  public java.lang.Integer getIntValue() {
+    return intValue;
+  }
+
+  /**
+   * Sets the value of the 'intValue' field.
+   * @param value the value to set.
+   */
+  public void setIntValue(java.lang.Integer value) {
+    this.intValue = value;
+  }
+
+  /**
+   * Gets the value of the 'longValue' field.
+   */
+  public java.lang.Long getLongValue() {
+    return longValue;
+  }
+
+  /**
+   * Sets the value of the 'longValue' field.
+   * @param value the value to set.
+   */
+  public void setLongValue(java.lang.Long value) {
+    this.longValue = value;
+  }
+
+  /**
+   * Gets the value of the 'booleanValue' field.
+   */
+  public java.lang.Boolean getBooleanValue() {
+    return booleanValue;
+  }
+
+  /**
+   * Sets the value of the 'booleanValue' field.
+   * @param value the value to set.
+   */
+  public void setBooleanValue(java.lang.Boolean value) {
+    this.booleanValue = value;
+  }
+
+  /**
+   * Gets the value of the 'floatValue' field.
+   */
+  public java.lang.Float getFloatValue() {
+    return floatValue;
+  }
+
+  /**
+   * Sets the value of the 'floatValue' field.
+   * @param value the value to set.
+   */
+  public void setFloatValue(java.lang.Float value) {
+    this.floatValue = value;
+  }
+
+  /**
+   * Gets the value of the 'doubleValue' field.
+   */
+  public java.lang.Double getDoubleValue() {
+    return doubleValue;
+  }
+
+  /**
+   * Sets the value of the 'doubleValue' field.
+   * @param value the value to set.
+   */
+  public void setDoubleValue(java.lang.Double value) {
+    this.doubleValue = value;
+  }
+
+  /**
+   * Gets the value of the 'bytesValue' field.
+   */
+  public java.nio.ByteBuffer getBytesValue() {
+    return bytesValue;
+  }
+
+  /**
+   * Sets the value of the 'bytesValue' field.
+   * @param value the value to set.
+   */
+  public void setBytesValue(java.nio.ByteBuffer value) {
+    this.bytesValue = value;
+  }
+
+  /**
+   * Gets the value of the 'nullValue' field.
+   */
+  public java.lang.Void getNullValue() {
+    return nullValue;
+  }
+
+  /**
+   * Sets the value of the 'nullValue' field.
+   * @param value the value to set.
+   */
+  public void setNullValue(java.lang.Void value) {
+    this.nullValue = value;
+  }
+
+  /** Creates a new RecordPojo RecordBuilder */
+  public static org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
newBuilder() {
+    return new org.apache.pig.builtin.avro.code.java.RecordPojo.Builder();
+  }
+  
+  /** Creates a new RecordPojo RecordBuilder by copying an existing Builder */
+  public static org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
newBuilder(org.apache.pig.builtin.avro.code.java.RecordPojo.Builder other) {
+    return new org.apache.pig.builtin.avro.code.java.RecordPojo.Builder(other);
+  }
+  
+  /** Creates a new RecordPojo RecordBuilder by copying an existing RecordPojo 
instance */
+  public static org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
newBuilder(org.apache.pig.builtin.avro.code.java.RecordPojo other) {
+    return new org.apache.pig.builtin.avro.code.java.RecordPojo.Builder(other);
+  }
+  
+  /**
+   * RecordBuilder for RecordPojo instances.
+   */
+  public static class Builder extends 
org.apache.avro.specific.SpecificRecordBuilderBase<RecordPojo>
+    implements org.apache.avro.data.RecordBuilder<RecordPojo> {
+
+    private java.lang.CharSequence key;
+    private int intValue;
+    private long longValue;
+    private boolean booleanValue;
+    private float floatValue;
+    private double doubleValue;
+    private java.nio.ByteBuffer bytesValue;
+    private java.lang.Void nullValue;
+
+    /** Creates a new Builder */
+    private Builder() {
+      super(org.apache.pig.builtin.avro.code.java.RecordPojo.SCHEMA$);
+    }
+    
+    /** Creates a Builder by copying an existing Builder */
+    private Builder(org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
other) {
+      super(other);
+    }
+    
+    /** Creates a Builder by copying an existing RecordPojo instance */
+    private Builder(org.apache.pig.builtin.avro.code.java.RecordPojo other) {
+            super(org.apache.pig.builtin.avro.code.java.RecordPojo.SCHEMA$);
+      if (isValidValue(fields()[0], other.key)) {
+        this.key = data().deepCopy(fields()[0].schema(), other.key);
+        fieldSetFlags()[0] = true;
+      }
+      if (isValidValue(fields()[1], other.intValue)) {
+        this.intValue = data().deepCopy(fields()[1].schema(), other.intValue);
+        fieldSetFlags()[1] = true;
+      }
+      if (isValidValue(fields()[2], other.longValue)) {
+        this.longValue = data().deepCopy(fields()[2].schema(), 
other.longValue);
+        fieldSetFlags()[2] = true;
+      }
+      if (isValidValue(fields()[3], other.booleanValue)) {
+        this.booleanValue = data().deepCopy(fields()[3].schema(), 
other.booleanValue);
+        fieldSetFlags()[3] = true;
+      }
+      if (isValidValue(fields()[4], other.floatValue)) {
+        this.floatValue = data().deepCopy(fields()[4].schema(), 
other.floatValue);
+        fieldSetFlags()[4] = true;
+      }
+      if (isValidValue(fields()[5], other.doubleValue)) {
+        this.doubleValue = data().deepCopy(fields()[5].schema(), 
other.doubleValue);
+        fieldSetFlags()[5] = true;
+      }
+      if (isValidValue(fields()[6], other.bytesValue)) {
+        this.bytesValue = data().deepCopy(fields()[6].schema(), 
other.bytesValue);
+        fieldSetFlags()[6] = true;
+      }
+      if (isValidValue(fields()[7], other.nullValue)) {
+        this.nullValue = data().deepCopy(fields()[7].schema(), 
other.nullValue);
+        fieldSetFlags()[7] = true;
+      }
+    }
+
+    /** Gets the value of the 'key' field */
+    public java.lang.CharSequence getKey() {
+      return key;
+    }
+    
+    /** Sets the value of the 'key' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setKey(java.lang.CharSequence value) {
+      validate(fields()[0], value);
+      this.key = value;
+      fieldSetFlags()[0] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'key' field has been set */
+    public boolean hasKey() {
+      return fieldSetFlags()[0];
+    }
+    
+    /** Clears the value of the 'key' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder clearKey() 
{
+      key = null;
+      fieldSetFlags()[0] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'intValue' field */
+    public java.lang.Integer getIntValue() {
+      return intValue;
+    }
+    
+    /** Sets the value of the 'intValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setIntValue(int value) {
+      validate(fields()[1], value);
+      this.intValue = value;
+      fieldSetFlags()[1] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'intValue' field has been set */
+    public boolean hasIntValue() {
+      return fieldSetFlags()[1];
+    }
+    
+    /** Clears the value of the 'intValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearIntValue() {
+      fieldSetFlags()[1] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'longValue' field */
+    public java.lang.Long getLongValue() {
+      return longValue;
+    }
+    
+    /** Sets the value of the 'longValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setLongValue(long value) {
+      validate(fields()[2], value);
+      this.longValue = value;
+      fieldSetFlags()[2] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'longValue' field has been set */
+    public boolean hasLongValue() {
+      return fieldSetFlags()[2];
+    }
+    
+    /** Clears the value of the 'longValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearLongValue() {
+      fieldSetFlags()[2] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'booleanValue' field */
+    public java.lang.Boolean getBooleanValue() {
+      return booleanValue;
+    }
+    
+    /** Sets the value of the 'booleanValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setBooleanValue(boolean value) {
+      validate(fields()[3], value);
+      this.booleanValue = value;
+      fieldSetFlags()[3] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'booleanValue' field has been set */
+    public boolean hasBooleanValue() {
+      return fieldSetFlags()[3];
+    }
+    
+    /** Clears the value of the 'booleanValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearBooleanValue() {
+      fieldSetFlags()[3] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'floatValue' field */
+    public java.lang.Float getFloatValue() {
+      return floatValue;
+    }
+    
+    /** Sets the value of the 'floatValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setFloatValue(float value) {
+      validate(fields()[4], value);
+      this.floatValue = value;
+      fieldSetFlags()[4] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'floatValue' field has been set */
+    public boolean hasFloatValue() {
+      return fieldSetFlags()[4];
+    }
+    
+    /** Clears the value of the 'floatValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearFloatValue() {
+      fieldSetFlags()[4] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'doubleValue' field */
+    public java.lang.Double getDoubleValue() {
+      return doubleValue;
+    }
+    
+    /** Sets the value of the 'doubleValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setDoubleValue(double value) {
+      validate(fields()[5], value);
+      this.doubleValue = value;
+      fieldSetFlags()[5] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'doubleValue' field has been set */
+    public boolean hasDoubleValue() {
+      return fieldSetFlags()[5];
+    }
+    
+    /** Clears the value of the 'doubleValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearDoubleValue() {
+      fieldSetFlags()[5] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'bytesValue' field */
+    public java.nio.ByteBuffer getBytesValue() {
+      return bytesValue;
+    }
+    
+    /** Sets the value of the 'bytesValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setBytesValue(java.nio.ByteBuffer value) {
+      validate(fields()[6], value);
+      this.bytesValue = value;
+      fieldSetFlags()[6] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'bytesValue' field has been set */
+    public boolean hasBytesValue() {
+      return fieldSetFlags()[6];
+    }
+    
+    /** Clears the value of the 'bytesValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearBytesValue() {
+      bytesValue = null;
+      fieldSetFlags()[6] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'nullValue' field */
+    public java.lang.Void getNullValue() {
+      return nullValue;
+    }
+    
+    /** Sets the value of the 'nullValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
setNullValue(java.lang.Void value) {
+      validate(fields()[7], value);
+      this.nullValue = value;
+      fieldSetFlags()[7] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'nullValue' field has been set */
+    public boolean hasNullValue() {
+      return fieldSetFlags()[7];
+    }
+    
+    /** Clears the value of the 'nullValue' field */
+    public org.apache.pig.builtin.avro.code.java.RecordPojo.Builder 
clearNullValue() {
+      nullValue = null;
+      fieldSetFlags()[7] = false;
+      return this;
+    }
+
+    @Override
+    public RecordPojo build() {
+      try {
+        RecordPojo record = new RecordPojo();
+        record.key = fieldSetFlags()[0] ? this.key : (java.lang.CharSequence) 
defaultValue(fields()[0]);
+        record.intValue = fieldSetFlags()[1] ? this.intValue : 
(java.lang.Integer) defaultValue(fields()[1]);
+        record.longValue = fieldSetFlags()[2] ? this.longValue : 
(java.lang.Long) defaultValue(fields()[2]);
+        record.booleanValue = fieldSetFlags()[3] ? this.booleanValue : 
(java.lang.Boolean) defaultValue(fields()[3]);
+        record.floatValue = fieldSetFlags()[4] ? this.floatValue : 
(java.lang.Float) defaultValue(fields()[4]);
+        record.doubleValue = fieldSetFlags()[5] ? this.doubleValue : 
(java.lang.Double) defaultValue(fields()[5]);
+        record.bytesValue = fieldSetFlags()[6] ? this.bytesValue : 
(java.nio.ByteBuffer) defaultValue(fields()[6]);
+        record.nullValue = fieldSetFlags()[7] ? this.nullValue : 
(java.lang.Void) defaultValue(fields()[7]);
+        return record;
+      } catch (Exception e) {
+        throw new org.apache.avro.AvroRuntimeException(e);
+      }
+    }
+  }
+}

Added: pig/trunk/test/org/apache/pig/builtin/avro/schema/RecordPojo.avsc
URL: 
http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/builtin/avro/schema/RecordPojo.avsc?rev=1685138&view=auto
==============================================================================
--- pig/trunk/test/org/apache/pig/builtin/avro/schema/RecordPojo.avsc (added)
+++ pig/trunk/test/org/apache/pig/builtin/avro/schema/RecordPojo.avsc Fri Jun 
12 17:25:30 2015
@@ -0,0 +1,16 @@
+{
+  "name" : "RecordPojo",
+  "namespace" : "org.apache.pig.builtin.avro.code.java",
+  "type" : "record",
+  "doc" : "to test a generated Avro Java class",
+  "fields" : [
+    {"name" : "key", "type" : "string"},
+    {"name" : "intValue", "type" : "int"},
+    {"name" : "longValue", "type" : "long"},
+    {"name" : "booleanValue", "type" : "boolean"},
+    {"name" : "floatValue", "type" : "float"},
+    {"name" : "doubleValue", "type" : "double"},
+    {"name" : "bytesValue", "type" : "bytes"},
+    {"name" : "nullValue", "type" : "null"}    
+  ]
+}
\ No newline at end of file


Reply via email to