avro-resolution_canonical_form 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e533fe17ac1e1efd5276ab07eb8f26830f0b93bee15e78465a275f297510f76e
4
- data.tar.gz: 943b99539ce570a2dd7999d60aa2ec364d5e43f4e04581acde19735b694c7bcd
3
+ metadata.gz: 92db806c8c64c020593f72c0915c506a6f644f732025e1b1188a6312999a1b7c
4
+ data.tar.gz: 352466440aa35ee0743aca9880b974c2a60db65e9b0326e985c42cdda3c47a35
5
5
  SHA512:
6
- metadata.gz: 993c1ba85a0c80e1498d0f8a90fdcac6aec0d22dd3a72bdf37ed5756eeeb5df29b5a02766363efc6fdfa5b364b654c685eb81edcd88ecd25d3d4c4fe5a1ab5b1
7
- data.tar.gz: 9577dc0b1e02ae7f87a162ee86273d26146daa9fa322e95bec31e0b0ab1c89bc9ced1c1ff64dc183427f390283b2574eae0ab5cb761fd47b54abc0b16ab4ff9d
6
+ metadata.gz: d33a9ce1bb91751e437c15c379afc95bd0d7249b32f3d88be6a2c24ed9e5bb64de38927a90cdaab06fca39391c608a07a066222bc41e9dd424ad6c84432d1af9
7
+ data.tar.gz: 3597d4ebb038f45750aeb926b099bdb0f7cd07c6e7458f4f398507200090392f66cf026df28098c4daa914f7726a0066df4525b836c74cee369a803408f77c95
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.4.6
4
- - 2.5.5
5
- - 2.6.3
3
+ - 2.5.8
4
+ - 2.6.6
5
+ - 2.7.1
6
6
  before_install: gem install bundler -v 2.0.1 --no-document
7
7
  before_script:
8
8
  - bundle exec appraisal install --jobs=3
data/Appraisals CHANGED
@@ -1,7 +1,3 @@
1
- appraise 'avro-patches-0.x' do
2
- gem 'avro-patches', '< 1.0.0'
3
- end
4
-
5
1
  appraise 'avro-patches-1.x' do
6
2
  gem 'avro-patches', '>= 1.0.0'
7
3
  end
@@ -1,5 +1,11 @@
1
1
  # avro-resolution_canonical_form
2
2
 
3
+ ## v0.3.0
4
+ - Require Avro v1.10.
5
+ - Include aliases, enum defaults, and decimal logical types in the resolution
6
+ canonical form. Schemas that use any of these parts of the Avro spec will
7
+ get a different fingerprint with this version.
8
+
3
9
  ## v0.2.1
4
10
  - Restrict to `avro-patches` versions < 2.0.0.
5
11
 
data/README.md CHANGED
@@ -23,12 +23,14 @@ Or install it yourself as:
23
23
 
24
24
  ## Resolution Canonical Form
25
25
 
