zjw1111 commented on code in PR #3457: URL: https://github.com/apache/avro/pull/3457#discussion_r2268448376
########## lang/c++/test/DataFileTests.cc: ########## @@ -838,6 +838,81 @@ void testSkipStringZstdCodec() { } #endif +struct Weather { + std::string station; + int64_t time; + int32_t temp; + Weather(const char *station, int64_t time, int32_t temp) + : station(station), time(time), temp(temp) {} + + bool operator==(const Weather &other) const { + return station == other.station && time == other.time && temp == other.temp; + } + friend std::ostream &operator<<(std::ostream &os, const Weather &w) { + return os << w.station << ' ' << w.time << ' ' << w.temp; + } +}; + +namespace avro { +template<> +struct codec_traits<Weather> { + static void decode(Decoder &d, Weather &v) { + avro::decode(d, v.station); + avro::decode(d, v.time); + avro::decode(d, v.temp); + } +}; +} // namespace avro + +void testCompatibility(const char *filename) { + const char *readerSchemaStr = "{" + "\"type\": \"record\", \"name\": \"test.Weather\", \"fields\":[" + "{\"name\": \"station\", \"type\": \"string\", \"order\": \"ignore\"}," + "{\"name\": \"time\", \"type\": \"long\"}," + "{\"name\": \"temp\", \"type\": \"int\"}" + "]}"; + avro::ValidSchema readerSchema = + avro::compileJsonSchemaFromString(readerSchemaStr); + avro::DataFileReader<Weather> df(filename, readerSchema); + + Weather ro("", -1, -1); + BOOST_CHECK_EQUAL(df.read(ro), true); + BOOST_CHECK_EQUAL(ro, Weather("011990-99999", -619524000000L, 0)); + BOOST_CHECK_EQUAL(df.read(ro), true); + BOOST_CHECK_EQUAL(ro, Weather("011990-99999", -619506000000L, 22)); + BOOST_CHECK_EQUAL(df.read(ro), true); + BOOST_CHECK_EQUAL(ro, Weather("011990-99999", -619484400000L, -11)); + BOOST_CHECK_EQUAL(df.read(ro), true); + BOOST_CHECK_EQUAL(ro, Weather("012650-99999", -655531200000L, 111)); + BOOST_CHECK_EQUAL(df.read(ro), true); + BOOST_CHECK_EQUAL(ro, Weather("012650-99999", -655509600000L, 78)); + BOOST_CHECK_EQUAL(df.read(ro), false); +} + +void testCompatibilityNullCodec() { + BOOST_TEST_CHECKPOINT(__func__); + testCompatibility("../../share/test/data/weather.avro"); +} + +void testCompatibilityDeflateCodec() { + BOOST_TEST_CHECKPOINT(__func__); + testCompatibility("../../share/test/data/weather-deflate.avro"); +} + +#ifdef SNAPPY_CODEC_AVAILABLE +void testCompatibilitySnappyCodec() { + BOOST_TEST_CHECKPOINT(__func__); + testCompatibility("../../share/test/data/weather-snappy.avro"); +} +#endif + +#ifdef ZSTD_CODEC_AVAILABLE +void testCompatibilityZstdCodec() { + BOOST_TEST_CHECKPOINT(__func__); + testCompatibility("../../share/test/data/weather-zstd.avro"); Review Comment: The code repository originally had the file `share/test/data/weather.avro`. I rewrote this file using Java Avro with zstd compression. `java -jar ~/avro-tools-1.10.2.jar recodec ./share/test/data/weather.avro ./share/test/data/weather-zstd.avro --codec=zstandard` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@avro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org