[prev in list] [next in list] [prev in thread] [next in thread]
List: avro-commits
Subject: svn commit: r1495955 - in /avro/trunk: CHANGES.txt lang/c++/impl/json/JsonIO.cc lang/c++/impl/json/J
From: thiru () apache ! org
Date: 2013-06-24 8:37:43
Message-ID: 20130624083744.373CF23889EC () eris ! apache ! org
[Download RAW message or body]
Author: thiru
Date: Mon Jun 24 08:37:43 2013
New Revision: 1495955
URL: http://svn.apache.org/r1495955
Log:
AVRO-1172. Avro C++ Json Decoder: Double cannot be decoded
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/c++/impl/json/JsonIO.cc
avro/trunk/lang/c++/impl/json/JsonIO.hh
avro/trunk/lang/c++/test/CodecTests.cc
Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1495955&r1=1495954&r2=1495955&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Mon Jun 24 08:37:43 2013
@@ -104,6 +104,8 @@ Trunk (not yet released)
AVRO-1346. C++: schema parser cannot parse verbose primitive types (Skye \
Wanderman-Milne via thiru)
+ AVRO-1171. Avro C++ Json Decoder: Double cannot be decoded (Sam Overend via \
thiru) +
Avro 1.7.4 (22 February 2012)
NEW FEATURES
Modified: avro/trunk/lang/c++/impl/json/JsonIO.cc
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c%2B%2B/impl/json/JsonIO.cc?rev=1495955&r1=1495954&r2=1495955&view=diff
==============================================================================
--- avro/trunk/lang/c++/impl/json/JsonIO.cc (original)
+++ avro/trunk/lang/c++/impl/json/JsonIO.cc Mon Jun 24 08:37:43 2013
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+#include "boost/math/special_functions/fpclassify.hpp"
#include "JsonIO.hh"
namespace avro {
@@ -49,13 +50,20 @@ char JsonParser::next()
void JsonParser::expectToken(Token tk)
{
if (advance() != tk) {
- if (tk == tkDouble && cur() == tkString
- && (sv == "Infinity" || sv == "-Infinity" || sv == "NaN")) {
- curToken = tkDouble;
- dv = sv == "Infinity" ? std::numeric_limits<double>::infinity() :
- sv == "-Infinity" ? -std::numeric_limits<double>::infinity() :
- std::numeric_limits<double>::quiet_NaN();
- return;
+ if (tk == tkDouble) {
+ if(cur() == tkString
+ && (sv == "Infinity" || sv == "-Infinity" || sv == "NaN")) {
+ curToken = tkDouble;
+ dv = sv == "Infinity" ?
+ std::numeric_limits<double>::infinity() :
+ sv == "-Infinity" ?
+ -std::numeric_limits<double>::infinity() :
+ std::numeric_limits<double>::quiet_NaN();
+ return;
+ } else if (cur() == tkLong) {
+ dv = double(lv);
+ return;
+ }
}
ostringstream oss;
oss << "Incorrect token in the stream. Expected: "
@@ -343,6 +351,24 @@ JsonParser::Token JsonParser::tryLiteral
return tk;
}
+void JsonGenerator::encodeNumber(double t) {
+ sep();
+ std::ostringstream oss;
+ if (boost::math::isfinite(t)) {
+ oss << t;
+ } else if (boost::math::isnan(t)) {
+ oss << "NaN";
+ } else if (t == std::numeric_limits<double>::infinity()) {
+ oss << "Infinity";
+ } else {
+ oss << "-Infinity";
+ }
+ const std::string& s = oss.str();
+ out_.writeBytes(reinterpret_cast<const uint8_t*>(&s[0]), s.size());
+ sep2();
+}
+
+
}
}
Modified: avro/trunk/lang/c++/impl/json/JsonIO.hh
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c%2B%2B/impl/json/JsonIO.hh?rev=1495955&r1=1495954&r2=1495955&view=diff
==============================================================================
--- avro/trunk/lang/c++/impl/json/JsonIO.hh (original)
+++ avro/trunk/lang/c++/impl/json/JsonIO.hh Mon Jun 24 08:37:43 2013
@@ -257,6 +257,8 @@ public:
sep2();
}
+ void encodeNumber(double t);
+
void encodeString(const std::string& s) {
if (top == stMap0) {
top = stKey;
Modified: avro/trunk/lang/c++/test/CodecTests.cc
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c%2B%2B/test/CodecTests.cc?rev=1495955&r1=1495954&r2=1495955&view=diff
==============================================================================
--- avro/trunk/lang/c++/test/CodecTests.cc (original)
+++ avro/trunk/lang/c++/test/CodecTests.cc Mon Jun 24 08:37:43 2013
@@ -1309,6 +1309,7 @@ static const TestData4 data4[] = {
};
#define COUNTOF(x) sizeof(x) / sizeof(x[0])
+#define ENDOF(x) (x) + COUNTOF(x)
#define ADD_TESTS(testSuite, Factory, testFunc, data) \
testSuite.add(BOOST_PARAM_TEST_CASE(&testFunc<Factory>, \
@@ -1470,6 +1471,28 @@ static void testLimitsJsonCodec()
testLimits(jsonEncoder(schema), jsonDecoder(schema));
}
+struct JsonData {
+ const char *schema;
+ const char *json;
+ const char* calls;
+ int depth;
+};
+
+const JsonData jsonData[] = {
+ { "{\"type\": \"double\"}", " 10 ", "D", 1 },
+ { "{\"type\": \"double\"}", " 10.0 ", "D", 1 },
+ { "{\"type\": \"double\"}", " \"Infinity\"", "D", 1 },
+ { "{\"type\": \"double\"}", " \"-Infinity\"", "D", 1 },
+ { "{\"type\": \"double\"}", " \"NaN\"", "D", 1 },
+ { "{\"type\": \"long\"}", " 10 ", "L", 1 },
+};
+
+static void testJson(const JsonData& data)
+{
+ ValidSchema schema = parsing::makeValidSchema(data.schema);
+ EncoderPtr e = jsonEncoder(schema);
+
+}
} // namespace avro
@@ -1483,6 +1506,8 @@ init_unit_test_suite( int argc, char* ar
ts->add(BOOST_TEST_CASE(avro::testStreamLifetimes));
ts->add(BOOST_TEST_CASE(avro::testLimitsBinaryCodec));
ts->add(BOOST_TEST_CASE(avro::testLimitsJsonCodec));
+ ts->add(BOOST_PARAM_TEST_CASE(&avro::testJson, avro::jsonData,
+ ENDOF(avro::jsonData)));
return ts;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic