avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1601020 - in /avro/trunk: ./ lang/java/thrift/ lang/java/thrift/src/main/java/org/apache/avro/thrift/ lang/java/thrift/src/test/java/org/apache/avro/thrift/ lang/java/thrift/src/test/java/org/apache/avro/thrift/test/ lang/java/thrift/src/t...
Date Fri, 06 Jun 2014 21:56:40 GMT
Author: cutting
Date: Fri Jun  6 21:56:40 2014
New Revision: 1601020

URL: http://svn.apache.org/r1601020
Log:
AVRO-1500. Java: Fix bug in handling of Thrift shorts in unions.  Contributed by Michael Pershyn.

Added:
    avro/trunk/lang/java/thrift/README   (with props)
Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java
    avro/trunk/lang/java/thrift/src/test/java/org/apache/avro/thrift/TestThrift.java
    avro/trunk/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Test.java
    avro/trunk/lang/java/thrift/src/test/thrift/test.thrift

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1601020&r1=1601019&r2=1601020&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Jun  6 21:56:40 2014
@@ -76,6 +76,9 @@ Trunk (not yet released)
     AVRO-1442. Java: Fix ResolvingGrammarGenerator to work with fixed type.
     (Jim Pivarski via cutting)
 
+    AVRO-1500. Java: Fix bug in handling of Thrift shorts in unions.
+    (Michael Pershyn via cutting)
+
 Avro 1.7.6 (15 January 2014)
 
   NEW FEATURES

Added: avro/trunk/lang/java/thrift/README
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/thrift/README?rev=1601020&view=auto
==============================================================================
--- avro/trunk/lang/java/thrift/README (added)
+++ avro/trunk/lang/java/thrift/README Fri Jun  6 21:56:40 2014
@@ -0,0 +1,3 @@
+The trift-generated files are checked-in so that every developer who runs tests need not
have the Thrift compiler installed.
+
+For regeneration of thrift files make sure you have required version of thrift-compiler installed
(0.7) and run `mvn -Pthrift-generate generate-test-sources`

Propchange: avro/trunk/lang/java/thrift/README
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: avro/trunk/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java?rev=1601020&r1=1601019&r2=1601020&view=diff
==============================================================================
--- avro/trunk/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java (original)
+++ avro/trunk/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java Fri Jun
 6 21:56:40 2014
@@ -111,6 +111,15 @@ public class ThriftData extends GenericD
   }
 
   @Override
+  protected String getSchemaName(Object datum) {
+    // support implicit conversion from thrift's i16
+    // to avro INT for thrift's optional fields
+    if (datum instanceof Short)
+      return Schema.Type.INT.getName();
+    return super.getSchemaName(datum);
+  }
+
+  @Override
   protected boolean isRecord(Object datum) {
     return datum instanceof TBase;
   }

Modified: avro/trunk/lang/java/thrift/src/test/java/org/apache/avro/thrift/TestThrift.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/thrift/src/test/java/org/apache/avro/thrift/TestThrift.java?rev=1601020&r1=1601019&r2=1601020&view=diff
==============================================================================
--- avro/trunk/lang/java/thrift/src/test/java/org/apache/avro/thrift/TestThrift.java (original)
+++ avro/trunk/lang/java/thrift/src/test/java/org/apache/avro/thrift/TestThrift.java Fri Jun
 6 21:56:40 2014
