embulk-input-presto 0.1.1 → 0.1.2

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: cc144684e67c11aba628fa38f6ba455c453b87d2
4
- data.tar.gz: 893c46973bfa5fc1c6a278b10ad7e81ea78be2dd
3
+ metadata.gz: 1a57f6dc5a7064378aba3325b8765ffc3e3f1cdd
4
+ data.tar.gz: f272abf3aad3768b0603366e404685cf33d4e61d
5
5
  SHA512:
6
- metadata.gz: 9b79cc502d7a9f092116ce22a7abd72f6268b923429858c0ce2c822098f62be07a3b1a6d2f38cf16727a629507edf093d01f285c601144bde0f7f036cbae2dbe
7
- data.tar.gz: 86cdb8c582355601eaebca39a37ca308c07af437e171b551620108c6223259215c1f2baf2e29fb28746c57ec61aec2ebae59ff104cd8c52e2880c006438bb222
6
+ metadata.gz: 13ce34fd728876372f389ac13cf422d23b8facba8c3069b60f946f4762cc37e003e2493ec5c1129ca10fdab20a8ed0ed860028a9109e02a5afd6bb62e9e30ccc
7
+ data.tar.gz: 1898c4f776b9570ecf9813372cfd80ff2c62c339f0872e633d85a722e8a844d911b1bb0716489cf243cde6b25aa6fc2452a8c628d3877cc6b13399a8924b279a
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- jruby-9.0.0.0
1
+ jruby-9.0.5.0
data/Rakefile CHANGED
@@ -1,3 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
2
3
 
3
- task default: :build
4
+ desc 'Run test_unit based test'
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.test_files = Dir["test/**/test_*.rb"].sort
8
+ t.verbose = true
9
+ t.warning = false
10
+ end
11
+ task :default => :test
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-input-presto"
4
- spec.version = "0.1.1"
4
+ spec.version = "0.1.2"
5
5
  spec.authors = ["toyama0919"]
6
6
  spec.summary = "Facebook Presto input plugin for Embulk"
7
7
  spec.description = "Facebook Presto input plugin for Embulk."
@@ -14,7 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.require_paths = ["lib"]
15
15
 
16
16
  spec.add_dependency "presto-client"
17
- spec.add_development_dependency 'embulk', ['~> 0.7.10']
17
+ spec.add_development_dependency 'embulk', ['>= 0.8.9']
18
18
  spec.add_development_dependency 'bundler', ['~> 1.0']
19
19
  spec.add_development_dependency 'rake', ['>= 10.0']
20
+ spec.add_development_dependency 'test-unit'
20
21
  end
@@ -1,59 +1,93 @@
1
1
  module Embulk
2
- class InputPresto < InputPlugin
3
- require 'presto-client'
4
-
5
- Plugin.register_input("presto", self)
6
-
7
- def self.transaction(config, &control)
8
- task = {
9
- "host" => config.param("host", :string, default: "localhost"),
10
- "port" => config.param("port", :integer, default: 8080),
11
- "schema" => config.param("schema", :string, default: "default"),
12
- "catalog" => config.param("catalog", :string, default: "native"),
13
- "query" => config.param("query", :string),
14
- "user" => config.param("user", :string, default: "embulk"),
15
- "columns" => config.param("columns", :array, default: [])
16
- }
17
-
18
- columns = task['columns'].each_with_index.map do |c, i|
19
- Column.new(i, c["name"], c["type"].to_sym)
20
- end
2
+ module Input
3
+ class Presto < InputPlugin
4
+ require 'presto-client'
21
5
 
22
- resume(task, columns, 1, &control)
23
- end
6
+ Plugin.register_input("presto", self)
24
7
 
25
- def self.resume(task, columns, count, &control)
26
- task_reports = yield(task, columns, count)
8
+ def self.transaction(config, &control)
9
+ task = {
10
+ "host" => config.param("host", :string, default: "localhost"),
11
+ "port" => config.param("port", :integer, default: 8080),
12
+ "schema" => config.param("schema", :string, default: "default"),
13
+ "catalog" => config.param("catalog", :string, default: "native"),
14
+ "query" => config.param("query", :string),
15
+ "user" => config.param("user", :string, default: "embulk"),
16
+ "columns" => config.param("columns", :array)
17
+ }
27
18
 
28
- next_config_diff = {}
29
- return next_config_diff
30
- end
19
+ columns = task['columns'].each_with_index.map do |c, i|
20
+ Column.new(i, c["name"], c["type"].to_sym)
21
+ end
31
22
 
32
- def init
33
- @client = Presto::Client.new(
34
- server: "#{task['host']}:#{task['port']}",
35
- catalog: task['catalog'],
36
- user: task['user'],
37
- schema: task['schema']
38
- )
39
- @query = task["query"]
23
+ resume(task, columns, 1, &control)
24
+ end
40
25
 
41
- Embulk.logger.info "SQL: #{@query}"
42
- end
26
+ def self.resume(task, columns, count, &control)
27
+ task_reports = yield(task, columns, count)
43
28
 
44
- def run
45
- size = 0
46
- @client.query(@query) do |q|
47
- q.each_row {|row|
48
- page_builder.add(row)
49
- }
50
- size = q.rows.size
29
+ next_config_diff = {}
30
+ return next_config_diff
51
31
  end
52
32
 
