embulk-formatter-mysql_xml 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ea623fd3aaab4f4773f9b4684e68464369b534f
4
+ data.tar.gz: a57ba06651163081bff7bcec315f29d84d414d29
5
+ SHA512:
6
+ metadata.gz: 6f4b67c3cad4f02d79bc2228389918fd83f9a27f81988101197d185a88a134de9cf9b23227859cb3189b44d6b53c1f10c6ab54adb8377a02e4f0dc11359e7ab1
7
+ data.tar.gz: 8c73b18271427cf88245d0017af09488d8a1b07b31bb63a9724c22f4d917535461b78e76a595996b5d40d7ddd52ee1b51cd6906b1168077eb9989bde1bf9abe1
@@ -0,0 +1,6 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ /.bundle/
5
+ /Gemfile.lock
6
+ *.swp
@@ -0,0 +1 @@
1
+ jruby-9.1.15.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec
@@ -0,0 +1,21 @@
1
+
2
+ MIT License
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # MySQL XML formatter plugin for Embulk
2
+
3
+ Embulk formatter plugin to output value for MySQL's `LOAD XML` statement.
4
+
5
+ https://dev.mysql.com/doc/refman/5.7/en/load-xml.html
6
+
7
+ ## Overview
8
+
9
+ * **Plugin type**: formatter
10
+
11
+ ## Configuration
12
+
13
+ - **root_element**: A element name of root element (string, required)
14
+ - **row_element**: A element name of row element (string, required)
15
+ - **timestamp_format**: Timestamp format for timestamp column (string, default: `%Y-%m-%d %H:%M:%S`)
16
+
17
+ ## Example
18
+
19
+ ```yaml
20
+ out:
21
+ type: an output plugin supporting a formatter plugin such as `file`
22
+ formatter:
23
+ type: mysql_xml
24
+ root_element: root
25
+ row_element: row
26
+ ```
27
+
28
+ ## Build
29
+
30
+ ```
31
+ $ rake
32
+ ```
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :build
@@ -0,0 +1,18 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-formatter-mysql_xml"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["Takehiro Shiozaki"]
6
+ spec.summary = "MySQL XML formatter plugin for Embulk"
7
+ spec.description = "Embulk formatter plugin to output value for MySQL's `LOAD XML` statement."
8
+ spec.email = ["shio.phys@gmail.com"]
9
+ spec.licenses = ["MIT"]
10
+ spec.homepage = "https://github.com/shio.phys/embulk-formatter-mysql_xml"
11
+
12
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
13
+ spec.test_files = spec.files.grep(%r{^(test|spec)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_development_dependency 'bundler', ['>= 1.10.6']
17
+ spec.add_development_dependency 'rake', ['>= 10.0']
18
+ end
@@ -0,0 +1,5 @@
1
+ id,account,time,purchase,comment
2
+ 1,32864,2015-01-27 19:23:49,20150127,embulk
3
+ 2,14824,2015-01-27 19:01:23,20150127,embulk jruby
4
+ 3,27559,2015-01-28 02:20:02,20150128,"Embulk ""csv"" parser plugin"
5
+ 4,11270,2015-01-29 11:54:36,20150129,NULL
@@ -0,0 +1,28 @@
1
+ in:
2
+ type: file
3
+ path_prefix: example/example.csv
4
+ parser:
5
+ charset: UTF-8
6
+ newline: LF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: '"'
10
+ escape: '"'
11
+ trim_if_not_quoted: false
12
+ skip_header_lines: 1
13
+ allow_extra_columns: false
14
+ allow_optional_columns: false
15
+ columns:
16
+ - {name: id, type: long}
17
+ - {name: account, type: long}
18
+ - {name: time, type: timestamp, format: '%Y-%m-%d %H:%M:%S'}
19
+ - {name: purchase, type: timestamp, format: '%Y%m%d'}
20
+ - {name: comment, type: string}
21
+ out:
22
+ type: file
23
+ path_prefix: /tmp/mysql_xml_
24
+ file_ext: xml
25
+ formatter:
26
+ type: mysql_xml
27
+ root_element: root
28
+ row_element: row
@@ -0,0 +1,58 @@
1
+ require 'rexml/document'
2
+
3
+ module Embulk
4
+ module Formatter
5
+
6
+ class MysqlXml < FormatterPlugin
7
+ Plugin.register_formatter("mysql_xml", self)
8
+
9
+ def self.transaction(config, schema, &control)
10
+ task = {
11
+ "root_element" => config.param("root_element", :string),
12
+ "row_element" => config.param("row_element", :string),
13
+ "timestamp_format" => config.param("timestamp_format", :string, default: "%Y-%m-%d %H:%M:%S"),
14
+ }
15
+
16
+ yield(task)
17
+ end
18
+
19
+ def init
20
+ @root_element = task["root_element"]
21
+ @row_element = task["row_element"]
22
+ @timestamp_format = task["timestamp_format"]
23
+
24
+ @document = REXML::Document.new
25
+ @document.add(REXML::XMLDecl.new)
26
+ @document.add(REXML::Element.new(@root_element))
27
+ end
28
+
29
+ def close
30
+ end
31
+
32
+ def add(page)
33
+ column_names = page.schema.map(&:name)
34
+ page.each do |record|
35
+ row = REXML::Element.new(@row_element)
36
+ column_names.zip(record).each do |column_name, value|
37
+ if value.is_a?(Time)
38
+ value = value.strftime(@timestamp_format)
39
+ end
40
+ row.add_attribute(column_name, value)
41
+ end
42
+ @document.root.add_element(row)
43
+ end
44
+ end
45
+
46
+ def finish
47
+ buf = ''
48
+ @document.write(output: buf, indent: 4)
49
+
50
+ file = file_output.next_file
51
+ file.write(buf)
52
+ file.write("\n")
53
+ file_output.finish
54
+ end
55
+ end
56
+
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-formatter-mysql_xml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takehiro Shiozaki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 1.10.6
19
+ name: bundler
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.10.6
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '10.0'
33
+ name: rake
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Embulk formatter plugin to output value for MySQL's `LOAD XML` statement.
42
+ email:
43
+ - shio.phys@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".ruby-version"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - embulk-formatter-mysql_xml.gemspec
55
+ - example/example.csv
56
+ - example/example.yml
57
+ - lib/embulk/formatter/mysql_xml.rb
58
+ homepage: https://github.com/shio.phys/embulk-formatter-mysql_xml
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.6.14
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: MySQL XML formatter plugin for Embulk
82
+ test_files: []