avro 1.9.0 → 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +2 -2
- data/Manifest +1 -0
- data/NOTICE +1 -1
- data/Rakefile +12 -15
- data/avro.gemspec +11 -11
- data/interop/test_interop.rb +13 -3
- data/lib/avro.rb +15 -3
- data/lib/avro/VERSION.txt +1 -0
- data/lib/avro/data_file.rb +25 -2
- data/lib/avro/io.rb +34 -27
- data/lib/avro/ipc.rb +3 -3
- data/lib/avro/logical_types.rb +1 -1
- data/lib/avro/protocol.rb +1 -1
- data/lib/avro/schema.rb +174 -29
- data/lib/avro/schema_compatibility.rb +25 -14
- data/lib/avro/schema_normalization.rb +1 -1
- data/lib/avro/schema_validator.rb +36 -31
- data/test/case_finder.rb +9 -4
- data/test/random_data.rb +4 -3
- data/test/sample_ipc_client.rb +1 -1
- data/test/sample_ipc_http_client.rb +1 -1
- data/test/sample_ipc_http_server.rb +1 -1
- data/test/sample_ipc_server.rb +1 -1
- data/test/test_datafile.rb +14 -1
- data/test/test_fingerprints.rb +20 -1
- data/test/test_help.rb +1 -1
- data/test/test_io.rb +83 -2
- data/test/test_logical_types.rb +1 -1
- data/test/test_protocol.rb +1 -1
- data/test/test_schema.rb +269 -1
- data/test/test_schema_compatibility.rb +71 -1
- data/test/test_schema_normalization.rb +2 -1
- data/test/test_schema_validator.rb +10 -4
- data/test/test_socket_transport.rb +1 -1
- data/test/tool.rb +4 -4
- metadata +17 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38a2f2d15367014464b4613e0fc80724b345d3b3
|
4
|
+
data.tar.gz: 823aa3ebb6ea719cbd4c94060757a545c7d626a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da4d7d3ecf02bb18c30c044635188ba2b8a34ff13f9450330e850198610ee87f4e9116a79a95366bc23b5e3fb7f70906736d1ff7834e9293825c5c3eba072b9b
|
7
|
+
data.tar.gz: 3194b9379e1ae396acd0a120f583ade7127628d5adf78ac382fcf7215643c69c5341ee0a5f234db56eec3e62070683340b4a21bcff4ba0e2208a832c571f8dc9
|
data/LICENSE
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
Apache License
|
3
3
|
Version 2.0, January 2004
|
4
|
-
|
4
|
+
https://www.apache.org/licenses/
|
5
5
|
|
6
6
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
7
|
|
@@ -193,7 +193,7 @@
|
|
193
193
|
you may not use this file except in compliance with the License.
|
194
194
|
You may obtain a copy of the License at
|
195
195
|
|
196
|
-
|
196
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
197
197
|
|
198
198
|
Unless required by applicable law or agreed to in writing, software
|
199
199
|
distributed under the License is distributed on an "AS IS" BASIS,
|
data/Manifest
CHANGED
data/NOTICE
CHANGED
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# "License"); you may not use this file except in compliance
|
7
7
|
# with the License. You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing, software
|
12
12
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
@@ -17,14 +17,15 @@
|
|
17
17
|
require 'rubygems'
|
18
18
|
require 'echoe'
|
19
19
|
VERSION = File.open('../../share/VERSION.txt').read.sub('-SNAPSHOT', '.pre1').chomp
|
20
|
+
File.write("lib/avro/VERSION.txt", VERSION)
|
20
21
|
Echoe.new('avro', VERSION) do |p|
|
21
22
|
p.author = "Apache Software Foundation"
|
22
23
|
p.email = "dev@avro.apache.org"
|
23
24
|
p.summary = "Apache Avro for Ruby"
|
24
25
|
p.description = "Avro is a data serialization and RPC format"
|
25
|
-
p.url = "
|
26
|
-
p.runtime_dependencies =
|
27
|
-
p.licenses = ["Apache
|
26
|
+
p.url = "https://avro.apache.org/"
|
27
|
+
p.runtime_dependencies = ["multi_json ~>1"]
|
28
|
+
p.licenses = ["Apache-2.0"]
|
28
29
|
end
|
29
30
|
|
30
31
|
t = Rake::TestTask.new(:interop)
|
@@ -38,17 +39,13 @@ task :generate_interop do
|
|
38
39
|
|
39
40
|
schema = Avro::Schema.parse(File.read(SCHEMAS + '/interop.avsc'))
|
40
41
|
r = RandomData.new(schema, ENV['SEED'])
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
Avro::DataFile.open(BUILD + '/interop/data/ruby_deflate.avro', 'w', schema.to_s, :deflate) do |writer|
|
51
|
-
20.times { writer << r.next }
|
42
|
+
Avro::DataFile.codecs.each do |name, codec|
|
43
|
+
next unless codec
|
44
|
+
filename = name == 'null' ? 'ruby.avro' : "ruby_#{name}.avro"
|
45
|
+
path = File.join(BUILD, 'interop/data', filename)
|
46
|
+
Avro::DataFile.open(path, 'w', schema.to_s, name) do |writer|
|
47
|
+
writer << r.next
|
48
|
+
end
|
52
49
|
end
|
53
50
|
end
|
54
51
|
|
data/avro.gemspec
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: avro 1.
|
2
|
+
# stub: avro 1.10.2 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "avro".freeze
|
6
|
-
s.version = "1.
|
6
|
+
s.version = "1.10.2"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Apache Software Foundation".freeze]
|
11
|
-
s.date = "
|
11
|
+
s.date = "2021-03-09"
|
12
12
|
s.description = "Avro is a data serialization and RPC format".freeze
|
13
13
|
s.email = "dev@avro.apache.org".freeze
|
14
|
-
s.extra_rdoc_files = ["CHANGELOG".freeze, "LICENSE".freeze, "lib/avro.rb".freeze, "lib/avro/data_file.rb".freeze, "lib/avro/io.rb".freeze, "lib/avro/ipc.rb".freeze, "lib/avro/logical_types.rb".freeze, "lib/avro/protocol.rb".freeze, "lib/avro/schema.rb".freeze, "lib/avro/schema_compatibility.rb".freeze, "lib/avro/schema_normalization.rb".freeze, "lib/avro/schema_validator.rb".freeze]
|
15
|
-
s.files = ["CHANGELOG".freeze, "LICENSE".freeze, "Manifest".freeze, "NOTICE".freeze, "Rakefile".freeze, "avro.gemspec".freeze, "interop/test_interop.rb".freeze, "lib/avro.rb".freeze, "lib/avro/data_file.rb".freeze, "lib/avro/io.rb".freeze, "lib/avro/ipc.rb".freeze, "lib/avro/logical_types.rb".freeze, "lib/avro/protocol.rb".freeze, "lib/avro/schema.rb".freeze, "lib/avro/schema_compatibility.rb".freeze, "lib/avro/schema_normalization.rb".freeze, "lib/avro/schema_validator.rb".freeze, "test/case_finder.rb".freeze, "test/random_data.rb".freeze, "test/sample_ipc_client.rb".freeze, "test/sample_ipc_http_client.rb".freeze, "test/sample_ipc_http_server.rb".freeze, "test/sample_ipc_server.rb".freeze, "test/test_datafile.rb".freeze, "test/test_fingerprints.rb".freeze, "test/test_help.rb".freeze, "test/test_io.rb".freeze, "test/test_logical_types.rb".freeze, "test/test_protocol.rb".freeze, "test/test_schema.rb".freeze, "test/test_schema_compatibility.rb".freeze, "test/test_schema_normalization.rb".freeze, "test/test_schema_validator.rb".freeze, "test/test_socket_transport.rb".freeze, "test/tool.rb".freeze]
|
16
|
-
s.homepage = "
|
17
|
-
s.licenses = ["Apache
|
14
|
+
s.extra_rdoc_files = ["CHANGELOG".freeze, "LICENSE".freeze, "lib/avro.rb".freeze, "lib/avro/VERSION.txt".freeze, "lib/avro/data_file.rb".freeze, "lib/avro/io.rb".freeze, "lib/avro/ipc.rb".freeze, "lib/avro/logical_types.rb".freeze, "lib/avro/protocol.rb".freeze, "lib/avro/schema.rb".freeze, "lib/avro/schema_compatibility.rb".freeze, "lib/avro/schema_normalization.rb".freeze, "lib/avro/schema_validator.rb".freeze]
|
15
|
+
s.files = ["CHANGELOG".freeze, "LICENSE".freeze, "Manifest".freeze, "NOTICE".freeze, "Rakefile".freeze, "avro.gemspec".freeze, "interop/test_interop.rb".freeze, "lib/avro.rb".freeze, "lib/avro/VERSION.txt".freeze, "lib/avro/data_file.rb".freeze, "lib/avro/io.rb".freeze, "lib/avro/ipc.rb".freeze, "lib/avro/logical_types.rb".freeze, "lib/avro/protocol.rb".freeze, "lib/avro/schema.rb".freeze, "lib/avro/schema_compatibility.rb".freeze, "lib/avro/schema_normalization.rb".freeze, "lib/avro/schema_validator.rb".freeze, "test/case_finder.rb".freeze, "test/random_data.rb".freeze, "test/sample_ipc_client.rb".freeze, "test/sample_ipc_http_client.rb".freeze, "test/sample_ipc_http_server.rb".freeze, "test/sample_ipc_server.rb".freeze, "test/test_datafile.rb".freeze, "test/test_fingerprints.rb".freeze, "test/test_help.rb".freeze, "test/test_io.rb".freeze, "test/test_logical_types.rb".freeze, "test/test_protocol.rb".freeze, "test/test_schema.rb".freeze, "test/test_schema_compatibility.rb".freeze, "test/test_schema_normalization.rb".freeze, "test/test_schema_validator.rb".freeze, "test/test_socket_transport.rb".freeze, "test/tool.rb".freeze]
|
16
|
+
s.homepage = "https://avro.apache.org/".freeze
|
17
|
+
s.licenses = ["Apache-2.0".freeze]
|
18
18
|
s.rdoc_options = ["--line-numbers".freeze, "--title".freeze, "Avro".freeze]
|
19
19
|
s.rubyforge_project = "avro".freeze
|
20
20
|
s.rubygems_version = "2.5.2.1".freeze
|
21
21
|
s.summary = "Apache Avro for Ruby".freeze
|
22
|
-
s.test_files = ["test/
|
22
|
+
s.test_files = ["test/test_schema.rb".freeze, "test/test_socket_transport.rb".freeze, "test/test_io.rb".freeze, "test/test_logical_types.rb".freeze, "test/test_help.rb".freeze, "test/test_datafile.rb".freeze, "test/test_protocol.rb".freeze, "test/test_schema_validator.rb".freeze, "test/test_schema_compatibility.rb".freeze, "test/test_schema_normalization.rb".freeze, "test/test_fingerprints.rb".freeze]
|
23
23
|
|
24
24
|
if s.respond_to? :specification_version then
|
25
25
|
s.specification_version = 4
|
26
26
|
|
27
27
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
28
|
-
s.add_runtime_dependency(%q<multi_json>.freeze, ["
|
28
|
+
s.add_runtime_dependency(%q<multi_json>.freeze, ["~> 1"])
|
29
29
|
else
|
30
|
-
s.add_dependency(%q<multi_json>.freeze, ["
|
30
|
+
s.add_dependency(%q<multi_json>.freeze, ["~> 1"])
|
31
31
|
end
|
32
32
|
else
|
33
|
-
s.add_dependency(%q<multi_json>.freeze, ["
|
33
|
+
s.add_dependency(%q<multi_json>.freeze, ["~> 1"])
|
34
34
|
end
|
35
35
|
end
|
data/interop/test_interop.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
# "License"); you may not use this file except in compliance
|
8
8
|
# with the License. You may obtain a copy of the License at
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
11
11
|
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
@@ -19,12 +19,22 @@ require 'rubygems'
|
|
19
19
|
require 'test/unit'
|
20
20
|
require 'avro'
|
21
21
|
|
22
|
+
CODECS_TO_VALIDATE = ['deflate', 'snappy', 'zstandard'] # The 'null' codec is implicitly included
|
23
|
+
|
22
24
|
class TestInterop < Test::Unit::TestCase
|
23
25
|
HERE = File.expand_path(File.dirname(__FILE__))
|
24
26
|
SHARE = HERE + '/../../../share'
|
25
27
|
SCHEMAS = SHARE + '/test/schemas'
|
26
|
-
|
27
|
-
|
28
|
+
|
29
|
+
files = Dir[HERE + '/../../../build/interop/data/*.avro'].select do |fn|
|
30
|
+
sep, codec = File.basename(fn, '.avro').rpartition('_')[1, 2]
|
31
|
+
sep.empty? || CODECS_TO_VALIDATE.include?(codec)
|
32
|
+
end
|
33
|
+
puts "The following files will be tested:"
|
34
|
+
puts files
|
35
|
+
|
36
|
+
files.each do |fn|
|
37
|
+
define_method("test_read_#{File.basename(fn, '.avro')}") do
|
28
38
|
projection = Avro::Schema.parse(File.read(SCHEMAS+'/interop.avsc'))
|
29
39
|
|
30
40
|
File.open(fn) do |f|
|
data/lib/avro.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# "License"); you may not use this file except in compliance
|
7
7
|
# with the License. You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing, software
|
12
12
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
@@ -22,24 +22,36 @@ require 'stringio'
|
|
22
22
|
require 'zlib'
|
23
23
|
|
24
24
|
module Avro
|
25
|
-
VERSION = "
|
25
|
+
VERSION = File.read("#{__dir__}/avro/VERSION.txt").freeze
|
26
26
|
|
27
27
|
class AvroError < StandardError; end
|
28
28
|
|
29
29
|
class AvroTypeError < Avro::AvroError
|
30
30
|
def initialize(schm=nil, datum=nil, msg=nil)
|
31
|
-
msg ||= "Not a #{schm
|
31
|
+
msg ||= "Not a #{schm}: #{datum}"
|
32
32
|
super(msg)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
class << self
|
37
|
+
attr_writer :disable_enum_symbol_validation
|
37
38
|
attr_writer :disable_field_default_validation
|
39
|
+
attr_writer :disable_schema_name_validation
|
40
|
+
|
41
|
+
def disable_enum_symbol_validation
|
42
|
+
@disable_enum_symbol_validation ||=
|
43
|
+
ENV.fetch('AVRO_DISABLE_ENUM_SYMBOL_VALIDATION', '') != ''
|
44
|
+
end
|
38
45
|
|
39
46
|
def disable_field_default_validation
|
40
47
|
@disable_field_default_validation ||=
|
41
48
|
ENV.fetch('AVRO_DISABLE_FIELD_DEFAULT_VALIDATION', '') != ''
|
42
49
|
end
|
50
|
+
|
51
|
+
def disable_schema_name_validation
|
52
|
+
@disable_schema_name_validation ||=
|
53
|
+
ENV.fetch('AVRO_DISABLE_SCHEMA_NAME_VALIDATION', '') != ''
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
45
57
|
|
@@ -0,0 +1 @@
|
|
1
|
+
1.10.2
|
data/lib/avro/data_file.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# "License"); you may not use this file except in compliance
|
7
7
|
# with the License. You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing, software
|
12
12
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
@@ -316,7 +316,7 @@ module Avro
|
|
316
316
|
def decompress(compressed)
|
317
317
|
# Passing a negative number to Inflate puts it into "raw" RFC1951 mode
|
318
318
|
# (without the RFC1950 header & checksum). See the docs for
|
319
|
-
# inflateInit2 in
|
319
|
+
# inflateInit2 in https://www.zlib.net/manual.html
|
320
320
|
zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
|
321
321
|
data = zstream.inflate(compressed)
|
322
322
|
data << zstream.finish
|
@@ -372,9 +372,32 @@ module Avro
|
|
372
372
|
end
|
373
373
|
end
|
374
374
|
|
375
|
+
class ZstandardCodec
|
376
|
+
def codec_name; 'zstandard'; end
|
377
|
+
|
378
|
+
def decompress(data)
|
379
|
+
load_zstandard!
|
380
|
+
Zstd.decompress(data)
|
381
|
+
end
|
382
|
+
|
383
|
+
def compress(data)
|
384
|
+
load_zstandard!
|
385
|
+
Zstd.compress(data)
|
386
|
+
end
|
387
|
+
|
388
|
+
private
|
389
|
+
|
390
|
+
def load_zstandard!
|
391
|
+
require 'zstd-ruby' unless defined?(Zstd)
|
392
|
+
rescue LoadError
|
393
|
+
raise LoadError, "Zstandard compression is not available, please install the `zstd-ruby` gem."
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
375
397
|
DataFile.register_codec NullCodec
|
376
398
|
DataFile.register_codec DeflateCodec
|
377
399
|
DataFile.register_codec SnappyCodec
|
400
|
+
DataFile.register_codec ZstandardCodec
|
378
401
|
|
379
402
|
# TODO this constant won't be updated if you register another codec.
|
380
403
|
# Deprecated in favor of Avro::DataFile::codecs
|
data/lib/avro/io.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# "License"); you may not use this file except in compliance
|
7
7
|
# with the License. You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing, software
|
12
12
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
@@ -172,7 +172,7 @@ module Avro
|
|
172
172
|
end
|
173
173
|
|
174
174
|
# null is written as zero bytes
|
175
|
-
def write_null(
|
175
|
+
def write_null(_datum)
|
176
176
|
nil
|
177
177
|
end
|
178
178
|
|
@@ -292,7 +292,7 @@ module Avro
|
|
292
292
|
readers_schema.type_adapter.decode(datum)
|
293
293
|
end
|
294
294
|
|
295
|
-
def read_fixed(writers_schema,
|
295
|
+
def read_fixed(writers_schema, _readers_schema, decoder)
|
296
296
|
decoder.read(writers_schema.size)
|
297
297
|
end
|
298
298
|
|
@@ -300,12 +300,12 @@ module Avro
|
|
300
300
|
index_of_symbol = decoder.read_int
|
301
301
|
read_symbol = writers_schema.symbols[index_of_symbol]
|
302
302
|
|
303
|
-
|
304
|
-
|
305
|
-
unless readers_schema.symbols.include?(read_symbol)
|
306
|
-
# 'unset' here
|
303
|
+
if !readers_schema.symbols.include?(read_symbol) && readers_schema.default
|
304
|
+
read_symbol = readers_schema.default
|
307
305
|
end
|
308
306
|
|
307
|
+
# This implementation deviates from the spec by always returning
|
308
|
+
# a symbol.
|
309
309
|
read_symbol
|
310
310
|
end
|
311
311
|
|
@@ -359,26 +359,28 @@ module Avro
|
|
359
359
|
readers_fields_hash = readers_schema.fields_hash
|
360
360
|
read_record = {}
|
361
361
|
writers_schema.fields.each do |field|
|
362
|
-
|
362
|
+
readers_field = readers_fields_hash[field.name]
|
363
|
+
if readers_field
|
363
364
|
field_val = read_data(field.type, readers_field.type, decoder)
|
364
365
|
read_record[field.name] = field_val
|
366
|
+
elsif readers_schema.fields_by_alias.key?(field.name)
|
367
|
+
readers_field = readers_schema.fields_by_alias[field.name]
|
368
|
+
field_val = read_data(field.type, readers_field.type, decoder)
|
369
|
+
read_record[readers_field.name] = field_val
|
365
370
|
else
|
366
371
|
skip_data(field.type, decoder)
|
367
372
|
end
|
368
373
|
end
|
369
374
|
|
370
375
|
# fill in the default values
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
raise AvroError, "Missing data for #{field.type} with no default"
|
380
|
-
end
|
381
|
-
end
|
376
|
+
readers_fields_hash.each do |field_name, field|
|
377
|
+
next if read_record.key?(field_name)
|
378
|
+
|
379
|
+
if field.default?
|
380
|
+
field_val = read_default_value(field.type, field.default)
|
381
|
+
read_record[field.name] = field_val
|
382
|
+
else
|
383
|
+
raise AvroError, "Missing data for #{field.type} with no default"
|
382
384
|
end
|
383
385
|
end
|
384
386
|
|
@@ -468,7 +470,7 @@ module Avro
|
|
468
470
|
decoder.skip(writers_schema.size)
|
469
471
|
end
|
470
472
|
|
471
|
-
def skip_enum(
|
473
|
+
def skip_enum(_writers_schema, decoder)
|
472
474
|
decoder.skip_int
|
473
475
|
end
|
474
476
|
|
@@ -508,6 +510,8 @@ module Avro
|
|
508
510
|
|
509
511
|
# DatumWriter for generic ruby objects
|
510
512
|
class DatumWriter
|
513
|
+
VALIDATION_OPTIONS = { recursive: false, encoded: true }.freeze
|
514
|
+
|
511
515
|
attr_accessor :writers_schema
|
512
516
|
def initialize(writers_schema=nil)
|
513
517
|
@writers_schema = writers_schema
|
@@ -520,7 +524,7 @@ module Avro
|
|
520
524
|
def write_data(writers_schema, logical_datum, encoder)
|
521
525
|
datum = writers_schema.type_adapter.encode(logical_datum)
|
522
526
|
|
523
|
-
unless Schema.validate(writers_schema, datum,
|
527
|
+
unless Schema.validate(writers_schema, datum, VALIDATION_OPTIONS)
|
524
528
|
raise AvroTypeError.new(writers_schema, datum)
|
525
529
|
end
|
526
530
|
|
@@ -545,7 +549,7 @@ module Avro
|
|
545
549
|
end
|
546
550
|
end
|
547
551
|
|
548
|
-
def write_fixed(
|
552
|
+
def write_fixed(_writers_schema, datum, encoder)
|
549
553
|
encoder.write(datum)
|
550
554
|
end
|
551
555
|
|
@@ -578,12 +582,15 @@ module Avro
|
|
578
582
|
end
|
579
583
|
|
580
584
|
def write_union(writers_schema, datum, encoder)
|
581
|
-
index_of_schema =
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
+
index_of_schema = writers_schema.schemas.find_index do |schema|
|
586
|
+
# Optimize away expensive validation calls for the common null type
|
587
|
+
schema.type_sym == :null ? datum.nil? : Schema.validate(schema, datum)
|
588
|
+
end
|
589
|
+
|
590
|
+
unless index_of_schema
|
585
591
|
raise AvroTypeError.new(writers_schema, datum)
|
586
592
|
end
|
593
|
+
|
587
594
|
encoder.write_long(index_of_schema)
|
588
595
|
write_data(writers_schema.schemas[index_of_schema], datum, encoder)
|
589
596
|
end
|
@@ -591,7 +598,7 @@ module Avro
|
|
591
598
|
def write_record(writers_schema, datum, encoder)
|
592
599
|
raise AvroTypeError.new(writers_schema, datum) unless datum.is_a?(Hash)
|
593
600
|
writers_schema.fields.each do |field|
|
594
|
-
write_data(field.type, datum[field.name], encoder)
|
601
|
+
write_data(field.type, datum.key?(field.name) ? datum[field.name] : datum[field.name.to_sym], encoder)
|
595
602
|
end
|
596
603
|
end
|
597
604
|
end # DatumWriter
|
data/lib/avro/ipc.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# "License"); you may not use this file except in compliance
|
7
7
|
# with the License. You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing, software
|
12
12
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
@@ -278,7 +278,7 @@ module Avro::IPC
|
|
278
278
|
response = call(local_message, request)
|
279
279
|
rescue AvroRemoteError => e
|
280
280
|
error = e
|
281
|
-
rescue Exception => e
|
281
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
282
282
|
error = AvroRemoteError.new(e.to_s)
|
283
283
|
end
|
284
284
|
|
@@ -350,7 +350,7 @@ module Avro::IPC
|
|
350
350
|
remote_protocol
|
351
351
|
end
|
352
352
|
|
353
|
-
def call(
|
353
|
+
def call(_local_message, _request)
|
354
354
|
# Actual work done by server: cf. handler in thrift.
|
355
355
|
raise NotImplementedError
|
356
356
|
end
|