avro-resolution_canonical_form 0.1.0 → 0.4.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: dd4c9bcb8a8a9547bdf86e07f176653c6f652eef
4
- data.tar.gz: e9cdf593af4a7d544730b7f0861af33380a19418
2
+ SHA256:
3
+ metadata.gz: 5bc3f7c52afdd1298ab687f9d68d77c0c9aacf080c5087ed0c89a7f9066e55a7
4
+ data.tar.gz: a76c46c1a5b50efc70b634063de67f84d6dee38a3b91934a8263365622c5fc58
5
5
  SHA512:
6
- metadata.gz: 82d0029b499e6094121baaefc687ed60d5dcdeb94aec258b625d38edbaa6ca44b86c9c8e194fb3af30b1f5af1b4105020118fc8d0978eef0e8dd505ac4a1cc18
7
- data.tar.gz: def105ef3ab398094c5110a2505dd3f61f89296e74f00fbc6f500f85257cd327c362f337b946dcceeaea8c34310afc2e3a900f8eafe3918b823d9ea5cc1afb3e
6
+ metadata.gz: 510197a7bf31b4841e18664d02aaf29b96a215a3d914ac1615f21e7680bfb4b9edeab7218983fc340efaae0649dbd01d7be83d7329557602b9ffccb11dc046fc
7
+ data.tar.gz: c910f5a1de6cfed67a46f52ce5a746fcf7403a458ae29aa41d13170592afd29f02a1be72deedd11833fb26adc07790c038040200b5c87e3bf3e885cead5c3b84
@@ -0,0 +1,71 @@
1
+ version: 2.1
2
+ jobs:
3
+ lint:
4
+ docker:
5
+ - image: salsify/ruby_ci:2.6.6
6
+ working_directory: ~/avro-resolution_canonical_form
7
+ steps:
8
+ - checkout
9
+ - restore_cache:
10
+ keys:
11
+ - v2-gems-ruby-2.6.6-{{ checksum "avro-resolution_canonical_form.gemspec" }}-{{ checksum "Gemfile" }}
12
+ - v2-gems-ruby-2.6.6-
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.6-{{ 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.6"
70
+ - "2.7.2"
71
+ - "3.0.0"
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,4 +1,22 @@
1
1
  # avro-resolution_canonical_form
2
2
 
3
+ ## v0.4.0 (Unreleased)
4
+ - Drop dependency on `avro-patches`.
5
+ - Add support for Ruby 3.0.
6
+ - Drop support for Ruby < 2.6.
7
+ - Use frozen string literals.
8
+
9
+ ## v0.3.0
10
+ - Require Avro v1.10.
11
+ - Include aliases, enum defaults, and decimal logical types in the resolution
12
+ canonical form. Schemas that use any of these parts of the Avro spec will
13
+ get a different fingerprint with this version.
14
+
15
+ ## v0.2.1
16
+ - Restrict to `avro-patches` versions < 2.0.0.
17
+
18
+ ## v0.2.0
19
+ - Require `avro-patches` instead of `avro-salsify-fork`.
20
+
3
21
  ## v0.1.0
4
22
  - Initial version
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,27 +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-salsify-fork](https://github.com/salsify/avro)
38
- gem due to a bug in the Avro Ruby gem support for defaults. The fix for this issue
39
- will be included in Avro v1.8.2.
40
-
41
- ### Aliases
42
-
43
- The Avro Ruby gem, including the avro-salsify-fork, does not yet include support
44
- for aliases. Aliases are included in the specification of the Resolution Canonical
45
- Form above, but not yet supported by this gem.
46
-
47
37
  ## Usage
48
38
 
49
39
  `Avro::ResolutionCanonicalForm` subclasses `Avro::SchemaNormalization`
@@ -68,7 +58,7 @@ schema = Avro::Schema.parse(<<-JSON)
68
58
  JSON
69
59
 
70
60
  Avro::ResolutionCanonicalForm.to_resolution_form(schema)
71
- #=> {"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\"]}"
72
62
  ```
73
63
 
74
64
  A new method, `#sha256_resolution_fingerprint`, is added to `Avro::Schema` to
@@ -78,7 +68,7 @@ the existing `#sha256_fingerprint` which is based on the Parsing Canonical Form.
78
68
  ```ruby
79
69
  schema.sha256_resolution_fingerprint
80
70
 
81
- #=> 80361294467930602613800428579400567035362599364974249578710466785512094641526
71
+ #=> 71676413924523555041213790831440929350080614901361467355865523343334332562796
82
72
  ```
83
73
 
84
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,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'avro-resolution_canonical_form/version'
5
6
 
@@ -27,11 +28,28 @@ Gem::Specification.new do |spec|
27
28
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
29
  spec.require_paths = ['lib']
29
30
 
30
- spec.add_development_dependency 'bundler', '~> 1.12'
31
- spec.add_development_dependency 'rake', '~> 10.0'
32
- spec.add_development_dependency 'rspec', '~> 3.4'
33
- 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'
34
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'
35
39
  spec.add_development_dependency 'simplecov'
36
- spec.add_runtime_dependency 'avro-salsify-fork', '>= 1.9.0.5'
40
+
41
+ spec.add_runtime_dependency 'avro', '~> 1.10.0'
42
+
43
+ spec.post_install_message = %(
44
+ avro-resolution_canonical_form now requires Avro v1.10.
45
+
46
+ New features in Avro Ruby v1.10 are now included in the canonical form:
47
+ - aliases
48
+ - enum defaults
49
+ - decimal logical types
50
+
51
+ Schemas that use any of these features will get a different fingerprint with
52
+ this version. For projects that only use Ruby, use of these features is unlikely
53
+ as they were previously unsupported.
54
+ )
37
55
  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'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AvroResolutionCanonicalForm
2
- VERSION = '0.1.0'.freeze
4
+ VERSION = '0.4.0'
3
5
  end
@@ -1,7 +1,9 @@
1
- require 'avro'
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
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.1.0
4
+ version: 0.4.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-03-14 00:00:00.000000000 Z
11
+ date: 2021-02-15 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-salsify-fork
112
+ name: avro
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 1.9.0.5
117
+ version: 1.10.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: 1.9.0.5
124
+ version: 1.10.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,18 @@ 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.10.
159
+
160
+ New features in Avro Ruby v1.10 are now included in the canonical form:
161
+ - aliases
162
+ - enum defaults
163
+ - decimal logical types
164
+
165
+ Schemas that use any of these features will get a different fingerprint with
166
+ this version. For projects that only use Ruby, use of these features is unlikely
167
+ as they were previously unsupported.
143
168
  rdoc_options: []
144
169
  require_paths:
145
170
  - lib
@@ -147,16 +172,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
172
  requirements:
148
173
  - - ">="
149
174
  - !ruby/object:Gem::Version
150
- version: '0'
175
+ version: '2.6'
151
176
  required_rubygems_version: !ruby/object:Gem::Requirement
152
177
  requirements:
153
178
  - - ">="
154
179
  - !ruby/object:Gem::Version
155
180
  version: '0'
156
181
  requirements: []
157
- rubyforge_project:
158
- rubygems_version: 2.6.10
159
- signing_key:
182
+ rubygems_version: 3.2.3
183
+ signing_key:
160
184
  specification_version: 4
161
185
  summary: Unique identification of Avro schemas for schema resolution
162
186
  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