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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1d69182fd9f26bd44547e3423b7a9291c7fde64
4
- data.tar.gz: a988cb81d92efdc69df47459c030b661937577da
3
+ metadata.gz: f017d50a25129c53993d3f8df50932a5ab4ea586
4
+ data.tar.gz: 32c0550e9eeefe6184f6578a430f96c3db120cdb
5
5
  SHA512:
6
- metadata.gz: 23fad82ccdd061d8c02310fc28cb764aa0b71a46b55c189f267a2a4f3e23dbf2a738d76dac98f2a6d2bed1354f07182daa5acdb818990e4fc8ccf71f78524b43
7
- data.tar.gz: fd42f7f0e8310e93efe0b84a442a937c8d1e1774291a0b75a413fd80e032ecd2557c51405d0b25859976da5dfb5d226d5f11fec1461ddd5e4946b4368673616c
6
+ metadata.gz: c8b0d3a8d94a883374d25825f5e135f0a765af1b7e53e523f54dc63e4a51aeec091f544b2c67f9cdb9e530224abdf1cdc99b13dfc9d47c38144c854e241c0dec
7
+ data.tar.gz: dce163316c84bfc4ab2f1f1d4c993485ad3398b6e4ce8f7a22980c9ddee52d4caba0dc68526aeed7c28f9fb64319b1eb396b7cef35016bd718a76bc63a89ddf7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.1.1 (2016-02-19)
2
+
3
+ Fixes:
4
+
5
+ * Fix for cases there are multiple input columns
6
+
1
7
  # 0.1.0 (2016-02-19)
2
8
 
3
9
  Initial release
10
+
data/build.gradle CHANGED
@@ -13,7 +13,7 @@ configurations {
13
13
  provided
14
14
  }
15
15
 
16
- version = "0.1.0"
16
+ version = "0.1.1"
17
17
 
18
18
  sourceCompatibility = 1.7
19
19
  targetCompatibility = 1.7
@@ -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
data/example/example.yml CHANGED
@@ -6,7 +6,7 @@ in:
6
6
  message_key: message
7
7
  out:
8
8
  type: file
9
- path_prefix: /tmp/signle_value_
9
+ path_prefix: /tmp/single_value_
10
10
  file_ext: txt
11
11
  formatter:
12
12
  type: single_value
@@ -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
@@ -8,7 +8,7 @@ in:
8
8
  - {name: time, type: timestamp, format: '%Y-%m-%d %H:%M:%S', timezone: "Asia/Tokyo"}
9
9
  out:
10
10
  type: file
11
- path_prefix: /tmp/signle_value_
11
+ path_prefix: /tmp/single_value_
12
12
  file_ext: txt
13
13
  formatter:
14
14
  type: single_value
@@ -57,29 +57,32 @@ public class SingleValueFormatterPlugin
57
57
  control.run(task.dump());
58
58
  }
59
59
 
60
- private Schema getOutputSchema(Optional<String> columnName, Schema inputSchema)
60
+ private int getInputColumnIndex(Optional<String> columnName, Schema inputSchema)
61
61
  {
62
- Column outputColumn;
63
62
  if (columnName.isPresent()) {
64
- outputColumn = inputSchema.lookupColumn(columnName.get());
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 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 Schema outputSchema = getOutputSchema(task.getMessageKey(), schema);
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(outputSchema);
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
- schema.visitColumns(new ColumnVisitor() {
100
+ outputSchema.visitColumns(new ColumnVisitor() {
98
101
  public void booleanColumn(Column column)
99
102
  {
100
- if (!pageReader.isNull(column)) {
101
- addValue(Boolean.toString(pageReader.getBoolean(column)));
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(column)) {
111
- addValue(Long.toString(pageReader.getLong(column)));
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(column)) {
121
- addValue(Double.toString(pageReader.getDouble(column)));
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(column)) {
131
- addValue(pageReader.getString(column));
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(column)) {
141
- Timestamp value = pageReader.getTimestamp(column);
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(column)) {
152
- Value value = pageReader.getJson(column);
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.0
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.0.jar
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