You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by th...@apache.org on 2014/06/29 20:29:32 UTC

svn commit: r1606560 - in /avro/trunk: CHANGES.txt lang/c++/impl/NodeImpl.cc lang/c++/test/DataFileTests.cc

Author: thiru
Date: Sun Jun 29 18:29:31 2014
New Revision: 1606560

URL: http://svn.apache.org/r1606560
Log:
AVRO-1352. Schema for fixed types corrupted when writing out in JSON format

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/c++/impl/NodeImpl.cc
    avro/trunk/lang/c++/test/DataFileTests.cc

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1606560&r1=1606559&r2=1606560&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Sun Jun 29 18:29:31 2014
@@ -22,6 +22,8 @@ Trunk (not yet released)
 
     AVRO-1474. C++ resolvind decoder doesn't work when reader schema has more fields than writer schema. (thiru with help from Ramana Suvarapu)
 
+    AVRO-1352. Schema for fixed types corrupted when writing out in JSON format (Steve Roehrs via thiru)
+
   OPTIMIZATIONS
 
     AVRO-1455. Deep copy does not need to create new instances for primitives.

Modified: avro/trunk/lang/c++/impl/NodeImpl.cc
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c%2B%2B/impl/NodeImpl.cc?rev=1606560&r1=1606559&r2=1606560&view=diff
==============================================================================
--- avro/trunk/lang/c++/impl/NodeImpl.cc (original)
+++ avro/trunk/lang/c++/impl/NodeImpl.cc Sun Jun 29 18:29:31 2014
@@ -274,8 +274,8 @@ NodeFixed::printJson(std::ostream &os, i
 {
     os << "{\n";
     os << indent(++depth) << "\"type\": \"fixed\",\n";
-    os << indent(depth) << "\"size\": " << sizeAttribute_.get() << ",\n";
     printName(os, nameAttribute_.get(), depth);
+    os << indent(depth) << "\"size\": " << sizeAttribute_.get() << "\n";
     os << indent(--depth) << '}';
 }
 

Modified: avro/trunk/lang/c++/test/DataFileTests.cc
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c%2B%2B/test/DataFileTests.cc?rev=1606560&r1=1606559&r2=1606560&view=diff
==============================================================================
--- avro/trunk/lang/c++/test/DataFileTests.cc (original)
+++ avro/trunk/lang/c++/test/DataFileTests.cc Sun Jun 29 18:29:31 2014
@@ -95,6 +95,18 @@ template <> struct codec_traits<Double> 
     }
 };
 
+template<> struct codec_traits<uint32_t> {
+    static void encode(Encoder& e, const uint32_t& v) {
+      e.encodeFixed( (uint8_t *) &v,sizeof(uint32_t));
+    }
+
+    static void decode(Decoder& d, uint32_t& v) {
+        std::vector <uint8_t> value;
+        d.decodeFixed(sizeof(uint32_t),value);
+        memcpy(&v,&(value[0]),sizeof(uint32_t));
+    }
+};
+
 }
 
 static ValidSchema makeValidSchema(const char* schema)
@@ -123,6 +135,8 @@ static const char dblsch[] = "{\"type\":
     "\"name\":\"ComplexDouble\", \"fields\": ["
         "{\"name\":\"re\", \"type\":\"double\"}"
     "]}";
+static const char fsch[] = "{\"type\": \"fixed\","
+    "\"name\":\"Fixed_32\", \"size\":4}";
 
 
 string toString(const ValidSchema& s)
@@ -419,6 +433,21 @@ public:
             }
         }
     }
+
+    void testSchemaReadWrite() {
+    uint32_t a=42;
+    {
+            avro::DataFileWriter<uint32_t> df(filename, writerSchema);
+        df.write(a);    
+        }
+
+        {
+        avro::DataFileReader<uint32_t> df(filename);
+        uint32_t b;
+            df.read(b);
+            BOOST_CHECK_EQUAL(b, a);
+    }
+    }
 };
 
 void addReaderTests(test_suite* ts, const shared_ptr<DataFileTest>& t)
@@ -464,6 +493,9 @@ init_unit_test_suite( int argc, char* ar
     shared_ptr<DataFileTest> t6(new DataFileTest("test6.df", dsch, dblsch));
     ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testZip, t6));
 
+    shared_ptr<DataFileTest> t7(new DataFileTest("test7.df",fsch,fsch));
+    ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testSchemaReadWrite,t7));
+    ts->add(BOOST_CLASS_TEST_CASE(&DataFileTest::testCleanup,t7));
 
     return ts;
 }