You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by jm...@apache.org on 2010/08/26 21:26:30 UTC
svn commit: r989896 - in /avro/trunk: CHANGES.txt lang/ruby/lib/avro/io.rb
lang/ruby/test/test_io.rb
Author: jmhodges
Date: Thu Aug 26 19:26:29 2010
New Revision: 989896
URL: http://svn.apache.org/viewvc?rev=989896&view=rev
Log:
AVRO-633. Ruby: Implement skip_union to correct issues with updating protocols
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/ruby/lib/avro/io.rb
avro/trunk/lang/ruby/test/test_io.rb
Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=989896&r1=989895&r2=989896&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Aug 26 19:26:29 2010
@@ -193,6 +193,9 @@ Avro 1.4.0 (unreleased)
AVRO-510. C: Fix some memory leaks in datafile reader &
writer. (Robert G. Jakabosky via cutting)
+ AVRO-633. Ruby: Implement skip_union to correct issues with
+ updating protocols
+
Avro 1.3.3 (7 June 2010)
IMPROVEMENTS
Modified: avro/trunk/lang/ruby/lib/avro/io.rb
URL: http://svn.apache.org/viewvc/avro/trunk/lang/ruby/lib/avro/io.rb?rev=989896&r1=989895&r2=989896&view=diff
==============================================================================
--- avro/trunk/lang/ruby/lib/avro/io.rb (original)
+++ avro/trunk/lang/ruby/lib/avro/io.rb Thu Aug 26 19:26:29 2010
@@ -500,6 +500,11 @@ module Avro
decoder.skip_int
end
+ def skip_union(writers_schema, decoder)
+ index = decoder.read_long
+ skip_data(writers_schema.schemas[index], decoder)
+ end
+
def skip_array(writers_schema, decoder)
skip_blocks(decoder) { skip_data(writers_schema.items, decoder) }
end
Modified: avro/trunk/lang/ruby/test/test_io.rb
URL: http://svn.apache.org/viewvc/avro/trunk/lang/ruby/test/test_io.rb?rev=989896&r1=989895&r2=989896&view=diff
==============================================================================
--- avro/trunk/lang/ruby/test/test_io.rb (original)
+++ avro/trunk/lang/ruby/test/test_io.rb Thu Aug 26 19:26:29 2010
@@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -232,6 +232,28 @@ EOS
end
end
+ def test_skip_union
+ ["hello", -1, 32, nil].each do |value_to_skip|
+ value_to_read = 6253
+
+ schema = Avro::Schema.parse('["int", "string", "null"]')
+ writer = StringIO.new
+ encoder = Avro::IO::BinaryEncoder.new(writer)
+ datum_writer = Avro::IO::DatumWriter.new(schema)
+ datum_writer.write(value_to_skip, encoder)
+ datum_writer.write(value_to_read, encoder)
+
+ reader = StringIO.new(writer.string)
+ decoder = Avro::IO::BinaryDecoder.new(reader)
+ datum_reader = Avro::IO::DatumReader.new(schema)
+ datum_reader.skip_data(schema, decoder)
+ read_value = datum_reader.read(decoder)
+
+ assert_equal value_to_read, read_value
+ end
+ end
+
+
def test_schema_promotion
promotable_schemas = ['"int"', '"long"', '"float"', '"double"']
incorrect = 0
@@ -310,7 +332,7 @@ EOS
count = 10
random_data = RandomData.new(schm, seed)
-
+
f = File.open(DATAFILE, 'wb')
dw = Avro::DataFile::Writer.new(f, datum_writer(schm), schm)
count.times{ dw << random_data.next }