Example #1
0
 @Test
 public void testPairs() throws Exception {
   AvroType<Pair<String, String>> at = Avros.pairs(Avros.strings(), Avros.strings());
   Pair<String, String> j = Pair.of("a", "b");
   GenericData.Record w = new GenericData.Record(at.getSchema());
   w.put(0, new Utf8("a"));
   w.put(1, new Utf8("b"));
   testInputOutputFn(at, j, w);
 }
Example #2
0
 @Test
 public void testCollections() throws Exception {
   Collection<String> j = Lists.newArrayList();
   j.add("a");
   j.add("b");
   Schema collectionSchema = Schema.createArray(Avros.strings().getSchema());
   GenericData.Array<Utf8> w = new GenericData.Array<Utf8>(2, collectionSchema);
   w.add(new Utf8("a"));
   w.add(new Utf8("b"));
   testInputOutputFn(Avros.collections(Avros.strings()), j, w);
 }
Example #3
0
 @Test
 @SuppressWarnings("rawtypes")
 public void testTriples() throws Exception {
   AvroType at = Avros.triples(Avros.strings(), Avros.strings(), Avros.strings());
   Tuple3 j = Tuple3.of("a", "b", "c");
   GenericData.Record w = new GenericData.Record(at.getSchema());
   w.put(0, new Utf8("a"));
   w.put(1, new Utf8("b"));
   w.put(2, new Utf8("c"));
   testInputOutputFn(at, j, w);
 }
Example #4
0
 @Test
 @SuppressWarnings("rawtypes")
 public void testTableOf() throws Exception {
   AvroType at = Avros.tableOf(Avros.strings(), Avros.strings());
   Pair<String, String> j = Pair.of("a", "b");
   org.apache.avro.mapred.Pair w = new org.apache.avro.mapred.Pair(at.getSchema());
   w.put(0, new Utf8("a"));
   w.put(1, new Utf8("b"));
   // TODO update this after resolving the o.a.a.m.Pair.equals issue
   initialize(at);
   assertEquals(j, at.getInputMapFn().map(w));
   org.apache.avro.mapred.Pair converted =
       (org.apache.avro.mapred.Pair) at.getOutputMapFn().map(j);
   assertEquals(w.key(), converted.key());
   assertEquals(w.value(), converted.value());
 }
Example #5
0
 @Test
 public void testPairEquals() throws Exception {
   AvroType<Pair<Long, ByteBuffer>> at1 = Avros.pairs(Avros.longs(), Avros.bytes());
   AvroType<Pair<Long, ByteBuffer>> at2 = Avros.pairs(Avros.longs(), Avros.bytes());
   assertEquals(at1, at2);
   assertEquals(at1.hashCode(), at2.hashCode());
 }
Example #6
0
  /**
   * Determine if the wrapped type is a specific data avro type or wraps one.
   *
   * @return true if the wrapped type is a specific data type or wraps one
   */
  public boolean hasSpecific() {
    if (Avros.isPrimitive(this)) {
      return false;
    }

    if (!this.subTypes.isEmpty()) {
      for (PType<?> subType : this.subTypes) {
        AvroType<?> atype = (AvroType<?>) subType;
        if (atype.hasSpecific()) {
          return true;
        }
      }
      return false;
    }

    return SpecificRecord.class.isAssignableFrom(typeClass);
  }
Example #7
0
  /**
   * Determine if the wrapped type is a reflection-based avro type or wraps one.
   *
   * @return true if the wrapped type is a reflection-based type or wraps one.
   */
  public boolean hasReflect() {
    if (Avros.isPrimitive(this)) {
      return false;
    }

    if (!this.subTypes.isEmpty()) {
      for (PType<?> subType : this.subTypes) {
        if (((AvroType<?>) subType).hasReflect()) {
          return true;
        }
      }
      return false;
    }

    return !(typeClass.equals(GenericData.Record.class)
        || SpecificRecord.class.isAssignableFrom(typeClass));
  }
Example #8
0
 @Test
 public void testBytes() throws Exception {
   byte[] bytes = new byte[] {17, 26, -98};
   ByteBuffer bb = ByteBuffer.wrap(bytes);
   testInputOutputFn(Avros.bytes(), bb, bb);
 }
Example #9
0
 @Test
 public void testBooleans() throws Exception {
   boolean j = true;
   testInputOutputFn(Avros.booleans(), j, j);
 }
Example #10
0
 @Test
 public void testDoubles() throws Exception {
   double j = Double.MIN_VALUE;
   testInputOutputFn(Avros.doubles(), j, j);
 }
Example #11
0
 @Test
 public void testFloats() throws Exception {
   float j = Float.MIN_VALUE;
   testInputOutputFn(Avros.floats(), j, j);
 }
Example #12
0
 @Test
 public void testLongs() throws Exception {
   long j = Long.MAX_VALUE;
   testInputOutputFn(Avros.longs(), j, j);
 }
Example #13
0
 @Test
 public void testInts() throws Exception {
   int j = 55;
   testInputOutputFn(Avros.ints(), j, j);
 }
Example #14
0
 @Test
 public void testStrings() throws Exception {
   String s = "abc";
   Utf8 w = new Utf8(s);
   testInputOutputFn(Avros.strings(), s, w);
 }
Example #15
0
 @Test
 public void testNulls() throws Exception {
   Void n = null;
   testInputOutputFn(Avros.nulls(), n, n);
 }