embulk-parser-query_string 0.1.2 → 0.1.3

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
2
  SHA1:
3
- metadata.gz: 1d212e03f093b093ae862308c637069251feb71a
4
- data.tar.gz: 968354927bcd4ab12998fe8c366e79e3613401bc
3
+ metadata.gz: 577bbbbfd20a0b5ac1a95053773531166aa6abf4
4
+ data.tar.gz: d371c84d90510138671ff77fcd991d73596f5213
5
5
  SHA512:
6
- metadata.gz: 5e31e9f7e2675cf161686d05a4517bddeac6be16cc8eeb890c86257bff274077a8735060e8dd0d5a269a061497fec1b30a4e7b930b2f02c740a8f982be0ae12f
7
- data.tar.gz: e5e3adfa549e74d627b6afa06acad1b30026811b0db9073cafaa63254156f16774ae00143dc6a9ba630f10fac6c2904d572b3d31adabfeaa4336b1efd5127416
6
+ metadata.gz: df8f61b4304e53d7e6fa13cbbaa10506db82e911c99b1ed65f4c02047144c3c84b4c7eddf1b88bf17e6b4d878613f35ad6c2ac3fef2f8650901476f2a893f8e5
7
+ data.tar.gz: 23f03b8da79ef4e96911f2477dbe686198ca97c47a09609e5038d1b0d17b7808f46060c2fe39200f8052082807969be4c469c4b2cbb20274c602b3efba36d3d5
data/.travis.yml CHANGED
@@ -10,3 +10,12 @@ notifications:
10
10
  secure: "QRZ6zQxcRdN2XylIz+b46TbYIv7x5Ko7Y0Mi0aGbf7Wg1xfnS4X2FZKp8gF+RH1qjT6CYsQFUpPBhPVCMx0fP0ik5/gBrdngrj0htludvQ5CTK2oVegM1VC5NSn+gi8bt2F20Ode9fxU5OS1HDzNR9sjPz3W7miMUNDZoYPy77Om/CvmVkBbGyMkWnfwhEvwnL8JpBNpklDvrUUKznNsAcSbKQBMBAglFMds/OaHXCkK142zMbSlHMctch1VDAKhX9/6M3v8v6ZRheX68+VVCz3nTrTF0/lnYh3ig9ey3DNlgkZUqK2gmypnhTE6tpeibHdyVa8qOMNzyAgltu1qIhFHN390WMk9gZXEcvWG3m++PMAIKKtd4varbH1vdCeHOGUV7GRgarcfSMvJ54I9xc5GkUnAhjRKj8xDzYzhkXwApD8eqWb2RgGXUm6G4cKj0MeQ4WBqHr9FOW/4EJcZoztFi0YlP7KE+6xptBJU479KSsv31BwHrMfblObOOj58C7gUfdbTCByxng0u1axxvixL8zJwgHvFND3/4yoXoCCgm0DXBPbi6B5xpt8QmN6K4E5sMGrppTI7VwJqkcwkVD0EEeCedRNiWLTaxlKpLYxYnoXwEnpm9o2WXWa+PjkWeawsnJvV5IAt6oJhaK22VqJN86Macuu+nCdeF1/0TZU="
11
11
  jdk:
12
12
  - oraclejdk8