26
- The Resolution Canonical Form extends the [Parsing Canonical Form](http://avro.apache.org/docs/1.8.1/spec.html#Parsing+Canonical+Form+for+Schemas)
27
- to include `default` and `aliases` attributes:
26
+ The Resolution Canonical Form extends the [Parsing Canonical Form](http://avro.apache.org/docs/1.10.0/spec.html#Parsing+Canonical+Form+for+Schemas)
27
+ to include `default` and `aliases` attributes and logical type for decimals:
28
28
 
29
+ * [STRIP] Keep only attributes that are relevant to resolution, which are:
30
+ `name, type, fields, symbols, items, values, size, default, aliases, logical_type(=decimal), precision, scale`
29
31
  * [ORDER] Order the appearance of fields in JSON objects as follows:
30
32
  `name, type, fields, symbols, items, values, size, default, aliases`
31
- * [ALIASES] [Aliases](http://avro.apache.org/docs/1.8.1/spec.html#Aliases) for
33
+ * [ALIASES] [Aliases](http://avro.apache.org/docs/1.10.0/spec.html#Aliases) for
32
34
  named types and fields are converted to their fullname, using applicable
33
35
  namespace, and sorted.
34
36
 
@@ -67,7 +69,7 @@ schema = Avro::Schema.parse(<<-JSON)
67
69
  JSON
68
70
 
69
71
  Avro::ResolutionCanonicalForm.to_resolution_form(schema)
70
- #=> {"name":"example.dimensions","type":"record","fields":[{"name":"height","type":"int","default":1},{"name":"width","type":"int"}]}
72
+ #=> => "{\"name\":\"example.dimensions\",\"type\":\"record\",\"fields\":[{\"name\":\"height\",\"type\":\"int\",\"default\":1},{\"name\":\"width\",\"type\":\"int\",\"aliases\":[\"across\"]}],\"aliases\":[\"eg.sizing\",\"example.dims\"]}"
71
73
  ```
72
74
 
73
75
  A new method, `#sha256_resolution_fingerprint`, is added to `Avro::Schema` to
@@ -77,7 +79,7 @@ the existing `#sha256_fingerprint` which is based on the Parsing Canonical Form.
77
79
  ```ruby
78
80
  schema.sha256_resolution_fingerprint
79
81
 
80
- #=> 80361294467930602613800428579400567035362599364974249578710466785512094641526
82
+ #=> 71676413924523555041213790831440929350080614901361467355865523343334332562796
81
83
  ```
82
84
 
83
85
  ## Development
@@ -35,5 +35,20 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'salsify_rubocop', '~> 0.46.0'
36
36
  spec.add_development_dependency 'overcommit'
37
37
  spec.add_development_dependency 'simplecov'
38
+
39
+ spec.add_runtime_dependency 'avro', '~> 1.10.0'
38
40
  spec.add_runtime_dependency 'avro-patches', '< 2.0.0'
41
+
42
+ spec.post_install_message = %(
43
+ avro-resolution_canonical_form now requires Avro v1.10.
44
+
45
+ New features in Avro Ruby v1.10 are now included in the canonical form:
46
+ - aliases
47
+ - enum defaults
48
+ - decimal logical types
49
+
50
+ Schemas that use any of these features will get a different fingerprint with
51
+ this version. For projects that only use Ruby, use of these features is unlikely
52
+ as they were previously unsupported.
53
+ )
39
54
  end
@@ -1,3 +1,3 @@
1
1
  module AvroResolutionCanonicalForm
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -2,6 +2,8 @@ require 'avro-patches'
2
2
 
3
3
  module Avro
4
4
  class ResolutionCanonicalForm < SchemaNormalization
5
+ DECIMAL_LOGICAL_TYPE = 'decimal'.freeze
6
+
5
7
  def self.to_resolution_form(schema)
6
8
  new.to_resolution_form(schema)
7
9
  end
@@ -12,20 +14,46 @@ module Avro
12
14
 
13
15
  private
14
16
 
15
- # TODO: include aliases once the avro Ruby gem supports them
16
- # Note: permitted values for defaults are not enforced here.
17
- # That should be done at the schema level, and is not done currently
18
- # in the Avro Ruby gem
17
+ def normalize_schema(schema)
18
+ if schema.type_sym == :bytes && schema.logical_type == DECIMAL_LOGICAL_TYPE
19
+ add_logical_type(schema, type: schema.type)
20
+ else
21
+ super
22
+ end
23
+ end
24
+
19
25
  def normalize_field(field)
20
- default_value = if field.default?
21
- { default: field.default }
22
- else
23
- {}
24
- end
25
- super.merge(default_value)
26
+ extensions = {}
27
+ extensions[:default] = field.default if field.default?
28
+ if field.aliases && !field.aliases.empty?
29
+ extensions[:aliases] = field.aliases.sort
30
+ end
31
+
32
+ super.merge(extensions)
26
33
  end
27
34
 
28
- # TODO: Override normalize_named_type once the Avro Ruby gem supports aliases
29
- # def normalized_named_type(schema, attributes = {})
35
+ def add_logical_type(schema, serialized)
36
+ if schema.logical_type == DECIMAL_LOGICAL_TYPE
37
+ extensions = { logicalType: DECIMAL_LOGICAL_TYPE }
38
+ extensions[:precision] = schema.precision if schema.respond_to?(:precision) && schema.precision
39
+ extensions[:scale] = schema.scale if schema.respond_to?(:scale) && schema.scale
40
+ serialized.merge(extensions)
41
+ else
42
+ serialized
43
+ end
44
+ end
45
+
46
+ def normalize_named_type(schema, attributes = {})
47
+ extensions = {}
48
+ if schema.respond_to?(:default)
49
+ # For enum defaults
50
+ extensions[:default] = schema.default unless schema.default.nil?
51
+ end
52
+
53
+ aliases = schema.fullname_aliases
54
+ extensions[:aliases] = aliases.sort unless aliases.empty?
55
+ extensions = add_logical_type(schema, extensions)
56
+ super.merge(extensions)
57
+ end
30
58
  end
31
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avro-resolution_canonical_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salsify, Inc
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-22 00:00:00.000000000 Z
11
+ date: 2020-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: avro
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.10.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.10.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: avro-patches
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -156,7 +170,18 @@ licenses:
156
170
  - MIT
157
171
  metadata:
158
172
  allowed_push_host: https://rubygems.org
159
- post_install_message:
173
+ post_install_message: |2
174
+
175
+ avro-resolution_canonical_form now requires Avro v1.10.
176
+
177
+ New features in Avro Ruby v1.10 are now included in the canonical form:
178
+ - aliases
179
+ - enum defaults
180
+ - decimal logical types
181
+
182
+ Schemas that use any of these features will get a different fingerprint with
183
+ this version. For projects that only use Ruby, use of these features is unlikely
184
+ as they were previously unsupported.
160
185
  rdoc_options: []
161
186
  require_paths:
162
187
  - lib
@@ -171,9 +196,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
196
  - !ruby/object:Gem::Version
172
197
  version: '0'
173
198
  requirements: []
174
- rubyforge_project:
175
- rubygems_version: 2.7.9
176
- signing_key:
199
+ rubyforge_project:
200
+ rubygems_version: 2.7.6.2
201
+ signing_key:
177
202
  specification_version: 4
178
203
  summary: Unique identification of Avro schemas for schema resolution
179
204
  test_files: []