norikra-querydump-format 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/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +90 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/norikra-querydump-format~ +12 -0
- data/bin/setup +7 -0
- data/exe/norikra-querydump-format +32 -0
- data/lib/norikra/querydump/format.rb +49 -0
- data/lib/norikra/querydump/format/version.rb +7 -0
- data/norikra-querydump-format.gemspec +25 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce7ad56594136a657981fe165b34f2df3fe6d5a7
|
4
|
+
data.tar.gz: f42a9d450a730fa5607c742fd06f033e874623e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b420c3b2960ceb5b8ac3cde5636bdb6767e403683a3c5ef3d53ef89df41f1556478fbf078fef75ef2e893440f6c6b343ced89e82c47c95d4e099502b45c1493
|
7
|
+
data.tar.gz: 864de9368b4344ef98f0e066f08a56dfa11ca2991fab84e473844b783c6cb7e06e16bee7914feb30012b44690ef955e010a31c3c4becae135dadb3bded13b5b9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 FUJIWARA Shunichiro
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Norikra::Querydump::Format
|
2
|
+
|
3
|
+
A formatter for norikra-client query dump and sync.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
$ gem install norikra-querydump-format
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```
|
14
|
+
$ norikra-querydump-format -i (text|json) [inputfile]
|
15
|
+
```
|
16
|
+
|
17
|
+
Format norikra query dump as a text.
|
18
|
+
|
19
|
+
```
|
20
|
+
$ norikra-client query dump | norikra-querydump-format -i json > dump.txt
|
21
|
+
```
|
22
|
+
|
23
|
+
Sync queries from a text to norikra.
|
24
|
+
|
25
|
+
```
|
26
|
+
$ norikra-querydump-format -i text < dump.txt | norikra-client query sync
|
27
|
+
```
|
28
|
+
|
29
|
+
## Examples
|
30
|
+
|
31
|
+
An example output of `norikra-client query dump`.
|
32
|
+
|
33
|
+
```json
|
34
|
+
[
|
35
|
+
{
|
36
|
+
"name": "query1",
|
37
|
+
"group": null,
|
38
|
+
"suspended": false,
|
39
|
+
"targets": [
|
40
|
+
"foo"
|
41
|
+
],
|
42
|
+
"expression": "SELECT count(*) FROM\n foo.win:time_batch(1 min)\n"
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"name": "query2",
|
46
|
+
"group": null,
|
47
|
+
"suspended": false,
|
48
|
+
"targets": [
|
49
|
+
"bar"
|
50
|
+
],
|
51
|
+
"expression": "SELECT count(*) FROM bar.win:time_batch(1 min)\n"
|
52
|
+
}
|
53
|
+
]
|
54
|
+
```
|
55
|
+
|
56
|
+
`-i json` converts a json to text below.
|
57
|
+
|
58
|
+
```sql
|
59
|
+
-- QUERY:{"name":"query1","group":null,"suspended":false,"targets":["foo"]}
|
60
|
+
SELECT count(*) FROM
|
61
|
+
foo.win:time_batch(1 min)
|
62
|
+
|
63
|
+
-- QUERY:{"name":"query2","group":null,"suspended":false,"targets":["bar"]}
|
64
|
+
SELECT count(*) FROM bar.win:time_batch(1 min)
|
65
|
+
|
66
|
+
```
|
67
|
+
|
68
|
+
`-i text` converts a text to json.
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
|
+
|
74
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/norikra-querydump-format.
|
79
|
+
|
80
|
+
## See also
|
81
|
+
|
82
|
+
- [Norikra](https://norikra.github.io/)
|
83
|
+
|
84
|
+
## Copyright
|
85
|
+
|
86
|
+
(c) 2015- FUJIWARA Shunichiro
|
87
|
+
|
88
|
+
## License
|
89
|
+
|
90
|
+
MIT License
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "norikra/querydump/format"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'norikra/querydump/format'
|
5
|
+
|
6
|
+
def usage(code)
|
7
|
+
warn "Usage: norikra-querydump-format -i (text|json) [inputfile]"
|
8
|
+
exit code
|
9
|
+
end
|
10
|
+
|
11
|
+
params = ARGV.getopts('hi:')
|
12
|
+
if params['h']
|
13
|
+
usage(0)
|
14
|
+
end
|
15
|
+
|
16
|
+
case ARGV.size
|
17
|
+
when 0
|
18
|
+
src = STDIN
|
19
|
+
when 1
|
20
|
+
src = File.open(ARGV.first)
|
21
|
+
else
|
22
|
+
usage(1)
|
23
|
+
end
|
24
|
+
|
25
|
+
case params['i']
|
26
|
+
when 'text'
|
27
|
+
Norikra::Querydump::Format.text2json(src)
|
28
|
+
when 'json'
|
29
|
+
Norikra::Querydump::Format.json2text(src)
|
30
|
+
else
|
31
|
+
usage(1)
|
32
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "norikra/querydump/format/version"
|
2
|
+
|
3
|
+
module Norikra
|
4
|
+
module Querydump
|
5
|
+
module Format
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
HEADER = '-- QUERY:'
|
9
|
+
HEADER_REGEXP = Regexp.new("^#{HEADER}")
|
10
|
+
|
11
|
+
def self.json2text(src=STDIN, dest=STDOUT)
|
12
|
+
JSON.parse(src.read).each do |q|
|
13
|
+
expression = q.delete('expression')
|
14
|
+
dest.puts "#{HEADER}#{q.to_json}"
|
15
|
+
dest.puts expression
|
16
|
+
dest.puts ""
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.text2json(src=STDIN, dest=STDOUT)
|
21
|
+
queries = []
|
22
|
+
buf = []
|
23
|
+
index = -1
|
24
|
+
|
25
|
+
src.each do |line|
|
26
|
+
next if line == "\n"
|
27
|
+
if line =~ HEADER_REGEXP
|
28
|
+
if index >= 0
|
29
|
+
queries[index]['expression'] = buf.join('')
|
30
|
+
buf.clear
|
31
|
+
end
|
32
|
+
line.gsub!(HEADER_REGEXP, '')
|
33
|
+
line.gsub!(/ *$/, '')
|
34
|
+
index = index + 1
|
35
|
+
queries[index] = JSON.parse(line)
|
36
|
+
elsif line =~ /^--/
|
37
|
+
# skip comment line
|
38
|
+
next
|
39
|
+
else
|
40
|
+
buf << line
|
41
|
+
end
|
42
|
+
end
|
43
|
+
queries[index]['expression'] = buf.join('')
|
44
|
+
dest.puts queries.to_json
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'norikra/querydump/format/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "norikra-querydump-format"
|
8
|
+
spec.version = Norikra::Querydump::Format::VERSION
|
9
|
+
spec.authors = ["FUJIWARA Shunichiro"]
|
10
|
+
spec.email = ["fujiwara.shunichiro@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Formatter for norikra-client query dump and sync.}
|
13
|
+
spec.description = %q{Formatter for norikra-client query dump and sync.}
|
14
|
+
spec.homepage = "https://github.com/fujiwara/norikra-querydump-format"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: norikra-querydump-format
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- FUJIWARA Shunichiro
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Formatter for norikra-client query dump and sync.
|
56
|
+
email:
|
57
|
+
- fujiwara.shunichiro@gmail.com
|
58
|
+
executables:
|
59
|
+
- norikra-querydump-format
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/norikra-querydump-format~
|
71
|
+
- bin/setup
|
72
|
+
- exe/norikra-querydump-format
|
73
|
+
- lib/norikra/querydump/format.rb
|
74
|
+
- lib/norikra/querydump/format/version.rb
|
75
|
+
- norikra-querydump-format.gemspec
|
76
|
+
homepage: https://github.com/fujiwara/norikra-querydump-format
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.5
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Formatter for norikra-client query dump and sync.
|
100
|
+
test_files: []
|