avro_utils 0.2.0 → 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 +4 -4
- data/avro_utils.gemspec +1 -1
- data/lib/utils/avro_utils.rb +33 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0080dc3e4ff8b2c5e3b1b23d244c2ffd51c6c7ce
|
4
|
+
data.tar.gz: 0eb26f5368882942dd37e81535ac63540955b227
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5354701d75e488ee89d476d7d4f7e196898bd34228af0e64a4d600e24f0cc2d4df9efd4187f01edaff48383033fd36892684a2dfa5cb514421c5c3b2a62866dd
|
7
|
+
data.tar.gz: 6983cbb57153c0c19c582f4bbca97ffa9424a629e65ef5944bbe542c53bf6eaaa61cac2fc5e826637cbb3f4170a0b27bb07901f7e87faa7a2a34315e73768eac
|
data/avro_utils.gemspec
CHANGED
data/lib/utils/avro_utils.rb
CHANGED
@@ -64,6 +64,39 @@ class AvroUtils
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
def is_valid_schema?(schema)
|
68
|
+
process_data do
|
69
|
+
working_schema = ( [Hash, Array].include?(schema.class) )? schema.to_json : schema.dup
|
70
|
+
all_names_valid?(working_schema)
|
71
|
+
Avro::Schema.parse(working_schema)
|
72
|
+
true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def all_names_valid?(string_schema)
|
77
|
+
result = { }
|
78
|
+
names = string_schema.scan(/"name":"[\w][^"]+/).map { |x| x.split(':"')[1] }
|
79
|
+
invalid_pt = /[^A-Za-z0-9_]/
|
80
|
+
names.each do |name|
|
81
|
+
invalid_chars = name.scan(invalid_pt)
|
82
|
+
if invalid_chars.any?
|
83
|
+
result.store(name, invalid_chars)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
if result.any?
|
88
|
+
error = "The following names have invalid characters:\n"
|
89
|
+
result.each do |key, value|
|
90
|
+
error += "#{key}: #{value}\n"
|
91
|
+
end
|
92
|
+
|
93
|
+
raise InvalidDataException.new(error)
|
94
|
+
end
|
95
|
+
|
96
|
+
true
|
97
|
+
end
|
98
|
+
|
99
|
+
|
67
100
|
# Avro assumes that all the hashes use strings for keys. It does not accept Indifferent Hash.
|
68
101
|
# So the conversion bellow ensures that the hash data uses strings for keys.
|
69
102
|
def hash_with_string_keys(json_data)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avro_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Linh Chau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|