53
- page_builder.finish
33
+ def init
34
+ @client = ::Presto::Client.new(
35
+ server: "#{task['host']}:#{task['port']}",
36
+ catalog: task['catalog'],
37
+ user: task['user'],
38
+ schema: task['schema']
39
+ )
40
+ @query = task["query"]
54
41
 
55
- task_report = { size: size }
56
- return task_report
42
+ Embulk.logger.info "SQL: #{@query}"
43
+ end
44
+
45
+ def run
46
+ size = 0
47
+ @client.query(@query) do |q|
48
+ q.each_row {|row|
49
+ converted_values = row.map.with_index { |value,i| convert_value(value, schema[i]) }
50
+ page_builder.add(converted_values)
51
+ }
52
+ size = q.rows.size
53
+ end
54
+
55
+ page_builder.finish
56
+
57
+ task_report = { size: size }
58
+ return task_report
59
+ end
60
+
61
+ def convert_value(value, field)
62
+ return nil if value.nil?
63
+ case field["type"]
64
+ when :string
65
+ value
66
+ when :long
67
+ value.to_i
68
+ when :double
69
+ value.to_f
70
+ when :boolean
71
+ if value.is_a?(TrueClass) || value.is_a?(FalseClass)
72
+ value
73
+ else
74
+ downcased_val = value.downcase
75
+ case downcased_val
76
+ when 'true' then true
77
+ when 'false' then false
78
+ when '1' then true
79
+ when '0' then false
80
+ else nil
81
+ end
82
+ end
83
+ when :timestamp
84
+ Time.parse(value)
85
+ when :json
86
+ value
87
+ else
88
+ raise "Unsupported type #{field['type']}"
89
+ end
90
+ end
57
91
  end
58
92
  end
59
93
  end
data/test/helper.rb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+
5
+ # require 'embulk/java/bootstrap'
6
+ require 'embulk'
7
+ Embulk.setup
8
+ Embulk.logger = Embulk::Logger.new('/dev/null')
9
+
10
+ APP_ROOT = File.expand_path('../', __dir__)
11
+ TEST_ROOT = File.expand_path(File.dirname(__FILE__))
@@ -0,0 +1,65 @@
1
+ require_relative './helper'
2
+ require 'embulk/input/presto'
3
+ require 'yaml'
4
+
5
+ Presto = Embulk::Input::Presto
6
+
7
+ module Embulk
8
+ class Input::Presto
9
+ class TestTransaction < Test::Unit::TestCase
10
+ def control
11
+ Proc.new {|task| task_reports = [] }
12
+ end
13
+
14
+ sub_test_case "transaction" do
15
+ def test_normal
16
+ yaml = YAML.load(%(
17
+ host: presto01
18
+ catalog: store
19
+ schema: public
20
+ query: |
21
+ SELECT
22
+ trim(upper(url_decode(keyword))) AS keyword,
23
+ count(*) as count
24
+ FROM search
25
+ CROSS JOIN UNNEST(split(keywords, ',')) AS t (keyword)
26
+ WHERE log_date >= (CURRENT_DATE - INTERVAL '90' DAY)
27
+ AND length(keywords) != 256
28
+ group by keyword
29
+ having count(*) >= 10
30
+ order by count(*) desc
31
+ columns:
32
+ - {name: keyword, type: string}
33
+ - {name: count, type: long}
34
+ )
35
+ )
36
+ config = DataSource.new(yaml)
37
+ Presto.transaction(config, &control)
38
+ end
39
+
40
+ def test_minimum
41
+ yaml = YAML.load(%(
42
+ query: |
43
+ SELECT
44
+ trim(upper(url_decode(keyword))) AS keyword,
45
+ count(*) as count
46
+ FROM search
47
+ CROSS JOIN UNNEST(split(keywords, ',')) AS t (keyword)
48
+ WHERE log_date >= (CURRENT_DATE - INTERVAL '90' DAY)
49
+ AND length(keywords) != 256
50
+ group by keyword
51
+ having count(*) >= 10
52
+ order by count(*) desc
53
+ columns:
54
+ - {name: keyword, type: string}
55
+ - {name: count, type: long}
56
+
57
+ )
58
+ )
59
+ config = DataSource.new(yaml)
60
+ Presto.transaction(config, &control)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-presto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - toyama0919
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-08 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -27,17 +27,17 @@ dependencies:
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - "~>"
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.7.10
32
+ version: 0.8.9
33
33
  name: embulk
34
34
  prerelease: false
35
35
  type: :development
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.7.10
40
+ version: 0.8.9
41
41
  - !ruby/object:Gem::Dependency
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ name: test-unit
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Facebook Presto input plugin for Embulk.
70
84
  email:
71
85
  - toyama0919@gmail.com
@@ -81,6 +95,8 @@ files:
81
95
  - Rakefile
82
96
  - embulk-input-presto.gemspec
83
97
  - lib/embulk/input/presto.rb
98
+ - test/helper.rb
99
+ - test/test_transaction.rb
84
100
  homepage: https://github.com/toyama0919/embulk-input-presto
85
101
  licenses:
86
102
  - MIT
@@ -101,8 +117,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
117
  version: '0'
102
118
  requirements: []
103
119
  rubyforge_project:
104
- rubygems_version: 2.4.5
120
+ rubygems_version: 2.4.8
105
121
  signing_key:
106
122
  specification_version: 4
107
123
  summary: Facebook Presto input plugin for Embulk
108
- test_files: []
124
+ test_files:
125
+ - test/helper.rb
126
+ - test/test_transaction.rb