13
+ gemfile:
14
+ - gemfiles/embulk-0.6.10
15
+ - gemfiles/embulk-0.6.11
16
+ - gemfiles/embulk-0.6.12
17
+ - gemfiles/embulk-0.6.13
18
+ - gemfiles/embulk-0.6.14
19
+ - gemfiles/embulk-0.6.15
20
+ - gemfiles/embulk-0.6.16
21
+ - gemfiles/embulk-latest
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.3 - 2015-07-16
2
+ * [enhancement] Fix bug nil value casting unexpectedly [#16](https://github.com/treasure-data/embulk-parser-query_string/pull/16)
3
+ * [maintenance] Improve test [#15](https://github.com/treasure-data/embulk-parser-query_string/pull/15)
4
+
1
5
  ## 0.1.2 - 2015-07-14
2
6
  * [fixed] Fix to ignore empty line same as invalid line [#14](https://github.com/treasure-data/embulk-parser-query_string/pull/14)
3
7
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-parser-query_string"
4
- spec.version = "0.1.2"
4
+ spec.version = "0.1.3"
5
5
  spec.authors = ["yoshihara", "uu59"]
6
6
  spec.summary = "Query String parser plugin for Embulk"
7
7
  spec.description = "Parses Query String files read by other file input plugins."
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.6.10"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.6.11"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.6.12"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.6.13"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.6.14"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.6.15"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.6.16"
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
@@ -82,11 +82,13 @@ module Embulk
82
82
  name = column.name
83
83
  value = record[name]
84
84
 
85
+ next nil unless value
86
+
85
87
  case column.type
86
88
  when :long
87
- Integer(value)
89
+ value.strip.empty? ? nil : Integer(value)
88
90
  when :timestamp
89
- Time.parse(value)
91
+ value.strip.empty? ? nil : Time.parse(value)
90
92
  else
91
93
  value.to_s
92
94
  end
@@ -0,0 +1,45 @@
1
+ module CaptureIo
2
+ def capture(output = :out, &block)
3
+ _, out = swap_io(output, &block)
4
+ out
5
+ end
6
+
7
+ def silence(&block)
8
+ block_result = nil
9
+ swap_io(:out) do
10
+ block_result,_ = swap_io(:err, &block)
11
+ end
12
+ block_result
13
+ end
14
+
15
+ def swap_io(output = :out, &block)
16
+ java_import 'java.io.PrintStream'
17
+ java_import 'java.io.ByteArrayOutputStream'
18
+ java_import 'java.lang.System'
19
+
20
+ ruby_original_stream = output == :out ? $stdout.dup : $stderr.dup
21
+ java_original_stream = System.send(output) # :out or :err
22
+ ruby_buf = StringIO.new
23
+ java_buf = ByteArrayOutputStream.new
24
+
25
+ case output
26
+ when :out
27
+ $stdout = ruby_buf
28
+ System.setOut(PrintStream.new(java_buf))
29
+ when :err
30
+ $stderr = ruby_buf
31
+ System.setErr(PrintStream.new(java_buf))
32
+ end
33
+
34
+ [block.call, ruby_buf.string + java_buf.toString]
35
+ ensure
36
+ case output
37
+ when :out
38
+ $stdout = ruby_original_stream
39
+ System.setOut(java_original_stream)
40
+ when :err
41
+ $stderr = ruby_original_stream
42
+ System.setErr(java_original_stream)
43
+ end
44
+ end
45
+ end
@@ -101,10 +101,10 @@ module Embulk
101
101
 
102
102
  def task
103
103
  {
104
- parser: {
105
- strip_quote: true,
106
- strip_whitespace: true,
107
- schema: columns,
104
+ "parser" => {
105
+ "strip_quote" => true,
106
+ "strip_whitespace" => true,
107
+ "schema" => columns,
108
108
  }
109
109
  }
110
110
  end
@@ -74,16 +74,34 @@ module Embulk
74
74
  end
75
75
 
76
76
  class TestProcessLine < self
77
- def test_process_line
77
+ def test_all_keys_exist_in_schema
78
78
  mock(page_builder).add(["FOO", 1, Time.parse("2015-07-08T16:25:46")])
79
79
  plugin.send(:process_line, line)
80
80
  end
81
81
 
82
+ def test_key_nonexist_in_schema
83
+ nonexist_column = Column.new(nil, "different", :long)
84
+ nonexist_schema = schema << nonexist_column
85
+
86
+ plugin = QueryString.new(DataSource[task], nonexist_schema, page_builder)
87
+ mock(page_builder).add(["FOO", 1, Time.parse("2015-07-08T16:25:46"), nil])
88
+ plugin.send(:process_line, line)
89
+ end
90
+
91
+ def test_long_value_for_key_nonexist
92
+ mock(page_builder).add(["FOO", nil, Time.parse("2015-07-08T16:25:46")])
93
+ plugin.send(:process_line, value_nonexist_line)
94
+ end
95
+
82
96
  private
83
97
 
84
98
  def line
85
99
  "foo=FOO&bar=1&baz=2015-07-08T16:25:46"
86
100
  end
101
+
102
+ def value_nonexist_line
103
+ "foo=FOO&bar=&baz=2015-07-08T16:25:46"
104
+ end
87
105
  end
88
106
 
89
107
  def test_transaction
@@ -0,0 +1,19 @@
1
+ require "capture_io"
2
+
3
+ module EmbulkRunHelper
4
+ include CaptureIo
5
+
6
+ def embulk_guess(seed_path, dest_path)
7
+ silence do
8
+ embulk_exec(%W(guess -g query_string #{seed_path} -o #{dest_path}))
9
+ end
10
+ end
11
+
12
+ def embulk_run(yaml_path)
13
+ embulk_exec(%W(run #{yaml_path}))
14
+ end
15
+
16
+ def embulk_exec(cli_options = [])
17
+ Embulk.run(cli_options)
18
+ end
19
+ end
@@ -0,0 +1,109 @@
1
+ require "yaml"
2
+ require "tmpdir"
3
+ require "prepare_embulk"
4
+ require "embulk_run_helper"
5
+
6
+ module Embulk
7
+ class EmbulkRunTest < Test::Unit::TestCase
8
+ include EmbulkRunHelper
9
+
10
+ def setup
11
+ @dir = Dir.mktmpdir
12
+ @target_file = "#{@dir}/target_file.txt"
13
+ File.open(@target_file, "w") do |f|
14
+ f.write <<-FILE
15
+ "foo=FOO&bar=1"
16
+ "foo=FOO&bar=2"
17
+ "foo=FOO&bar=3"
18
+ "foo=FOO&bar=4"
19
+ "foo=FOO&bar=5"
20
+ "foo=FOO&bar=6"
21
+ "foo=FOO&bar=7"
22
+ "foo=FOO&bar=8"
23
+ "foo=FOO&bar=9"
24
+ "foo=FOO&bar=10"
25
+ "foo=FOO&bar=11"
26
+ "foo=FOO&bar=12"
27
+ "foo=FOO&bar=13"
28
+ FILE
29
+ end
30
+ end
31
+
32
+ def teardown
33
+ FileUtils.rm_rf @dir
34
+ end
35
+
36
+ def test_embulk_run
37
+ config_path = "#{@dir}/config.yml"
38
+ File.open(config_path, "w") do |f|
39
+ f.write guessed_content
40
+ end
41
+ out = capture do
42
+ embulk_run(config_path)
43
+ end
44
+
45
+ assert_true(out.include?(<<-CONTENT))
46
+ FOO,1
47
+ FOO,2
48
+ FOO,3
49
+ FOO,4
50
+ FOO,5
51
+ FOO,6
52
+ FOO,7
53
+ FOO,8
54
+ FOO,9
55
+ FOO,10
56
+ FOO,11
57
+ FOO,12
58
+ FOO,13
59
+ CONTENT
60
+ end
61
+
62
+ def test_embulk_guess
63
+ seed_path = "#{@dir}/seed.yml"
64
+ File.open(seed_path, "w") do |f|
65
+ f.write seed_content
66
+ end
67
+ dest_path = "#{@dir}/guessed.yml"
68
+ embulk_guess(seed_path, dest_path)
69
+ guessed = IO.read(dest_path)
70
+
71
+ assert_equal(guessed_content, guessed)
72
+ end
73
+
74
+ private
75
+
76
+ def seed_content
77
+ <<YAML
78
+ in:
79
+ type: file
80
+ path_prefix: #{@dir}/target_file
81
+ parser:
82
+ strip_quote: true
83
+ strip_whitespace: true
84
+ exec: {}
85
+ out: {type: stdout}
86
+ YAML
87
+ end
88
+
89
+ def guessed_content
90
+ <<YAML
91
+ in:
92
+ type: file
93
+ path_prefix: #{@dir}/target_file
94
+ parser:
95
+ strip_quote: true
96
+ strip_whitespace: true
97
+ charset: UTF-8
98
+ newline: CRLF
99
+ type: query_string
100
+ schema:
101
+ - {name: foo, type: string}
102
+ - {name: bar, type: long}
103
+ exec: {}
104
+ out: {type: stdout}
105
+ YAML
106
+ end
107
+ end
108
+ end
109
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-parser-query_string
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshihara
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-14 00:00:00.000000000 Z
12
+ date: 2015-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement
@@ -132,13 +132,24 @@ files:
132
132
  - README.md
133
133
  - Rakefile
134
134
  - embulk-parser-query_string.gemspec
135
+ - gemfiles/embulk-0.6.10
136
+ - gemfiles/embulk-0.6.11
137
+ - gemfiles/embulk-0.6.12
138
+ - gemfiles/embulk-0.6.13
139
+ - gemfiles/embulk-0.6.14
140
+ - gemfiles/embulk-0.6.15
141
+ - gemfiles/embulk-0.6.16
142
+ - gemfiles/embulk-latest
135
143
  - lib/embulk/guess/query_string.rb
136
144
  - lib/embulk/parser/query_string.rb
137
145
  - partial-config.yml
146
+ - test/capture_io.rb
138
147
  - test/embulk/guess/test_query_string.rb
139
148
  - test/embulk/parser/test_query_string_plugin.rb
149
+ - test/embulk_run_helper.rb
140
150
  - test/prepare_embulk.rb
141
151
  - test/run-test.rb
152
+ - test/test_embulk_run.rb
142
153
  homepage: https://github.com/treasure-data/embulk-parser-query_string
143
154
  licenses:
144
155
  - Apache2
@@ -164,7 +175,10 @@ signing_key:
164
175
  specification_version: 4
165
176
  summary: Query String parser plugin for Embulk
166
177
  test_files:
178
+ - test/capture_io.rb
167
179
  - test/embulk/guess/test_query_string.rb
168
180
  - test/embulk/parser/test_query_string_plugin.rb
181
+ - test/embulk_run_helper.rb
169
182
  - test/prepare_embulk.rb
170
183
  - test/run-test.rb
184
+ - test/test_embulk_run.rb