embulk-formatter-single_value 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/build.gradle +1 -1
- data/example/example.csv +5 -0
- data/example/example.yml +1 -1
- data/example/first_column.yml +26 -0
- data/example/message_key.yml +27 -0
- data/example/timestamp.yml +1 -1
- data/src/main/java/org/embulk/formatter/single_value/SingleValueFormatterPlugin.java +25 -22
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f017d50a25129c53993d3f8df50932a5ab4ea586
|
4
|
+
data.tar.gz: 32c0550e9eeefe6184f6578a430f96c3db120cdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8b0d3a8d94a883374d25825f5e135f0a765af1b7e53e523f54dc63e4a51aeec091f544b2c67f9cdb9e530224abdf1cdc99b13dfc9d47c38144c854e241c0dec
|
7
|
+
data.tar.gz: dce163316c84bfc4ab2f1f1d4c993485ad3398b6e4ce8f7a22980c9ddee52d4caba0dc68526aeed7c28f9fb64319b1eb396b7cef35016bd718a76bc63a89ddf7
|
data/CHANGELOG.md
CHANGED
data/build.gradle
CHANGED
data/example/example.csv
ADDED
data/example/example.yml
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
in:
|
2
|
+
type: file
|
3
|
+
path_prefix: example/example.csv
|
4
|
+
parser:
|
5
|
+
charset: UTF-8
|
6
|
+
newline: CRLF
|
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/single_value_
|
24
|
+
file_ext: txt
|
25
|
+
formatter:
|
26
|
+
type: single_value
|
@@ -0,0 +1,27 @@
|
|
1
|
+
in:
|
2
|
+
type: file
|
3
|
+
path_prefix: example/example.csv
|
4
|
+
parser:
|
5
|
+
charset: UTF-8
|
6
|
+
newline: CRLF
|
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/single_value_
|
24
|
+
file_ext: txt
|
25
|
+
formatter:
|
26
|
+
type: single_value
|
27
|
+
message_key: comment
|
data/example/timestamp.yml
CHANGED
@@ -57,29 +57,32 @@ public class SingleValueFormatterPlugin
|
|
57
57
|
control.run(task.dump());
|
58
58
|
}
|
59
59
|
|
60
|
-
private
|
60
|
+
private int getInputColumnIndex(Optional<String> columnName, Schema inputSchema)
|
61
61
|
{
|
62
|
-
Column outputColumn;
|
63
62
|
if (columnName.isPresent()) {
|
64
|
-
|
65
|
-
}
|
66
|
-
else {
|
67
|
-
outputColumn = inputSchema.getColumn(0);
|
63
|
+
return inputSchema.lookupColumn(columnName.get()).getIndex();
|
68
64
|
}
|
65
|
+
return 0; // default is the first column
|
66
|
+
}
|
67
|
+
|
68
|
+
private Schema getOutputSchema(int inputColumnIndex, Schema inputSchema)
|
69
|
+
{
|
70
|
+
Column outputColumn = inputSchema.getColumn(inputColumnIndex);
|
69
71
|
ImmutableList.Builder<Column> builder = ImmutableList.builder();
|
70
72
|
builder.add(outputColumn);
|
71
73
|
return new Schema(builder.build());
|
72
74
|
}
|
73
75
|
|
74
76
|
@Override
|
75
|
-
public PageOutput open(final TaskSource taskSource, final Schema
|
77
|
+
public PageOutput open(final TaskSource taskSource, final Schema inputSchema,
|
76
78
|
final FileOutput output)
|
77
79
|
{
|
78
80
|
final PluginTask task = taskSource.loadTask(PluginTask.class);
|
79
81
|
final LineEncoder encoder = new LineEncoder(output, task);
|
80
82
|
final String nullString = task.getNullString();
|
81
83
|
|
82
|
-
final
|
84
|
+
final int inputColumnIndex = getInputColumnIndex(task.getMessageKey(), inputSchema);
|
85
|
+
final Schema outputSchema = getOutputSchema(inputColumnIndex, inputSchema);
|
83
86
|
final DateTimeZone timezone = DateTimeZone.forID(task.getTimezone());
|
84
87
|
final TimestampFormatter timestampFormatter =
|
85
88
|
new TimestampFormatter(task.getJRuby(), task.getTimestampFormat(), timezone);
|
@@ -88,17 +91,17 @@ public class SingleValueFormatterPlugin
|
|
88
91
|
encoder.nextFile();
|
89
92
|
|
90
93
|
return new PageOutput() {
|
91
|
-
private final PageReader pageReader = new PageReader(
|
94
|
+
private final PageReader pageReader = new PageReader(inputSchema);
|
92
95
|
|
93
96
|
public void add(Page page)
|
94
97
|
{
|
95
98
|
pageReader.setPage(page);
|
96
99
|
while (pageReader.nextRecord()) {
|
97
|
-
|
100
|
+
outputSchema.visitColumns(new ColumnVisitor() {
|
98
101
|
public void booleanColumn(Column column)
|
99
102
|
{
|
100
|
-
if (!pageReader.isNull(
|
101
|
-
addValue(Boolean.toString(pageReader.getBoolean(
|
103
|
+
if (!pageReader.isNull(inputColumnIndex)) {
|
104
|
+
addValue(Boolean.toString(pageReader.getBoolean(inputColumnIndex)));
|
102
105
|
}
|
103
106
|
else {
|
104
107
|
addNullString();
|
@@ -107,8 +110,8 @@ public class SingleValueFormatterPlugin
|
|
107
110
|
|
108
111
|
public void longColumn(Column column)
|
109
112
|
{
|
110
|
-
if (!pageReader.isNull(
|
111
|
-
addValue(Long.toString(pageReader.getLong(
|
113
|
+
if (!pageReader.isNull(inputColumnIndex)) {
|
114
|
+
addValue(Long.toString(pageReader.getLong(inputColumnIndex)));
|
112
115
|
}
|
113
116
|
else {
|
114
117
|
addNullString();
|
@@ -117,8 +120,8 @@ public class SingleValueFormatterPlugin
|
|
117
120
|
|
118
121
|
public void doubleColumn(Column column)
|
119
122
|
{
|
120
|
-
if (!pageReader.isNull(
|
121
|
-
addValue(Double.toString(pageReader.getDouble(
|
123
|
+
if (!pageReader.isNull(inputColumnIndex)) {
|
124
|
+
addValue(Double.toString(pageReader.getDouble(inputColumnIndex)));
|
122
125
|
}
|
123
126
|
else {
|
124
127
|
addNullString();
|
@@ -127,8 +130,8 @@ public class SingleValueFormatterPlugin
|
|
127
130
|
|
128
131
|
public void stringColumn(Column column)
|
129
132
|
{
|
130
|
-
if (!pageReader.isNull(
|
131
|
-
addValue(pageReader.getString(
|
133
|
+
if (!pageReader.isNull(inputColumnIndex)) {
|
134
|
+
addValue(pageReader.getString(inputColumnIndex));
|
132
135
|
}
|
133
136
|
else {
|
134
137
|
addNullString();
|
@@ -137,8 +140,8 @@ public class SingleValueFormatterPlugin
|
|
137
140
|
|
138
141
|
public void timestampColumn(Column column)
|
139
142
|
{
|
140
|
-
if (!pageReader.isNull(
|
141
|
-
Timestamp value = pageReader.getTimestamp(
|
143
|
+
if (!pageReader.isNull(inputColumnIndex)) {
|
144
|
+
Timestamp value = pageReader.getTimestamp(inputColumnIndex);
|
142
145
|
addValue(timestampFormatter.format(value));
|
143
146
|
}
|
144
147
|
else {
|
@@ -148,8 +151,8 @@ public class SingleValueFormatterPlugin
|
|
148
151
|
|
149
152
|
public void jsonColumn(Column column)
|
150
153
|
{
|
151
|
-
if (!pageReader.isNull(
|
152
|
-
Value value = pageReader.getJson(
|
154
|
+
if (!pageReader.isNull(inputColumnIndex)) {
|
155
|
+
Value value = pageReader.getJson(inputColumnIndex);
|
153
156
|
addValue(value.toJson());
|
154
157
|
}
|
155
158
|
else {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-formatter-single_value
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sonots
|
@@ -52,8 +52,11 @@ files:
|
|
52
52
|
- build.gradle
|
53
53
|
- config/checkstyle/checkstyle.xml
|
54
54
|
- config/checkstyle/default.xml
|
55
|
+
- example/example.csv
|
55
56
|
- example/example.txt
|
56
57
|
- example/example.yml
|
58
|
+
- example/first_column.yml
|
59
|
+
- example/message_key.yml
|
57
60
|
- example/timestamp.txt
|
58
61
|
- example/timestamp.yml
|
59
62
|
- gradle/wrapper/gradle-wrapper.jar
|
@@ -63,7 +66,7 @@ files:
|
|
63
66
|
- lib/embulk/formatter/single_value.rb
|
64
67
|
- src/main/java/org/embulk/formatter/single_value/SingleValueFormatterPlugin.java
|
65
68
|
- src/test/java/org/embulk/formatter/single_value/TestSingleValueFormatterPlugin.java
|
66
|
-
- classpath/embulk-formatter-single_value-0.1.
|
69
|
+
- classpath/embulk-formatter-single_value-0.1.1.jar
|
67
70
|
homepage: https://github.com/sonots/embulk-formatter-single_value
|
68
71
|
licenses:
|
69
72
|
- MIT
|