avro-resolution_canonical_form 0.2.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8523e79c3ed08122f68fb2dfc1f519bf41f22857
4
- data.tar.gz: d4e9400494a912fb338cc77a09903e62514e75d6
2
+ SHA256:
3
+ metadata.gz: e736c50683d624c7b5485a6f88f5781615aea22d511f9dda2e2303f93f4b3da0
4
+ data.tar.gz: 1ae5676258a29dbaa26161eca21fa7293284f6b882b9d9d0938b578ff7d8254a
5
5
  SHA512:
6
- metadata.gz: 6bf8e36a915d5c90039c69a8e6e37aaff7c74f609232db8a3a49fb1ecf775ac0b5f831341528f491be194f7c530cb9f8ae76d2b66833fdbff63a2a2da8a5a4ef
7
- data.tar.gz: 1af0f716d82109181fa44f6a32eb923635885f8df01a74a7b5c6963d59f20dadd95f67bbd805112fa99eb97fabe8ed75751dbe1eedbf9ef3011055de6b365063
6
+ metadata.gz: c7b1c18ea72995dea01d6b294056208d927f311203b4c907b93c1f240e253ea99f2f849d6602881b354f863016bc24801ba23542fdb427b007f0d81400fcc49d
7
+ data.tar.gz: bcc4207e111b01fbe560469b41069dc53f98747618ac4eca1572acd732a9268f51ba444788adee001649a8ef3a019108272c2d7f652bc9803a29b28dd4f0f60a
@@ -0,0 +1,71 @@
1
+ version: 2.1
2
+ jobs:
3
+ lint:
4
+ docker:
5
+ - image: salsify/ruby_ci:2.6.8
6
+ working_directory: ~/avro-resolution_canonical_form
7
+ steps:
8
+ - checkout
9
+ - restore_cache:
10
+ keys:
11
+ - v2-gems-ruby-2.6.8-{{ checksum "avro-resolution_canonical_form.gemspec" }}-{{ checksum "Gemfile" }}
12
+ - v2-gems-ruby-2.6.8-
13
+ - run:
14
+ name: Install Gems
15
+ command: |
16
+ if ! bundle check --path=vendor/bundle; then
17
+ bundle install --path=vendor/bundle --jobs=4 --retry=3
18
+ bundle clean
19
+ fi
20
+ - save_cache:
21
+ key: v2-gems-ruby-2.6.8-{{ checksum "avro-resolution_canonical_form.gemspec" }}-{{ checksum "Gemfile" }}
22
+ paths:
23
+ - "vendor/bundle"
24
+ - "gemfiles/vendor/bundle"
25
+ - run:
26
+ name: Run Rubocop
27
+ command: bundle exec rubocop
28
+ test:
29
+ parameters:
30
+ ruby-version:
31
+ type: string
32
+ docker:
33
+ - image: salsify/ruby_ci:<< parameters.ruby-version >>
34
+ environment:
35
+ CIRCLE_TEST_REPORTS: "test-results"
36
+ working_directory: ~/avro-resolution_canonical_form
37
+ steps:
38
+ - checkout
39
+ - restore_cache:
40
+ keys:
41
+ - v2-gems-ruby-<< parameters.ruby-version >>-{{ checksum "avro-resolution_canonical_form.gemspec" }}-{{ checksum "Gemfile" }}
42
+ - v2-gems-ruby-<< parameters.ruby-version >>-
43
+ - run:
44
+ name: Install Gems
45
+ command: |
46
+ if ! bundle check --path=vendor/bundle; then
47
+ bundle install --path=vendor/bundle --jobs=4 --retry=3
48
+ bundle clean
49
+ fi
50
+ - save_cache:
51
+ key: v2-gems-ruby-<< parameters.ruby-version >>-{{ checksum "avro-resolution_canonical_form.gemspec" }}-{{ checksum "Gemfile" }}
52
+ paths:
53
+ - "vendor/bundle"
54
+ - "gemfiles/vendor/bundle"
55
+ - run:
56
+ name: Run Tests
57
+ command: |
58
+ bundle exec rspec --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/junit.xml --format progress spec
59
+ - store_test_results:
60
+ path: "test-results"
61
+ workflows:
62
+ build:
63
+ jobs:
64
+ - lint
65
+ - test:
66
+ matrix:
67
+ parameters:
68
+ ruby-version:
69
+ - "2.6.8"
70
+ - "2.7.4"
71
+ - "3.0.2"
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /gemfiles/.bundle
11
+ /gemfiles/*.gemfile.lock
data/.rubocop.yml CHANGED
@@ -1,10 +1,12 @@
1
1
  inherit_gem:
2
2
  salsify_rubocop: conf/rubocop.yml
3
3
 
4
- Style/FileName:
4
+ AllCops:
5
+ TargetRubyVersion: 2.6
6
+
7
+ Naming/FileName:
5
8
  Exclude:
6
9
  - 'lib/avro-resolution_canonical_form.rb'
7
10
 
8
11
  RSpec/FilePath:
9
12
  Enabled: false
10
-
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # avro-resolution_canonical_form
2
2
 
3
+ ## v0.5.0
4
+ - Require Avro v1.11.
5
+
6
+ ## v0.4.0
7
+ - Drop dependency on `avro-patches`.
8
+ - Add support for Ruby 3.0.
9
+ - Drop support for Ruby < 2.6.
10
+ - Use frozen string literals.
11
+
12
+ ## v0.3.0
13
+ - Require Avro v1.10.
14
+ - Include aliases, enum defaults, and decimal logical types in the resolution
15
+ canonical form. Schemas that use any of these parts of the Avro spec will
16
+ get a different fingerprint with this version.
17
+
18
+ ## v0.2.1
19
+ - Restrict to `avro-patches` versions < 2.0.0.
20
+
3
21
  ## v0.2.0
4
22
  - Require `avro-patches` instead of `avro-salsify-fork`.
5
23
 
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # override the :github shortcut to be secure by using HTTPS
data/README.md CHANGED
@@ -23,26 +23,17 @@ 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
 
35
- ## Ruby Support
36
-
37
- This currently gem requires the [avro-patches](https://github.com/salsify/avro-patches)
38
- gem.
39
-
40
- ### Aliases
41
-
42
- The Avro Ruby gem, including the avro-patches, does not yet include support
43
- for aliases. Aliases are included in the specification of the Resolution Canonical
44
- Form above, but not yet supported by this gem.
45
-
46
37
  ## Usage
47
38
 
48
39
  `Avro::ResolutionCanonicalForm` subclasses `Avro::SchemaNormalization`
@@ -67,7 +58,7 @@ schema = Avro::Schema.parse(<<-JSON)
67
58
  JSON
68
59
 
69
60
  Avro::ResolutionCanonicalForm.to_resolution_form(schema)
70
- #=> {"name":"example.dimensions","type":"record","fields":[{"name":"height","type":"int","default":1},{"name":"width","type":"int"}]}
61
+ #=> => "{\"name\":\"example.dimensions\",\"type\":\"record\",\"fields\":[{\"name\":\"height\",\"type\":\"int\",\"default\":1},{\"name\":\"width\",\"type\":\"int\",\"aliases\":[\"across\"]}],\"aliases\":[\"eg.sizing\",\"example.dims\"]}"
71
62
  ```
72
63
 
73
64
  A new method, `#sha256_resolution_fingerprint`, is added to `Avro::Schema` to
@@ -77,7 +68,7 @@ the existing `#sha256_fingerprint` which is based on the Parsing Canonical Form.
77
68
  ```ruby
78
69
  schema.sha256_resolution_fingerprint
79
70
 
80
- #=> 80361294467930602613800428579400567035362599364974249578710466785512094641526
71
+ #=> 71676413924523555041213790831440929350080614901361467355865523343334332562796
81
72
  ```
82
73
 
83
74
  ## Development
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
5
  require 'rspec/core/rake_task'
@@ -1,6 +1,6 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'avro-resolution_canonical_form/version'
6
6
 
@@ -28,11 +28,26 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ['lib']
30
30
 
31
- spec.add_development_dependency 'bundler', '~> 1.12'
32
- spec.add_development_dependency 'rake', '~> 10.0'
33
- spec.add_development_dependency 'rspec', '~> 3.4'
34
- spec.add_development_dependency 'salsify_rubocop', '~> 0.46.0'
31
+ spec.required_ruby_version = '>= 2.6'
32
+
33
+ spec.add_development_dependency 'bundler', '~> 2.0'
35
34
  spec.add_development_dependency 'overcommit'
35
+ spec.add_development_dependency 'rake', '~> 13.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.8'
37
+ spec.add_development_dependency 'rspec_junit_formatter'
38
+ spec.add_development_dependency 'salsify_rubocop', '~> 1.0.1'
36
39
  spec.add_development_dependency 'simplecov'
37
- spec.add_runtime_dependency 'avro-patches'
40
+
41
+ spec.add_runtime_dependency 'avro', '~> 1.11.0'
42
+
43
+ spec.post_install_message = %(
44
+ avro-resolution_canonical_form now requires Avro v1.11.
45
+
46
+ Avro Ruby v1.11 adds support for decimal logical type attributes on fixed types and these attributes are
47
+ included in the resolution canonical form.
48
+
49
+ Schemas that use these attributes will get a different fingerprint with
50
+ this version. For projects that only use Ruby, use of these features is unlikely
51
+ as they were previously unsupported, and encoding/decoding fixed decimals is not yet supported.
52
+ )
38
53
  end
@@ -1,7 +1,9 @@
1
- require 'avro-patches'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Avro
4
- class ResolutionCanonicalForm < SchemaNormalization
4
+ class ResolutionCanonicalForm < Avro::SchemaNormalization
5
+ DECIMAL_LOGICAL_TYPE = 'decimal'
6
+
5
7
  def self.to_resolution_form(schema)
6
8
  new.to_resolution_form(schema)
7
9
  end
@@ -12,20 +14,44 @@ 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
+ extensions[:aliases] = field.aliases.sort if field.aliases && !field.aliases.empty?
29
+
30
+ super.merge(extensions)
26
31
  end
27
32
 
28
- # TODO: Override normalize_named_type once the Avro Ruby gem supports aliases
29
- # def normalized_named_type(schema, attributes = {})
33
+ def add_logical_type(schema, serialized)
34
+ if schema.logical_type == DECIMAL_LOGICAL_TYPE
35
+ extensions = { logicalType: DECIMAL_LOGICAL_TYPE }
36
+ extensions[:precision] = schema.precision if schema.respond_to?(:precision) && schema.precision
37
+ extensions[:scale] = schema.scale if schema.respond_to?(:scale) && schema.scale
38
+ serialized.merge(extensions)
39
+ else
40
+ serialized
41
+ end
42
+ end
43
+
44
+ def normalize_named_type(schema, attributes = {})
45
+ extensions = {}
46
+ if schema.respond_to?(:default) && !schema.default.nil?
47
+ # For enum defaults
48
+ extensions[:default] = schema.default
49
+ end
50
+
51
+ aliases = schema.fullname_aliases
52
+ extensions[:aliases] = aliases.sort unless aliases.empty?
53
+ extensions = add_logical_type(schema, extensions)
54
+ super.merge(extensions)
55
+ end
30
56
  end
31
57
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  class Schema
3
5
  # Returns the SHA-256 fingerprint of the Resolution Canonical Form for the
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AvroResolutionCanonicalForm
2
- VERSION = '0.2.0'.freeze
4
+ VERSION = '0.5.0'
3
5
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avro'
1
4
  require 'avro-resolution_canonical_form/version'
2
5
  require 'avro/resolution_canonical_form'
3
6
  require 'avro/resolution_fingerprint'
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.0
4
+ version: 0.5.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: 2017-05-31 00:00:00.000000000 Z
11
+ date: 2021-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,58 +16,58 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.12'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.12'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: overcommit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.4'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.4'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: salsify_rubocop
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.46.0
61
+ version: '3.8'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.46.0
68
+ version: '3.8'
69
69
  - !ruby/object:Gem::Dependency
70
- name: overcommit
70
+ name: rspec_junit_formatter
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: salsify_rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: simplecov
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -95,19 +109,19 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: avro-patches
112
+ name: avro
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: 1.11.0
104
118
  type: :runtime
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ">="
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: 1.11.0
111
125
  description: Unique identification of Avro schemas for schema resolution
112
126
  email:
113
127
  - engineering@salsify.com
@@ -117,11 +131,11 @@ executables:
117
131
  extensions: []
118
132
  extra_rdoc_files: []
119
133
  files:
134
+ - ".circleci/config.yml"
120
135
  - ".gitignore"
121
136
  - ".overcommit.yml"
122
137
  - ".rspec"
123
138
  - ".rubocop.yml"
124
- - ".travis.yml"
125
139
  - CHANGELOG.md
126
140
  - Gemfile
127
141
  - LICENSE.txt
@@ -139,7 +153,16 @@ licenses:
139
153
  - MIT
140
154
  metadata:
141
155
  allowed_push_host: https://rubygems.org
142
- post_install_message:
156
+ post_install_message: |2
157
+
158
+ avro-resolution_canonical_form now requires Avro v1.11.
159
+
160
+ Avro Ruby v1.11 adds support for decimal logical type attributes on fixed types and these attributes are
161
+ included in the resolution canonical form.
162
+
163
+ Schemas that use these attributes will get a different fingerprint with
164
+ this version. For projects that only use Ruby, use of these features is unlikely
165
+ as they were previously unsupported, and encoding/decoding fixed decimals is not yet supported.
143
166
  rdoc_options: []
144
167
  require_paths:
145
168
  - lib
@@ -147,16 +170,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
170
  requirements:
148
171
  - - ">="
149
172
  - !ruby/object:Gem::Version
150
- version: '0'
173
+ version: '2.6'
151
174
  required_rubygems_version: !ruby/object:Gem::Requirement
152
175
  requirements:
153
176
  - - ">="
154
177
  - !ruby/object:Gem::Version
155
178
  version: '0'
156
179
  requirements: []
157
- rubyforge_project:
158
- rubygems_version: 2.6.12
159
- signing_key:
180
+ rubygems_version: 3.0.3
181
+ signing_key:
160
182
  specification_version: 4
161
183
  summary: Unique identification of Avro schemas for schema resolution
162
184
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.3
4
- before_install: gem install bundler -v 1.14.6
5
- script:
6
- - bundle exec rubocop
7
- - bundle exec rspec