You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by tj...@apache.org on 2021/01/10 12:46:12 UTC
[avro] branch master updated: AVRO-3000: Avoid unnecessary schema
compatibility checks (#1038)
This is an automated email from the ASF dual-hosted git repository.
tjwp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new bd31cc4 AVRO-3000: Avoid unnecessary schema compatibility checks (#1038)
bd31cc4 is described below
commit bd31cc452dbe8513f9d2f00181d910622dfd4bbe
Author: Joel Turkel <Jt...@salsify.com>
AuthorDate: Sun Jan 10 07:46:06 2021 -0500
AVRO-3000: Avoid unnecessary schema compatibility checks (#1038)
Ruby Avro decoding spends a fair amount of time validating that the
reader and writer schemas are compatible. These checks are
unnecessary for the fairly common case of the reader and writer schemas
being the same Avro::Schema instance.
---
lang/ruby/lib/avro/schema_compatibility.rb | 10 ++++++++--
lang/ruby/test/test_schema_compatibility.rb | 2 ++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/lang/ruby/lib/avro/schema_compatibility.rb b/lang/ruby/lib/avro/schema_compatibility.rb
index 1d5b24e..5926047 100644
--- a/lang/ruby/lib/avro/schema_compatibility.rb
+++ b/lang/ruby/lib/avro/schema_compatibility.rb
@@ -15,6 +15,9 @@
# limitations under the License.
module Avro
module SchemaCompatibility
+ INT_COERCIBLE_TYPES_SYM = [:long, :float, :double].freeze
+ LONG_COERCIBLE_TYPES_SYM = [:float, :double].freeze
+
# Perform a full, recursive check that a datum written using the writers_schema
# can be read using the readers_schema.
def self.can_read?(writers_schema, readers_schema)
@@ -31,6 +34,9 @@ module Avro
# be read using the readers_schema. This check includes matching the types,
# including schema promotion, and matching the full name (including aliases) for named types.
def self.match_schemas(writers_schema, readers_schema)
+ # Bypass deeper checks if the schemas are the same Ruby objects
+ return true if writers_schema.equal?(readers_schema)
+
w_type = writers_schema.type_sym
r_type = readers_schema.type_sym
@@ -62,9 +68,9 @@ module Avro
end
# Handle schema promotion
- if w_type == :int && [:long, :float, :double].include?(r_type)
+ if w_type == :int && INT_COERCIBLE_TYPES_SYM.include?(r_type)
return true
- elsif w_type == :long && [:float, :double].include?(r_type)
+ elsif w_type == :long && LONG_COERCIBLE_TYPES_SYM.include?(r_type)
return true
elsif w_type == :float && r_type == :double
return true
diff --git a/lang/ruby/test/test_schema_compatibility.rb b/lang/ruby/test/test_schema_compatibility.rb
index 926c18d..355c33e 100644
--- a/lang/ruby/test/test_schema_compatibility.rb
+++ b/lang/ruby/test/test_schema_compatibility.rb
@@ -25,7 +25,9 @@ class TestSchemaCompatibility < Test::Unit::TestCase
end
def test_compatible_reader_writer_pairs
+ cached_schema = a_int_record1_schema
[
+ cached_schema, cached_schema,
long_schema, int_schema,
float_schema, int_schema,
float_schema, long_schema,