@@ -43,6 +43,7 @@ public class TestThrift {
     test.setBoolField(true);
     test.setByteField((byte)2);
     test.setI16Field((short)3);
+    test.setI16OptionalField((short)14);
     test.setI32Field(4);
     test.setI64Field(5L);
     test.setDoubleField(2.0);

Modified: avro/trunk/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Test.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Test.java?rev=1601020&r1=1601019&r2=1601020&view=diff
==============================================================================
--- avro/trunk/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Test.java (original)
+++ avro/trunk/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Test.java Fri Jun
 6 21:56:40 2014
@@ -26,6 +26,7 @@ public class Test implements org.apache.
   private static final org.apache.thrift.protocol.TField BOOL_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("boolField",
org.apache.thrift.protocol.TType.BOOL, (short)1);
   private static final org.apache.thrift.protocol.TField BYTE_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("byteField",
org.apache.thrift.protocol.TType.BYTE, (short)2);
   private static final org.apache.thrift.protocol.TField I16_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("i16Field",
org.apache.thrift.protocol.TType.I16, (short)3);
+  private static final org.apache.thrift.protocol.TField I16_OPTIONAL_FIELD_FIELD_DESC =
new org.apache.thrift.protocol.TField("i16OptionalField", org.apache.thrift.protocol.TType.I16,
(short)15);
   private static final org.apache.thrift.protocol.TField I32_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("i32Field",
org.apache.thrift.protocol.TType.I32, (short)4);
   private static final org.apache.thrift.protocol.TField I64_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("i64Field",
org.apache.thrift.protocol.TType.I64, (short)5);
   private static final org.apache.thrift.protocol.TField DOUBLE_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("doubleField",
org.apache.thrift.protocol.TType.DOUBLE, (short)6);
@@ -41,6 +42,7 @@ public class Test implements org.apache.
   private boolean boolField; // required
   private byte byteField; // required
   private short i16Field; // required
+  private short i16OptionalField; // required
   private int i32Field; // required
   private long i64Field; // required
   private double doubleField; // required
@@ -58,6 +60,7 @@ public class Test implements org.apache.
     BOOL_FIELD((short)1, "boolField"),
     BYTE_FIELD((short)2, "byteField"),
     I16_FIELD((short)3, "i16Field"),
+    I16_OPTIONAL_FIELD((short)15, "i16OptionalField"),
     I32_FIELD((short)4, "i32Field"),
     I64_FIELD((short)5, "i64Field"),
     DOUBLE_FIELD((short)6, "doubleField"),
@@ -93,6 +96,8 @@ public class Test implements org.apache.
           return BYTE_FIELD;
         case 3: // I16_FIELD
           return I16_FIELD;
+        case 15: // I16_OPTIONAL_FIELD
+          return I16_OPTIONAL_FIELD;
         case 4: // I32_FIELD
           return I32_FIELD;
         case 5: // I64_FIELD
@@ -158,10 +163,11 @@ public class Test implements org.apache.
   private static final int __BOOLFIELD_ISSET_ID = 0;
   private static final int __BYTEFIELD_ISSET_ID = 1;
   private static final int __I16FIELD_ISSET_ID = 2;
-  private static final int __I32FIELD_ISSET_ID = 3;
-  private static final int __I64FIELD_ISSET_ID = 4;
-  private static final int __DOUBLEFIELD_ISSET_ID = 5;
-  private BitSet __isset_bit_vector = new BitSet(6);
+  private static final int __I16OPTIONALFIELD_ISSET_ID = 3;
+  private static final int __I32FIELD_ISSET_ID = 4;
+  private static final int __I64FIELD_ISSET_ID = 5;
+  private static final int __DOUBLEFIELD_ISSET_ID = 6;
+  private BitSet __isset_bit_vector = new BitSet(7);
 
   public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
   static {
@@ -172,6 +178,8 @@ public class Test implements org.apache.
         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BYTE)));
     tmpMap.put(_Fields.I16_FIELD, new org.apache.thrift.meta_data.FieldMetaData("i16Field",
org.apache.thrift.TFieldRequirementType.DEFAULT, 
         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I16)));
