razorpay_pa 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/flatten +64 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 12ee637299227247cb7609b8e277f05b97b51bb71e19a6fbe3782b5107f0f01b
|
4
|
+
data.tar.gz: 269069f4b46519a70be4c2a6963ce7da9da83917166cf1bfc39277879a754dac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3054608cb15134da4c94b2a842cf23c74739649480b926dd6ab50a4f20f37c3a0093414bead7c73f7c3dd947847b80fef3ccdc5f7bcb0f98f91098f2d0dddbe
|
7
|
+
data.tar.gz: 831513af06674be996619ef1a0972e86999a18e46c7733c6ee8bbf85a2fa8cbe07b3e20448188c187a836df86ac55125d2c5c7cfdd041b3bc540229824152a8c
|
data/bin/flatten
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
# Apparently syntax is different dependiong on if it's hive or presto
|
6
|
+
engine=ARGV.first.to_sym rescue nil
|
7
|
+
raise "What kind of dumbfuck engine is that?" if not [:hive, :presto].include? engine
|
8
|
+
|
9
|
+
engine_mapping = {
|
10
|
+
hive: {
|
11
|
+
func: 'get_json_object',
|
12
|
+
type: 'string',
|
13
|
+
},
|
14
|
+
presto: {
|
15
|
+
func: 'json_extract_scalar',
|
16
|
+
type: 'varchar',
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
func = engine_mapping[engine][:func]
|
21
|
+
type = engine_mapping[engine][:type]
|
22
|
+
|
23
|
+
json_string=ARGV.last
|
24
|
+
json=JSON.parse(json_string)
|
25
|
+
|
26
|
+
module Enumerable
|
27
|
+
def flatten_with_path(parent_prefix = '$')
|
28
|
+
res = {}
|
29
|
+
|
30
|
+
self.each_with_index do |elem, i|
|
31
|
+
if elem.is_a?(Array)
|
32
|
+
k, v = elem
|
33
|
+
else
|
34
|
+
k, v = i, elem
|
35
|
+
end
|
36
|
+
|
37
|
+
key = parent_prefix ? "#{parent_prefix}.#{k}" : k # assign key name for result hash
|
38
|
+
|
39
|
+
if v.is_a? Enumerable
|
40
|
+
res.merge!(v.flatten_with_path(key)) # recursive call to flatten child elements
|
41
|
+
else
|
42
|
+
res[key] = v
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
res
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
columns=json.flatten_with_path.keys
|
51
|
+
casts=[]
|
52
|
+
|
53
|
+
columns.each do |key|
|
54
|
+
name=key[2..-1].gsub('.','_')
|
55
|
+
casts << "CAST(#{func} (properties,'#{key}') as #{type}) AS #{name}"
|
56
|
+
end
|
57
|
+
|
58
|
+
result = casts.join(",\n")
|
59
|
+
|
60
|
+
# Print the output...
|
61
|
+
puts result
|
62
|
+
|
63
|
+
# ...but also copy it to clipboard
|
64
|
+
IO.popen('pbcopy', 'w') { |f| f << result }
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: razorpay_pa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Harman Singh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- harman28@gmail.com
|
16
|
+
executables:
|
17
|
+
- flatten
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/flatten
|
22
|
+
homepage: https://github.com/harman28/razorpay_pa
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message: Executable scripts for the Razorpay PA team.
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- "."
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.0.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Executable scripts for the Razorpay PA team.
|
45
|
+
test_files: []
|