+    tmpMap.put(_Fields.I16_OPTIONAL_FIELD, new org.apache.thrift.meta_data.FieldMetaData("i16OptionalField",
org.apache.thrift.TFieldRequirementType.OPTIONAL, 
+        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I16)));
     tmpMap.put(_Fields.I32_FIELD, new org.apache.thrift.meta_data.FieldMetaData("i32Field",
org.apache.thrift.TFieldRequirementType.OPTIONAL, 
         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
     tmpMap.put(_Fields.I64_FIELD, new org.apache.thrift.meta_data.FieldMetaData("i64Field",
org.apache.thrift.TFieldRequirementType.DEFAULT, 
@@ -248,6 +256,7 @@ public class Test implements org.apache.
     this.boolField = other.boolField;
     this.byteField = other.byteField;
     this.i16Field = other.i16Field;
+    this.i16OptionalField = other.i16OptionalField;
     this.i32Field = other.i32Field;
     this.i64Field = other.i64Field;
     this.doubleField = other.doubleField;
@@ -310,6 +319,8 @@ public class Test implements org.apache.
     this.byteField = 0;
     setI16FieldIsSet(false);
     this.i16Field = 0;
+    setI16OptionalFieldIsSet(false);
+    this.i16OptionalField = 0;
     setI32FieldIsSet(false);
     this.i32Field = 0;
     setI64FieldIsSet(false);
@@ -392,6 +403,28 @@ public class Test implements org.apache.
     __isset_bit_vector.set(__I16FIELD_ISSET_ID, value);
   }
 
+  public short getI16OptionalField() {
+    return this.i16OptionalField;
+  }
+
+  public void setI16OptionalField(short i16OptionalField) {
+    this.i16OptionalField = i16OptionalField;
+    setI16OptionalFieldIsSet(true);
+  }
+
+  public void unsetI16OptionalField() {
+    __isset_bit_vector.clear(__I16OPTIONALFIELD_ISSET_ID);
+  }
+
+  /** Returns true if field i16OptionalField is set (has been assigned a value) and false
otherwise */
+  public boolean isSetI16OptionalField() {
+    return __isset_bit_vector.get(__I16OPTIONALFIELD_ISSET_ID);
+  }
+
+  public void setI16OptionalFieldIsSet(boolean value) {
+    __isset_bit_vector.set(__I16OPTIONALFIELD_ISSET_ID, value);
+  }
+
   public int getI32Field() {
     return this.i32Field;
   }
@@ -726,6 +759,14 @@ public class Test implements org.apache.
       }
       break;
 
+    case I16_OPTIONAL_FIELD:
+      if (value == null) {
+        unsetI16OptionalField();
+      } else {
+        setI16OptionalField((Short)value);
+      }
+      break;
+
     case I32_FIELD:
       if (value == null) {
         unsetI32Field();
@@ -828,6 +869,9 @@ public class Test implements org.apache.
     case I16_FIELD:
       return Short.valueOf(getI16Field());
 
+    case I16_OPTIONAL_FIELD:
+      return Short.valueOf(getI16OptionalField());
+
     case I32_FIELD:
       return Integer.valueOf(getI32Field());
 
@@ -878,6 +922,8 @@ public class Test implements org.apache.
       return isSetByteField();
     case I16_FIELD:
       return isSetI16Field();
+    case I16_OPTIONAL_FIELD:
+      return isSetI16OptionalField();
     case I32_FIELD:
       return isSetI32Field();
     case I64_FIELD:
@@ -944,6 +990,15 @@ public class Test implements org.apache.
         return false;
     }
 
+    boolean this_present_i16OptionalField = true && this.isSetI16OptionalField();
+    boolean that_present_i16OptionalField = true && that.isSetI16OptionalField();
+    if (this_present_i16OptionalField || that_present_i16OptionalField) {
+      if (!(this_present_i16OptionalField && that_present_i16OptionalField))
+        return false;
+      if (this.i16OptionalField != that.i16OptionalField)
+        return false;
+    }
+
     boolean this_present_i32Field = true && this.isSetI32Field();
     boolean that_present_i32Field = true && that.isSetI32Field();
     if (this_present_i32Field || that_present_i32Field) {
@@ -1089,6 +1144,16 @@ public class Test implements org.apache.
         return lastComparison;
       }
     }
+    lastComparison = Boolean.valueOf(isSetI16OptionalField()).compareTo(typedOther.isSetI16OptionalField());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetI16OptionalField()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.i16OptionalField, typedOther.i16OptionalField);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
     lastComparison = Boolean.valueOf(isSetI32Field()).compareTo(typedOther.isSetI32Field());
     if (lastComparison != 0) {
       return lastComparison;
@@ -1240,6 +1305,14 @@ public class Test implements org.apache.
             org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
           }
           break;
+        case 15: // I16_OPTIONAL_FIELD
+          if (field.type == org.apache.thrift.protocol.TType.I16) {
+            this.i16OptionalField = iprot.readI16();
+            setI16OptionalFieldIsSet(true);
+          } else { 
+            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
+          }
+          break;
         case 4: // I32_FIELD
           if (field.type == org.apache.thrift.protocol.TType.I32) {
             this.i32Field = iprot.readI32();
@@ -1451,6 +1524,11 @@ public class Test implements org.apache.
       this.fooOrBar.write(oprot);
       oprot.writeFieldEnd();
     }
+    if (isSetI16OptionalField()) {
+      oprot.writeFieldBegin(I16_OPTIONAL_FIELD_FIELD_DESC);
+      oprot.writeI16(this.i16OptionalField);
+      oprot.writeFieldEnd();
+    }
     oprot.writeFieldStop();
     oprot.writeStructEnd();
   }
@@ -1471,6 +1549,12 @@ public class Test implements org.apache.
     sb.append("i16Field:");
     sb.append(this.i16Field);
     first = false;
+    if (isSetI16OptionalField()) {
+      if (!first) sb.append(", ");
+      sb.append("i16OptionalField:");
+      sb.append(this.i16OptionalField);
+      first = false;
+    }
     if (isSetI32Field()) {
       if (!first) sb.append(", ");
       sb.append("i32Field:");

Modified: avro/trunk/lang/java/thrift/src/test/thrift/test.thrift
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/thrift/src/test/thrift/test.thrift?rev=1601020&r1=1601019&r2=1601020&view=diff
==============================================================================
--- avro/trunk/lang/java/thrift/src/test/thrift/test.thrift (original)
+++ avro/trunk/lang/java/thrift/src/test/thrift/test.thrift Fri Jun  6 21:56:40 2014
@@ -39,6 +39,7 @@ struct Test {
   1: bool boolField
   2: byte byteField
   3: i16 i16Field
+ 15: optional i16 i16OptionalField
   4: optional i32 i32Field
   5: i64 i64Field
   6: double doubleField



Mime
View raw message